Browse Source

[FIX] - default value for active field in contract line

[FIX] - fix flake8
13.0-mig-contract
sbejaoui 6 years ago
committed by Administrator
parent
commit
7c3c11efbb
  1. 3
      contract/migrations/12.0.2.0.0/pre-migration.py
  2. 25
      contract/models/contract.py
  3. 1
      contract/models/contract_line.py
  4. 10
      contract/tests/test_contract.py

3
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 lambda c: not c.create_invoice_visibility
) )
cr.execute( 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) % ','.join(finished_contract.ids)
) )

25
contract/models/contract.py

@ -176,9 +176,7 @@ class AccountAnalyticAccount(models.Model):
return { return {
'reference': self.code, 'reference': self.code,
'type': invoice_type, '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, 'currency_id': currency.id,
'date_invoice': date_invoice, 'date_invoice': date_invoice,
'journal_id': journal.id, 'journal_id': journal.id,
@ -236,11 +234,13 @@ class AccountAnalyticAccount(models.Model):
price_unit = invoice_line.price_unit price_unit = invoice_line.price_unit
invoice_line.invoice_id = new_invoice invoice_line.invoice_id = new_invoice
invoice_line._onchange_product_id() invoice_line._onchange_product_id()
invoice_line.update({
invoice_line.update(
{
'name': name, 'name': name,
'account_analytic_id': account_analytic_id, 'account_analytic_id': account_analytic_id,
'price_unit': price_unit, 'price_unit': price_unit,
})
}
)
return new_invoice._convert_to_write(new_invoice._cache) return new_invoice._convert_to_write(new_invoice._cache)
@api.model @api.model
@ -264,7 +264,8 @@ class AccountAnalyticAccount(models.Model):
final_invoices_values = [] final_invoices_values = []
for invoice_values in invoices_values: for invoice_values in invoices_values:
final_invoices_values.append( 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) invoices = self.env['account.invoice'].create(final_invoices_values)
self._finalize_invoice_creation(invoices) self._finalize_invoice_creation(invoices)
return invoices return invoices
@ -297,11 +298,11 @@ class AccountAnalyticAccount(models.Model):
:return: contract lines (account.analytic.invoice.line recordset) :return: contract lines (account.analytic.invoice.line recordset)
""" """
self.ensure_one() self.ensure_one()
if date_ref:
return self.recurring_invoice_line_ids.filtered( 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
lambda l: not l.is_canceled
and l.recurring_next_date
and l.recurring_next_date <= date_ref
)
@api.multi @api.multi
def _prepare_recurring_invoices_values(self, date_ref=False): def _prepare_recurring_invoices_values(self, date_ref=False):
@ -315,6 +316,10 @@ class AccountAnalyticAccount(models.Model):
for contract in self: for contract in self:
if not date_ref: if not date_ref:
date_ref = contract.recurring_next_date 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) contract_lines = contract._get_lines_to_invoice(date_ref)
if not contract_lines: if not contract_lines:
continue continue

1
contract/models/contract_line.py

@ -83,6 +83,7 @@ class AccountAnalyticInvoiceLine(models.Model):
related="contract_id.active", related="contract_id.active",
store=True, store=True,
readonly=True, readonly=True,
default=True,
) )
@api.multi @api.multi

10
contract/tests/test_contract.py

@ -659,10 +659,6 @@ class TestContract(TestContractBase):
self.acct_line.write({'date_end': False, 'is_auto_renew': False}) self.acct_line.write({'date_end': False, 'is_auto_renew': False})
self.assertFalse(self.contract.date_end) 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): def test_stop_contract_line(self):
"""It should put end to the contract line""" """It should put end to the contract line"""
self.acct_line.write( self.acct_line.write(
@ -1292,8 +1288,10 @@ class TestContract(TestContractBase):
invoice_lines = self.env['account.invoice.line'].search( invoice_lines = self.env['account.invoice.line'].search(
[('account_analytic_id', 'in', contracts.ids)] [('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): def test_get_invoiced_period_monthlylastday(self):
self.acct_line.date_start = '2018-01-05' self.acct_line.date_start = '2018-01-05'

Loading…
Cancel
Save