mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +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.status_code, 302)
|
||||||
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
||||||
invoice = self.user.facture_set.first()
|
invoice = self.user.facture_set.first()
|
||||||
|
cotisations = invoice.get_subscription()
|
||||||
delta = relativedelta(self.user.end_connexion(), date)
|
delta = relativedelta(self.user.end_connexion(), date)
|
||||||
delta.microseconds = 0
|
delta.microseconds = 0
|
||||||
self.assertEqual(delta, relativedelta(months=1, days=7))
|
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):
|
def test_several_articles_creates_several_purchases(self):
|
||||||
data = {
|
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.
|
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"]
|
||||||
|
|
Loading…
Reference in a new issue