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
553af7e6
Commit
553af7e6
authored
Jul 14, 2016
by
chirac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout d'articles mutliples en quantité différente et un peu de js pour un formulaire dynamique
parent
527f1b9f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
28 deletions
+85
-28
cotisations/admin.py
cotisations/admin.py
+2
-2
cotisations/forms.py
cotisations/forms.py
+5
-5
cotisations/migrations/0014_auto_20160712_0245.py
cotisations/migrations/0014_auto_20160712_0245.py
+24
-0
cotisations/models.py
cotisations/models.py
+5
-2
cotisations/templates/cotisations/facture.html
cotisations/templates/cotisations/facture.html
+27
-3
cotisations/views.py
cotisations/views.py
+22
-16
No files found.
cotisations/admin.py
View file @
553af7e6
...
...
@@ -3,10 +3,10 @@ from django.contrib import admin
from
.models
import
Facture
,
Article
,
Banque
,
Paiement
,
Cotisation
,
Vente
class
FactureAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'user'
,
'paiement'
,
'
number'
,
'
date'
,
'valid'
)
list_display
=
(
'user'
,
'paiement'
,
'date'
,
'valid'
)
class
VenteAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'facture'
,
'name'
,
'prix'
,
'cotisation'
,
'duration'
)
list_display
=
(
'facture'
,
'name'
,
'prix'
,
'
number'
,
'
cotisation'
,
'duration'
)
class
ArticleAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'name'
,
'prix'
,
'cotisation'
,
'duration'
)
...
...
cotisations/forms.py
View file @
553af7e6
...
...
@@ -4,8 +4,6 @@ from django import forms
from
.models
import
Article
,
Paiement
,
Facture
,
Banque
,
Vente
class
NewFactureForm
(
ModelForm
):
article
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Article
.
objects
.
all
(),
label
=
"Article"
,
widget
=
forms
.
CheckboxSelectMultiple
())
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
NewFactureForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'cheque'
].
required
=
False
...
...
@@ -23,13 +21,15 @@ class NewFactureForm(ModelForm):
paiement
=
cleaned_data
.
get
(
"paiement"
)
cheque
=
cleaned_data
.
get
(
"cheque"
)
banque
=
cleaned_data
.
get
(
"banque"
)
if
paiement
.
moyen
==
"chèque"
and
not
(
cheque
and
banque
):
if
not
paiement
:
raise
forms
.
ValidationError
(
"Le moyen de paiement est obligatoire"
)
elif
paiement
.
moyen
==
"chèque"
and
not
(
cheque
and
banque
):
raise
forms
.
ValidationError
(
"Le numero de chèque et la banque sont obligatoires"
)
return
cleaned_data
class
SelectArticleForm
(
Form
):
article
=
forms
.
ModelChoiceField
(
queryset
=
Article
.
objects
.
all
(),
label
=
"Article"
)
quantity
=
forms
.
IntegerField
(
label
=
"Quantité"
)
article
=
forms
.
ModelChoiceField
(
queryset
=
Article
.
objects
.
all
(),
label
=
"Article"
,
required
=
True
)
quantity
=
forms
.
IntegerField
(
label
=
"Quantité"
,
required
=
True
)
class
NewFactureFormPdf
(
Form
):
article
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Article
.
objects
.
all
(),
label
=
"Article"
)
...
...
cotisations/migrations/0014_auto_20160712_0245.py
0 → 100644
View file @
553af7e6
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'cotisations'
,
'0013_auto_20160711_2240'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'facture'
,
name
=
'number'
,
),
migrations
.
AddField
(
model_name
=
'vente'
,
name
=
'number'
,
field
=
models
.
IntegerField
(
default
=
1
),
preserve_default
=
False
,
),
]
cotisations/models.py
View file @
553af7e6
...
...
@@ -6,7 +6,6 @@ class Facture(models.Model):
paiement
=
models
.
ForeignKey
(
'Paiement'
,
on_delete
=
models
.
PROTECT
)
banque
=
models
.
ForeignKey
(
'Banque'
,
on_delete
=
models
.
PROTECT
,
blank
=
True
,
null
=
True
)
cheque
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
number
=
models
.
IntegerField
()
date
=
models
.
DateTimeField
(
auto_now_add
=
True
)
valid
=
models
.
BooleanField
(
default
=
True
)
...
...
@@ -15,7 +14,7 @@ class Facture(models.Model):
return
prix
def
prix_total
(
self
):
return
self
.
prix
()
*
self
.
number
return
Vente
.
objects
.
all
().
filter
(
facture
=
self
).
aggregate
(
total
=
models
.
Sum
(
models
.
F
(
'prix'
)
*
models
.
F
(
'number'
),
output_field
=
models
.
FloatField
()))[
'total'
]
def
name
(
self
):
name
=
' - '
.
join
(
vente
.
name
for
vente
in
Vente
.
objects
.
all
().
filter
(
facture
=
self
))
...
...
@@ -26,11 +25,15 @@ class Facture(models.Model):
class
Vente
(
models
.
Model
):
facture
=
models
.
ForeignKey
(
'Facture'
,
on_delete
=
models
.
PROTECT
)
number
=
models
.
IntegerField
()
name
=
models
.
CharField
(
max_length
=
255
)
prix
=
models
.
DecimalField
(
max_digits
=
5
,
decimal_places
=
2
)
cotisation
=
models
.
BooleanField
()
duration
=
models
.
IntegerField
(
help_text
=
"Durée exprimée en mois entiers"
,
blank
=
True
,
null
=
True
)
def
prix_total
(
self
):
return
self
.
prix
*
self
.
number
def
__str__
(
self
):
return
str
(
self
.
name
)
+
' '
+
str
(
self
.
facture
)
...
...
cotisations/templates/cotisations/facture.html
View file @
553af7e6
{% extends "cotisations/sidebar.html" %}
{% load bootstrap3 %}
{% load staticfiles%}
{% block title %}Création et modification de factures{% endblock %}
...
...
@@ -9,10 +10,33 @@
<form
class=
"form"
method=
"post"
>
{% csrf_token %}
{% bootstrap_form factureform %}
{% for vente in venteform %}
{% bootstrap_form vente %}
{% endfor %}
{{ venteform.management_form }}
<div
id=
"form_set"
>
{% for form in venteform.forms %}
{{ form.as_p }}
{% endfor %}
</div>
<input
class=
"btn btn-primary btn-sm"
role=
"button"
value=
"Ajouter un article"
id=
"add_one"
>
<input
class=
"btn btn-primary btn-sm"
role=
"button"
value=
"Supprimer un article"
id=
"del_one"
>
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<div
id=
"empty_form"
style=
"display:none"
>
<table
class=
'no_error'
>
{{ venteform.empty_form.as_p }}
</table>
</div>
<script>
$
(
'
#add_one
'
).
click
(
function
()
{
var
form_idx
=
$
(
'
#id_form-TOTAL_FORMS
'
).
val
();
$
(
'
#form_set
'
).
append
(
$
(
'
#empty_form
'
).
html
().
replace
(
/__prefix__/g
,
form_idx
));
$
(
'
#id_form-TOTAL_FORMS
'
).
val
(
parseInt
(
form_idx
)
+
1
);
});
$
(
'
#del_one
'
).
click
(
function
()
{
var
forms
=
$
(
'
.dynamic-form
'
);
$
(
'
#id_form-TOTAL_FORMS
'
).
val
(
forms
.
length
);
});
</script>
{% endblock %}
cotisations/views.py
View file @
553af7e6
...
...
@@ -12,7 +12,7 @@ from django.forms import modelformset_factory, formset_factory
import
os
from
.models
import
Facture
,
Article
,
Vente
,
Cotisation
,
Paiement
,
Banque
from
.forms
import
NewFactureForm
,
EditFactureForm
,
ArticleForm
,
DelArticleForm
,
PaiementForm
,
DelPaiementForm
,
BanqueForm
,
DelBanqueForm
,
NewFactureFormPdf
from
.forms
import
NewFactureForm
,
EditFactureForm
,
ArticleForm
,
DelArticleForm
,
PaiementForm
,
DelPaiementForm
,
BanqueForm
,
DelBanqueForm
,
NewFactureFormPdf
,
SelectArticleForm
from
users.models
import
User
from
.tex
import
render_tex
from
re2o.settings_local
import
ASSO_NAME
,
ASSO_ADDRESS_LINE1
,
ASSO_ADDRESS_LINE2
,
ASSO_SIRET
,
ASSO_EMAIL
,
ASSO_PHONE
,
LOGO_PATH
...
...
@@ -47,22 +47,28 @@ def new_facture(request, userid):
return
redirect
(
"/cotisations/"
)
facture
=
Facture
(
user
=
user
)
facture_form
=
NewFactureForm
(
request
.
POST
or
None
,
instance
=
facture
)
ArticleFormSet
=
formset_factory
(
ArticleForm
)
if
facture_form
.
is_valid
():
article_formset
=
formset_factory
(
SelectArticleForm
)
article_formset
=
article_formset
(
request
.
POST
or
None
)
if
facture_form
.
is_valid
()
and
article_formset
.
is_valid
():
new_facture
=
facture_form
.
save
(
commit
=
False
)
article
=
facture_form
.
cleaned_data
[
'article'
]
new_facture
.
save
()
for
art
in
article
:
new_vente
=
Vente
.
objects
.
create
(
facture
=
new_facture
,
name
=
art
.
name
,
prix
=
art
.
prix
,
cotisation
=
art
.
cotisation
,
duration
=
art
.
duration
,
number
=
1
)
new_vente
.
save
()
if
any
(
art
.
cotisation
for
art
in
article
):
duration
=
sum
(
art
.
duration
for
art
in
article
if
art
.
cotisation
)
create_cotis
(
new_facture
,
user
,
duration
)
messages
.
success
(
request
,
"La cotisation a été prolongée pour l'adhérent %s "
%
user
.
name
)
else
:
messages
.
success
(
request
,
"La facture a été crée"
)
return
redirect
(
"/users/profil/"
+
userid
)
return
form
({
'factureform'
:
facture_form
},
'cotisations/facture.html'
,
request
)
articles
=
article_formset
if
any
(
art
.
cleaned_data
for
art
in
articles
):
new_facture
.
save
()
for
art_item
in
articles
:
if
art_item
.
cleaned_data
:
article
=
art_item
.
cleaned_data
[
'article'
]
quantity
=
art_item
.
cleaned_data
[
'quantity'
]
new_vente
=
Vente
.
objects
.
create
(
facture
=
new_facture
,
name
=
article
.
name
,
prix
=
article
.
prix
,
cotisation
=
article
.
cotisation
,
duration
=
article
.
duration
,
number
=
quantity
)
new_vente
.
save
()
if
any
(
art
.
cleaned_data
[
'article'
].
cotisation
for
art
in
articles
):
duration
=
sum
(
art
.
cleaned_data
[
'article'
].
duration
*
art
.
cleaned_data
[
'quantity'
]
for
art
in
articles
if
art
.
cleaned_data
[
'article'
].
cotisation
)
create_cotis
(
new_facture
,
user
,
duration
)
messages
.
success
(
request
,
"La cotisation a été prolongée pour l'adhérent %s "
%
user
.
name
)
else
:
messages
.
success
(
request
,
"La facture a été crée"
)
return
redirect
(
"/users/profil/"
+
userid
)
messages
.
error
(
request
,
u
"Il faut au moins un article valide pour créer une facture"
)
return
form
({
'factureform'
:
facture_form
,
'venteform'
:
article_formset
},
'cotisations/facture.html'
,
request
)
@
login_required
@
permission_required
(
'trésorier'
)
...
...
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