@ -198,24 +198,40 @@ def new_facture_pdf(request):
get invoices that are not taken into account , for the administrative
get invoices that are not taken into account , for the administrative
point of view .
point of view .
"""
"""
# The template needs the list of articles (for the JS part)
articles = Article . objects . filter (
Q ( type_user = ' All ' ) | Q ( type_user = request . user . class_name )
)
# Building the invocie form and the article formset
invoice_form = NewFactureFormPdf ( request . POST or None )
invoice_form = NewFactureFormPdf ( request . POST or None )
if invoice_form . is_valid ( ) :
if request . user . is_class_club :
tbl = [ ]
articles_formset = formset_factory ( SelectClubArticleForm ) ( request . POST or None )
article = facture_form . cleaned_data [ ' article ' ]
else :
quantity = facture_form . cleaned_data [ ' number ' ]
articles_formset = formset_factory ( SelectUserArticleForm ) ( request . POST or None )
paid = facture_form . cleaned_data [ ' paid ' ]
if invoice_form . is_valid ( ) and articles_formset . is_valid ( ) :
recipient = facture_form . cleaned_data [ ' dest ' ]
# Get the article list and build an list out of it
room = facture_form . cleaned_data [ ' chambre ' ]
# contiaining (article_name, article_price, quantity, total_price)
invoice_id = facture_form . cleaned_data [ ' fid ' ]
articles_info = [ ]
for art in article :
for articles_form in articles_formset :
tbl . append ( [ art , quantity , art . prix * quantity ] )
if articles_form . cleaned_data :
total_price = sum ( a [ 2 ] for a in tbl )
article = articles_form . cleaned_data [ ' article ' ]
user = { ' name ' : recipient , ' room ' : room }
quantity = articles_form . cleaned_data [ ' quantity ' ]
articles_info . append ( {
' name ' : article . name ,
' price ' : article . prix ,
' quantity ' : quantity ,
' total_price ' : article . prix * quantity
} )
paid = invoice_form . cleaned_data [ ' paid ' ]
recipient = invoice_form . cleaned_data [ ' dest ' ]
address = invoice_form . cleaned_data [ ' chambre ' ]
total_price = sum ( a [ ' total_price ' ] for a in articles_info )
return render_invoice ( request , {
return render_invoice ( request , {
' DATE ' : timezone . now ( ) ,
' DATE ' : timezone . now ( ) ,
' dest ' : user ,
' recipient_name ' : recipient ,
' fid ' : invoice_id ,
' address ' : address ,
' article ' : tbl ,
' article ' : articles_info ,
' total ' : total_price ,
' total ' : total_price ,
' paid ' : paid ,
' paid ' : paid ,
' asso_name ' : AssoOption . get_cached_value ( ' name ' ) ,
' asso_name ' : AssoOption . get_cached_value ( ' name ' ) ,
@ -228,7 +244,9 @@ def new_facture_pdf(request):
} )
} )
return form ( {
return form ( {
' factureform ' : invoice_form ,
' factureform ' : invoice_form ,
' action_name ' : _ ( " Edit " )
' action_name ' : _ ( " Create " ) ,
' articlesformset ' : articles_formset ,
' articles ' : articles
} , ' cotisations/facture.html ' , request )
} , ' cotisations/facture.html ' , request )
@ -244,15 +262,26 @@ def facture_pdf(request, facture, factureid):
"""
"""
# TODO : change vente to purchase
# TODO : change vente to purchase
purchases_objects = Vente . objects . all ( ) . filter ( facture = facture )
purchases_objects = Vente . objects . all ( ) . filter ( facture = facture )
purchases = [ ]
# Get the article list and build an list out of it
# contiaining (article_name, article_price, quantity, total_price)
purchases_info = [ ]
for purchase in purchases_objects :
for purchase in purchases_objects :
purchases . append ( [ purchase , purchase . number , purchase . prix_total ] )
purchases_info . append ( {
' name ' : purchase . name ,
' price ' : purchase . prix ,
' quantity ' : purchase . number ,
' total_price ' : purchase . prix_total
} )
return render_invoice ( request , {
return render_invoice ( request , {
' paid ' : True ,
' paid ' : True ,
' fid ' : facture . id ,
' fid ' : facture . id ,
' DATE ' : facture . date ,
' DATE ' : facture . date ,
' dest ' : facture . user ,
' recipient_name ' : " {} {} " . format (
' article ' : purchases ,
facture . user . name ,
facture . user . surname
) ,
' address ' : facture . user . room ,
' article ' : purchases_info ,
' total ' : facture . prix_total ( ) ,
' total ' : facture . prix_total ( ) ,
' asso_name ' : AssoOption . get_cached_value ( ' name ' ) ,
' asso_name ' : AssoOption . get_cached_value ( ' name ' ) ,
' line1 ' : AssoOption . get_cached_value ( ' adresse1 ' ) ,
' line1 ' : AssoOption . get_cached_value ( ' adresse1 ' ) ,