Browse Source

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

[FIX] - fix flake8
pull/207/head
sbejaoui 6 years ago
parent
commit
494892f6b1
  1. 3
      contract/migrations/12.0.2.0.0/pre-migration.py
  2. 33
      contract/models/contract.py
  3. 1
      contract/models/contract_line.py
  4. 10
      contract/tests/test_contract.py
  5. 1
      contract_sale/__manifest__.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
)
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)
)

33
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

1
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

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.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'

1
contract_sale/__manifest__.py

@ -15,6 +15,7 @@
'data': [
'security/ir.model.access.csv',
'security/account_analytic_account_security.xml',
'views/abstract_contract_line.xml',
'views/contract.xml',
'views/contract_line.xml',
'views/contract_template.xml',

Loading…
Cancel
Save