Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
2845c49a
Commit
2845c49a
authored
Jul 02, 2018
by
Hugo LEVY-FALK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utilise un ModelForm pour les données de chèque + doc
parent
3f2de573
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
31 deletions
+36
-31
cotisations/models.py
cotisations/models.py
+27
-21
cotisations/payment_methods/cheque/views.py
cotisations/payment_methods/cheque/views.py
+9
-10
No files found.
cotisations/models.py
View file @
2845c49a
...
...
@@ -135,7 +135,7 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
"""
price
=
Vente
.
objects
.
filter
(
facture
=
self
).
aggregate
(
models
.
Sum
(
'prix'
))[
'prix__sum'
]
).
aggregate
(
models
.
Sum
(
'prix'
))[
'prix__sum'
]
return
price
# TODO : change prix to price
...
...
@@ -147,12 +147,12 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
# TODO : change Vente to somethingelse
return
Vente
.
objects
.
filter
(
facture
=
self
).
aggregate
(
total
=
models
.
Sum
(
models
.
F
(
'prix'
)
*
models
.
F
(
'number'
),
output_field
=
models
.
FloatField
()
)
)[
'total'
]
).
aggregate
(
total
=
models
.
Sum
(
models
.
F
(
'prix'
)
*
models
.
F
(
'number'
),
output_field
=
models
.
FloatField
()
)
)[
'total'
]
def
name
(
self
):
"""
...
...
@@ -161,7 +161,7 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
"""
name
=
' - '
.
join
(
Vente
.
objects
.
filter
(
facture
=
self
).
values_list
(
'name'
,
flat
=
True
))
).
values_list
(
'name'
,
flat
=
True
))
return
name
def
can_edit
(
self
,
user_request
,
*
args
,
**
kwargs
):
...
...
@@ -232,7 +232,6 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
_
(
"You don't have the right to create an invoice."
)
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
Facture
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
field_permissions
=
{
...
...
@@ -361,12 +360,12 @@ class Vente(RevMixin, AclMixin, models.Model):
facture__in
=
Facture
.
objects
.
filter
(
user
=
self
.
facture
.
user
).
exclude
(
valid
=
False
))
).
filter
(
Q
(
type_cotisation
=
'All'
)
|
Q
(
type_cotisation
=
self
.
type_cotisation
)
).
filter
(
date_start__lt
=
date_start
).
aggregate
(
Max
(
'date_end'
))[
'date_end__max'
]
).
filter
(
Q
(
type_cotisation
=
'All'
)
|
Q
(
type_cotisation
=
self
.
type_cotisation
)
).
filter
(
date_start__lt
=
date_start
).
aggregate
(
Max
(
'date_end'
))[
'date_end__max'
]
elif
self
.
type_cotisation
==
"Adhesion"
:
end_cotisation
=
self
.
facture
.
user
.
end_adhesion
()
else
:
...
...
@@ -377,7 +376,7 @@ class Vente(RevMixin, AclMixin, models.Model):
cotisation
.
date_start
=
date_max
cotisation
.
date_end
=
cotisation
.
date_start
+
relativedelta
(
months
=
self
.
duration
*
self
.
number
)
)
return
def
save
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -400,7 +399,7 @@ class Vente(RevMixin, AclMixin, models.Model):
elif
(
not
user_request
.
has_perm
(
'cotisations.change_all_facture'
)
and
not
self
.
facture
.
user
.
can_edit
(
user_request
,
*
args
,
**
kwargs
)[
0
]):
)[
0
]):
return
False
,
_
(
"You don't have the right to edit this user's "
"purchases."
)
elif
(
not
user_request
.
has_perm
(
'cotisations.change_all_vente'
)
and
...
...
@@ -632,12 +631,19 @@ class Paiement(RevMixin, AclMixin, models.Model):
)
super
(
Paiement
,
self
).
save
(
*
args
,
**
kwargs
)
def
end_payment
(
self
,
invoice
,
request
):
def
end_payment
(
self
,
invoice
,
request
,
use_payment_method
=
True
):
"""
The general way of ending a payment. You may redefine this method for custom
payment methods. Must return a HttpResponse-like object.
The general way of ending a payment.
:param invoice: The invoice being created.
:param request: Request sended by the user.
:param use_payment_method: If `self` has an attribute `payment_method`,
returns the result of
`self.payment_method.end_payment(invoice, request)`
:returns: An `HttpResponse`-like object.
"""
if
hasattr
(
self
,
'payment_method'
):
if
hasattr
(
self
,
'payment_method'
)
and
use_payment_method
:
return
self
.
payment_method
.
end_payment
(
invoice
,
request
)
# In case a cotisation was bought, inform the user, the
...
...
cotisations/payment_methods/cheque/views.py
View file @
2845c49a
...
...
@@ -12,7 +12,7 @@ from django.utils.translation import ugettext as _
from
cotisations.models
import
Facture
as
Invoice
from
.models
import
ChequePayment
from
.forms
import
Chequ
eForm
from
.forms
import
Invoic
eForm
@
login_required
...
...
@@ -28,16 +28,15 @@ def cheque(request, invoice_pk):
'users:profil'
,
kwargs
=
{
'userid'
:
request
.
user
.
pk
}
))
form
=
ChequeForm
(
request
.
POST
or
Non
e
)
form
=
InvoiceForm
(
request
.
POST
or
None
,
instance
=
invoic
e
)
if
form
.
is_valid
():
invoice
.
banque
=
form
.
cleaned_data
[
'bank'
]
invoice
.
cheque
=
form
.
cleaned_data
[
'number'
]
invoice
.
valid
=
True
invoice
.
save
()
return
redirect
(
reverse
(
'users:profil'
,
kwargs
=
{
'userid'
:
request
.
user
.
pk
}
))
form
.
instance
.
valid
=
True
form
.
save
()
return
form
.
instance
.
paiement
.
end_payment
(
form
.
instance
,
request
,
use_payment_method
=
False
)
return
render
(
request
,
'cotisations/payment_form.html'
,
...
...
Write
Preview
Markdown
is supported
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