From 4c36e1a3f4ff06cd1635ceaf60050814f38fd34c Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 14 Mar 2019 16:00:16 +0100 Subject: [PATCH] [FIX] - don't play onchange date_start for old lines on contract template change [FIX] - Fix stop post message [FIX] - Fix sale_contract_count should count all partner contract [FIX] - set recurring_next_date to False if contract line stoped at last date invoiced [FIX] - Group by next_invoice also considers dates in the past --- contract/models/contract.py | 2 +- contract/models/contract_line.py | 17 +++++++++-------- contract/models/res_partner.py | 4 ---- contract/tests/test_contract.py | 6 ++++++ contract/views/contract.xml | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/contract/models/contract.py b/contract/models/contract.py index e08c4622..74eb8fe0 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -183,7 +183,6 @@ class AccountAnalyticAccount(models.Model): ) ): self[field_name] = self.contract_template_id[field_name] - self.recurring_invoice_line_ids._onchange_date_start() @api.onchange('partner_id') def _onchange_partner_id(self): @@ -225,6 +224,7 @@ class AccountAnalyticAccount(models.Model): contract_line ) new_lines += contract_line_model.new(vals) + new_lines._onchange_date_start() return new_lines @api.multi diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index 29f9ed63..1fc654eb 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -658,8 +658,16 @@ class AccountAnalyticInvoiceLine(models.Model): rec.cancel() else: if not rec.date_end or rec.date_end > date_end: + old_date_end = rec.date_end + values = { + 'date_end': date_end, + 'is_auto_renew': False, + 'manual_renew_needed': manual_renew_needed, + } + if rec.last_date_invoiced == date_end: + values['recurring_next_date'] = False + rec.write(values) if post_message: - old_date_end = rec.date_end msg = _( """Contract line for {product} stopped:
@@ -671,13 +679,6 @@ class AccountAnalyticInvoiceLine(models.Model): ) ) rec.contract_id.message_post(body=msg) - rec.write( - { - 'date_end': date_end, - 'is_auto_renew': False, - "manual_renew_needed": manual_renew_needed, - } - ) else: rec.write( { diff --git a/contract/models/res_partner.py b/contract/models/res_partner.py index 2435d797..c18e00e9 100644 --- a/contract/models/res_partner.py +++ b/contract/models/res_partner.py @@ -16,14 +16,10 @@ class ResPartner(models.Model): def _compute_contract_count(self): contract_model = self.env['account.analytic.account'] - today = fields.Date.today() fetch_data = contract_model.read_group( [ ('recurring_invoices', '=', True), ('partner_id', 'child_of', self.ids), - '|', - ('date_end', '=', False), - ('date_end', '>=', today), ], ['partner_id', 'contract_type'], ['partner_id', 'contract_type'], diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index 4a7c1613..b21a9f8b 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -1807,3 +1807,9 @@ class TestContract(TestContractBase): self.contract.recurring_invoice_line_ids.cancel() self.contract.recurring_invoice_line_ids.unlink() self.assertFalse(self.contract.recurring_create_invoice()) + + def test_stop_at_last_date_invoiced(self): + self.contract.recurring_create_invoice() + self.assertTrue(self.acct_line.recurring_next_date) + self.acct_line.stop(self.acct_line.last_date_invoiced) + self.assertFalse(self.acct_line.recurring_next_date) diff --git a/contract/views/contract.xml b/contract/views/contract.xml index b7b74e5e..08398ca5 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -204,7 +204,7 @@