8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Sort articles by number of membership/cotisation months before saving a invoice

This commit is contained in:
chapeau 2024-02-29 14:27:55 +01:00
parent cab6598d28
commit 9b3892a1ea

View file

@ -75,6 +75,8 @@ def new_facture(request, user, userid):
A bit of JS is used in the template to add articles in a fancier way. A bit of JS is used in the template to add articles in a fancier way.
If everything is correct, save each one of the articles, save the If everything is correct, save each one of the articles, save the
purchase object associated and finally the newly created invoice. purchase object associated and finally the newly created invoice.
Each article is created and save sorted by the number of month-length
membership or connection they offer, to solve duration ambiguities.
""" """
invoice = Facture(user=user) invoice = Facture(user=user)
# The template needs the list of articles (for the JS part) # The template needs the list of articles (for the JS part)
@ -98,7 +100,13 @@ def new_facture(request, user, userid):
# Building a purchase for each article sold # Building a purchase for each article sold
purchases = [] purchases = []
total_price = 0 total_price = 0
for art_item in articles: # We sort articles by number of months of subscription in them, to solve month + day ambiguities issues
sorted_articles = sorted(
articles,
key=lambda art: max(art.cleaned_data["article"].duration_membership, art.cleaned_data["article"].duration_connection),
reverse=True
)
for art_item in sorted_articles:
if art_item.cleaned_data: if art_item.cleaned_data:
article = art_item.cleaned_data["article"] article = art_item.cleaned_data["article"]
quantity = art_item.cleaned_data["quantity"] quantity = art_item.cleaned_data["quantity"]