Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nounous
re2o
Commits
17f627c4
Commit
17f627c4
authored
Jul 05, 2018
by
Hugo LEVY-FALK
Browse files
Plus de nom de paiement hardcodés !
parent
193dfb67
Changes
10
Hide whitespace changes
Inline
Side-by-side
cotisations/forms.py
View file @
17f627c4
...
...
@@ -91,8 +91,7 @@ class CreditSoldeForm(NewFactureForm):
super
(
CreditSoldeForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
# TODO : change solde to balance
self
.
fields
[
'paiement'
].
queryset
=
Paiement
.
objects
.
exclude
(
moyen
=
'solde'
).
exclude
(
moyen
=
'Solde'
)
is_balance
=
True
)
montant
=
forms
.
DecimalField
(
max_digits
=
5
,
decimal_places
=
2
,
required
=
True
)
...
...
cotisations/migrations/0038_paiement_is_balance.py
0 → 100644
View file @
17f627c4
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-04 16:30
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
def
update_balance
(
apps
,
_
):
Payment
=
apps
.
get_model
(
'cotisations'
,
'Paiement'
)
try
:
balance
=
Payment
.
objects
.
get
(
moyen
=
"solde"
)
balance
.
is_balance
=
True
balance
.
save
()
except
Payment
.
DoesNotExist
:
pass
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'cotisations'
,
'0037_auto_20180703_1202'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'paiement'
,
name
=
'is_balance'
,
field
=
models
.
BooleanField
(
default
=
False
,
editable
=
False
,
help_text
=
'There should be only one balance payment method.'
,
verbose_name
=
'Is user balance'
),
),
migrations
.
RunPython
(
update_balance
)
]
cotisations/migrations/0039_auto_20180704_1147.py
0 → 100644
View file @
17f627c4
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-04 16:47
from
__future__
import
unicode_literals
import
cotisations.models
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'cotisations'
,
'0038_paiement_is_balance'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'paiement'
,
name
=
'is_balance'
,
field
=
models
.
BooleanField
(
default
=
False
,
editable
=
False
,
help_text
=
'There should be only one balance payment method.'
,
validators
=
[
cotisations
.
models
.
check_no_balance
],
verbose_name
=
'Is user balance'
),
),
]
cotisations/models.py
View file @
17f627c4
...
...
@@ -594,6 +594,17 @@ class Banque(RevMixin, AclMixin, models.Model):
return
self
.
name
def
check_no_balance
():
"""This functions checks that no Paiement with is_balance=True exists
:raises ValidationError: if such a Paiement exists.
"""
p
=
Paiement
.
objects
.
filter
(
is_balance
=
True
)
if
len
(
p
)
>
0
:
raise
ValidationError
(
_
(
"There are already payment method(s) for user balance"
)
)
# TODO : change Paiement to Payment
class
Paiement
(
RevMixin
,
AclMixin
,
models
.
Model
):
"""
...
...
@@ -624,6 +635,13 @@ class Paiement(RevMixin, AclMixin, models.Model):
default
=
False
,
verbose_name
=
_l
(
"Is available for every user"
)
)
is_balance
=
models
.
BooleanField
(
default
=
False
,
editable
=
False
,
verbose_name
=
_l
(
"Is user balance"
),
help_text
=
_l
(
"There should be only one balance payment method."
),
validators
=
[
check_no_balance
]
)
class
Meta
:
permissions
=
(
...
...
cotisations/payment_methods/balance/models.py
View file @
17f627c4
...
...
@@ -55,3 +55,14 @@ class BalancePayment(PaymentMethodMixin, models.Model):
request
,
use_payment_method
=
False
)
def
valid_form
(
self
,
form
):
p
=
Paiement
.
objects
.
filter
(
is_balance
=
True
)
if
len
(
p
)
>
0
:
form
.
add_error
(
'payment_method'
,
_
(
"There is already a payment type for user balance"
)
)
def
alter_payment
(
self
,
payment
):
self
.
payment
.
is_balance
=
True
cotisations/payment_methods/forms.py
View file @
17f627c4
...
...
@@ -51,16 +51,27 @@ class PaymentMethodForm(forms.Form):
else
:
self
.
fields
=
{}
def
save
(
self
,
*
args
,
payment
=
None
,
**
kwargs
):
commit
=
kwargs
.
pop
(
'commit'
,
True
)
def
clean
(
self
):
super
(
PaymentMethodForm
,
self
).
clean
(
)
choice
=
self
.
cleaned_data
[
'payment_method'
]
if
choice
==
''
:
return
choice
=
int
(
choice
)
model
=
PAYMENT_METHODS
[
choice
].
PaymentMethod
form
=
forms
.
modelform_factory
(
model
,
fields
=
'__all__'
)(
self
.
data
,
prefix
=
self
.
prefix
)
payment_method
=
form
.
save
(
commit
=
False
)
payment_method
.
payment
=
payment
self
.
payment_method
=
form
.
save
(
commit
=
False
)
if
hasattr
(
self
.
payment_method
,
'valid_form'
):
self
.
payment_method
.
valid_form
(
self
)
return
self
.
cleaned_data
def
save
(
self
,
payment
,
*
args
,
**
kwargs
):
commit
=
kwargs
.
pop
(
'commit'
,
True
)
self
.
payment_method
.
payment
=
payment
if
hasattr
(
self
.
payment_method
,
'alter_payment'
):
self
.
payment_method
.
alter_payment
(
payment
)
if
commit
:
payment_method
.
save
()
return
payment_method
payment
.
save
()
self
.
payment_method
.
save
()
return
self
.
payment_method
cotisations/templates/cotisations/facture.html
View file @
17f627c4
...
...
@@ -31,6 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block content %}
{% bootstrap_form_errors factureform %}
{% if payment_method %}
{% bootstrap_form_errors payment_method %}
{% endif %}
{% if title %}
<h3>
{{title}}
</h3>
{% endif %}
...
...
cotisations/views.py
View file @
17f627c4
...
...
@@ -409,7 +409,7 @@ def add_paiement(request):
)
if
payment
.
is_valid
()
and
payment_method
.
is_valid
():
payment
=
payment
.
save
()
payment_method
.
save
(
payment
=
payment
)
payment_method
.
save
(
payment
)
messages
.
success
(
request
,
_
(
"The payment method has been successfully created."
)
...
...
@@ -688,7 +688,7 @@ def new_facture_solde(request, userid):
"""
user
=
request
.
user
invoice
=
Facture
(
user
=
user
)
payment
,
_created
=
Paiement
.
objects
.
get_or_create
(
moyen
=
'Solde'
)
payment
,
_created
=
Paiement
.
objects
.
get_or_create
(
is_balance
=
True
)
invoice
.
paiement
=
payment
# The template needs the list of articles (for the JS part)
article_list
=
Article
.
objects
.
filter
(
...
...
preferences/models.py
View file @
17f627c4
...
...
@@ -118,10 +118,7 @@ class OptionalUser(AclMixin, PreferencesModel):
def
clean
(
self
):
"""Creation du mode de paiement par solde"""
if
self
.
user_solde
:
p
=
cotisations
.
models
.
Paiement
.
objects
.
filter
(
moyen
=
"Solde"
)
if
not
len
(
p
):
c
=
cotisations
.
models
.
Paiement
(
moyen
=
"Solde"
)
c
.
save
()
cotisations
.
models
.
Paiement
.
objects
.
get_or_create
(
is_balance
=
True
)
@
receiver
(
post_save
,
sender
=
OptionalUser
)
...
...
users/models.py
View file @
17f627c4
...
...
@@ -428,7 +428,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
def
solde
(
self
):
""" Renvoie le solde d'un user.
Somme les crédits de solde et retire les débit payés par solde"""
solde_objects
=
Paiement
.
objects
.
filter
(
moyen
=
'solde'
)
solde_objects
=
Paiement
.
objects
.
filter
(
is_balance
=
True
)
somme_debit
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
filter
(
user
=
self
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment