diff --git a/contract/models/abstract_contract_line.py b/contract/models/abstract_contract_line.py index a1ed154dc..a7c603367 100644 --- a/contract/models/abstract_contract_line.py +++ b/contract/models/abstract_contract_line.py @@ -59,6 +59,8 @@ class ContractAbstractContractLine(models.AbstractModel): ('weekly', 'Week(s)'), ('monthly', 'Month(s)'), ('monthlylastday', 'Month(s) last day'), + ('quarterly', 'Quarter(s)'), + ('semesterly', 'Semester(s)'), ('yearly', 'Year(s)'), ], default='monthly', diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index e5074d654..d67447965 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -799,6 +799,10 @@ class ContractLine(models.Model): return relativedelta(months=interval) elif recurring_rule_type == 'monthlylastday': return relativedelta(months=interval, day=1) + elif recurring_rule_type == 'quarterly': + return relativedelta(months=3 * interval) + elif recurring_rule_type == 'semesterly': + return relativedelta(months=6 * interval) else: return relativedelta(years=interval) diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index e4b9c7d77..c31c2cbc5 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -272,6 +272,66 @@ class TestContract(TestContractBase): ) self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + def test_contract_quarterly_pre_paid(self): + recurring_next_date = to_date('2018-05-22') + last_date_invoiced = to_date('2018-05-21') + self.acct_line.date_end = '2020-02-22' + self.acct_line.recurring_next_date = '2018-02-22' + self.acct_line.recurring_rule_type = 'quarterly' + self.acct_line.recurring_invoicing_type = 'pre-paid' + self.contract.recurring_create_invoice() + invoices_weekly = self.contract._get_related_invoices() + self.assertTrue(invoices_weekly) + self.assertEqual( + self.acct_line.recurring_next_date, recurring_next_date + ) + self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + + def test_contract_quarterly_post_paid(self): + recurring_next_date = to_date('2018-05-22') + last_date_invoiced = to_date('2018-02-21') + self.acct_line.date_end = '2020-02-22' + self.acct_line.recurring_next_date = '2018-02-22' + self.acct_line.recurring_rule_type = 'quarterly' + self.acct_line.recurring_invoicing_type = 'post-paid' + self.contract.recurring_create_invoice() + invoices_weekly = self.contract._get_related_invoices() + self.assertTrue(invoices_weekly) + self.assertEqual( + self.acct_line.recurring_next_date, recurring_next_date + ) + self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + + def test_contract_semesterly_pre_paid(self): + recurring_next_date = to_date('2018-08-22') + last_date_invoiced = to_date('2018-08-21') + self.acct_line.date_end = '2020-02-22' + self.acct_line.recurring_next_date = '2018-02-22' + self.acct_line.recurring_rule_type = 'semesterly' + self.acct_line.recurring_invoicing_type = 'pre-paid' + self.contract.recurring_create_invoice() + invoices_weekly = self.contract._get_related_invoices() + self.assertTrue(invoices_weekly) + self.assertEqual( + self.acct_line.recurring_next_date, recurring_next_date + ) + self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + + def test_contract_semesterly_post_paid(self): + recurring_next_date = to_date('2018-08-22') + last_date_invoiced = to_date('2018-02-21') + self.acct_line.date_end = '2020-02-22' + self.acct_line.recurring_next_date = '2018-02-22' + self.acct_line.recurring_rule_type = 'semesterly' + self.acct_line.recurring_invoicing_type = 'post-paid' + self.contract.recurring_create_invoice() + invoices_weekly = self.contract._get_related_invoices() + self.assertTrue(invoices_weekly) + self.assertEqual( + self.acct_line.recurring_next_date, recurring_next_date + ) + self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + def test_last_invoice_post_paid(self): self.acct_line.date_start = '2018-01-01' self.acct_line.recurring_invoicing_type = 'post-paid' diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index 3ce6bdc44..0e784d993 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -22,6 +22,8 @@ class ProductTemplate(models.Model): ('weekly', 'Week(s)'), ('monthly', 'Month(s)'), ('monthlylastday', 'Month(s) last day'), + ('quarterly', 'Quarter(s)'), + ('semesterly', 'Semester(s)'), ('yearly', 'Year(s)'), ], default='monthly', diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index bcaf1cef8..4883306db 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -27,6 +27,8 @@ class SaleOrderLine(models.Model): ('weekly', 'Week(s)'), ('monthly', 'Month(s)'), ('monthlylastday', 'Month(s) last day'), + ('quarterly', 'Quarter(s)'), + ('semesterly', 'Semester(s)'), ('yearly', 'Year(s)'), ], default='monthly',