From 6a928a2b2a9ee9e2a24edd3db23f0202e5939d9c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 9 Aug 2020 10:18:15 +0200 Subject: [PATCH] Fix tests for billing --- uncloud_pay/models.py | 11 +++++++++-- uncloud_pay/tests.py | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 5f2b5d3..7232cd3 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -327,7 +327,7 @@ class Order(models.Model): One time orders have a recurring period of 0, so this work universally """ - return self.starting_date + timedelta(seconds=self.recurring_period) + return self.starting_date + datetime.timedelta(seconds=self.recurring_period) @property @@ -438,7 +438,7 @@ class Bill(models.Model): starting_date = last_bill.starting_date ending_date = bill.ending_date else: - starting_date = last_bill.end_date + datetime.timedelta(seconds=1) + starting_date = last_bill.ending_date + datetime.timedelta(seconds=1) else: if first_order: starting_date = first_order.starting_date @@ -566,6 +566,13 @@ class Bill(models.Model): # For each recurring order get the usage and bill it + def close(self): + """ + Close/finish a bill + """ + + self.is_final = True + self.save() class BillRecord(models.Model): """ diff --git a/uncloud_pay/tests.py b/uncloud_pay/tests.py index 9a26e2b..7acd7d4 100644 --- a/uncloud_pay/tests.py +++ b/uncloud_pay/tests.py @@ -188,9 +188,10 @@ class BillAndOrderTestCase(TestCase): """ for ending_date in self.bill_dates: - Bill.create_next_bill_for_user(self.recurring_user, ending_date) + b = Bill.create_next_bill_for_user(self.recurring_user, ending_date) + b.close() - bills_count = Bill.objects.filter(owner=self.recurring_user).count() + bill_count = Bill.objects.filter(owner=self.recurring_user).count() self.assertEqual(len(self.bill_dates), bill_count)