mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Merge branch '348-mutliple-cotisations' into 'dev'
Resolve "Mutliple cotisations bought in an invoice are calculated in the wrong order" See merge request re2o/re2o!637
This commit is contained in:
commit
a7d2fc9f98
2 changed files with 13 additions and 1 deletions
|
@ -125,9 +125,13 @@ class NewFactureTests(TestCase):
|
|||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
||||
invoice = self.user.facture_set.first()
|
||||
cotisations = invoice.get_subscription()
|
||||
delta = relativedelta(self.user.end_connexion(), date)
|
||||
delta.microseconds = 0
|
||||
self.assertEqual(delta, relativedelta(months=1, days=7))
|
||||
# Check that the cotisations are sorted
|
||||
self.assertEqual(relativedelta(cotisations[0].date_end_con, cotisations[0].date_start_con), relativedelta(months=1))
|
||||
self.assertEqual(relativedelta(cotisations[1].date_end_con, cotisations[1].date_start_con), relativedelta(days=7))
|
||||
|
||||
def test_several_articles_creates_several_purchases(self):
|
||||
data = {
|
||||
|
|
|
@ -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.
|
||||
If everything is correct, save each one of the articles, save the
|
||||
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)
|
||||
# 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
|
||||
purchases = []
|
||||
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:
|
||||
article = art_item.cleaned_data["article"]
|
||||
quantity = art_item.cleaned_data["quantity"]
|
||||
|
|
Loading…
Reference in a new issue