From 7c3c11efbb12fdd325e969dde5bd5d6ea29692d3 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 20 Dec 2018 22:08:34 +0100 Subject: [PATCH] [FIX] - default value for active field in contract line [FIX] - fix flake8 --- .../migrations/12.0.2.0.0/pre-migration.py | 3 +- contract/models/contract.py | 33 +++++++++++-------- contract/models/contract_line.py | 1 + contract/tests/test_contract.py | 10 +++--- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/contract/migrations/12.0.2.0.0/pre-migration.py b/contract/migrations/12.0.2.0.0/pre-migration.py index e8f42894..5262b394 100644 --- a/contract/migrations/12.0.2.0.0/pre-migration.py +++ b/contract/migrations/12.0.2.0.0/pre-migration.py @@ -19,6 +19,7 @@ def migrate(cr, version): lambda c: not c.create_invoice_visibility ) cr.execute( - "UPDATE account_analytic_account set recurring_next_date=null where id in (%)" + "UPDATE account_analytic_account set recurring_next_date=null " + "where id in (%)" % ','.join(finished_contract.ids) ) diff --git a/contract/models/contract.py b/contract/models/contract.py index abe72816..6579c02b 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -176,9 +176,7 @@ class AccountAnalyticAccount(models.Model): return { 'reference': self.code, 'type': invoice_type, - 'partner_id': self.partner_id.address_get(['invoice'])[ - 'invoice' - ], + 'partner_id': self.partner_id.address_get(['invoice'])['invoice'], 'currency_id': currency.id, 'date_invoice': date_invoice, 'journal_id': journal.id, @@ -236,11 +234,13 @@ class AccountAnalyticAccount(models.Model): price_unit = invoice_line.price_unit invoice_line.invoice_id = new_invoice invoice_line._onchange_product_id() - invoice_line.update({ - 'name': name, - 'account_analytic_id': account_analytic_id, - 'price_unit': price_unit, - }) + invoice_line.update( + { + 'name': name, + 'account_analytic_id': account_analytic_id, + 'price_unit': price_unit, + } + ) return new_invoice._convert_to_write(new_invoice._cache) @api.model @@ -264,7 +264,8 @@ class AccountAnalyticAccount(models.Model): final_invoices_values = [] for invoice_values in invoices_values: final_invoices_values.append( - self._finalize_invoice_values(invoice_values)) + self._finalize_invoice_values(invoice_values) + ) invoices = self.env['account.invoice'].create(final_invoices_values) self._finalize_invoice_creation(invoices) return invoices @@ -297,11 +298,11 @@ class AccountAnalyticAccount(models.Model): :return: contract lines (account.analytic.invoice.line recordset) """ self.ensure_one() - if date_ref: - return self.recurring_invoice_line_ids.filtered( - lambda l: not l.is_canceled and l.recurring_next_date - and l.recurring_next_date <= date_ref) - return False + return self.recurring_invoice_line_ids.filtered( + lambda l: not l.is_canceled + and l.recurring_next_date + and l.recurring_next_date <= date_ref + ) @api.multi def _prepare_recurring_invoices_values(self, date_ref=False): @@ -315,6 +316,10 @@ class AccountAnalyticAccount(models.Model): for contract in self: if not date_ref: date_ref = contract.recurring_next_date + if not date_ref: + # this use case is possible when recurring_create_invoice is + # called for a finished contract + continue contract_lines = contract._get_lines_to_invoice(date_ref) if not contract_lines: continue diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index d0addafb..a6c297dd 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -83,6 +83,7 @@ class AccountAnalyticInvoiceLine(models.Model): related="contract_id.active", store=True, readonly=True, + default=True, ) @api.multi diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index a15fb0e6..28ac91ba 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -659,10 +659,6 @@ class TestContract(TestContractBase): self.acct_line.write({'date_end': False, 'is_auto_renew': False}) self.assertFalse(self.contract.date_end) - def test_last_date_invoiced_prepaid(self): - self.contract.recurring_create_invoice() - self - def test_stop_contract_line(self): """It should put end to the contract line""" self.acct_line.write( @@ -1292,8 +1288,10 @@ class TestContract(TestContractBase): invoice_lines = self.env['account.invoice.line'].search( [('account_analytic_id', 'in', contracts.ids)] ) - self.assertEqual(len(contracts.mapped('recurring_invoice_line_ids')), - len(invoice_lines)) + self.assertEqual( + len(contracts.mapped('recurring_invoice_line_ids')), + len(invoice_lines), + ) def test_get_invoiced_period_monthlylastday(self): self.acct_line.date_start = '2018-01-05'