Browse Source

[IMP] contract: Add extend existing invoice possibility

pull/202/head
Carlos Dauden 7 years ago
committed by Pedro M. Baeza
parent
commit
cd32e53308
  1. 2
      contract/__manifest__.py
  2. 26
      contract/models/account_analytic_account.py
  3. 13
      contract/tests/test_contract.py

2
contract/__manifest__.py

@ -8,7 +8,7 @@
{
'name': 'Contracts Management - Recurring',
'version': '11.0.2.0.0',
'version': '11.0.2.0.1',
'category': 'Contract Management',
'license': 'AGPL-3',
'author': "OpenERP SA, "

26
contract/models/account_analytic_account.py

@ -236,10 +236,30 @@ class AccountAnalyticAccount(models.Model):
return invoice._convert_to_write(invoice._cache)
@api.multi
def _create_invoice(self):
def _prepare_invoice_update(self, invoice):
vals = self._prepare_invoice()
update_vals = {
'contract_id': self.id,
'date_invoice': vals.get('date_invoice', False),
'reference': ' '.join(filter(None, [
invoice.reference, vals.get('reference')])),
'origin': ' '.join(filter(None, [
invoice.origin, vals.get('origin')])),
}
return update_vals
@api.multi
def _create_invoice(self, invoice=False):
"""
:param invoice: If not False add lines to this invoice
:return: invoice created or updated
"""
self.ensure_one()
invoice_vals = self._prepare_invoice()
invoice = self.env['account.invoice'].create(invoice_vals)
if invoice and invoice.state == 'draft':
invoice.update(self._prepare_invoice_update(invoice))
else:
invoice = self.env['account.invoice'].create(
self._prepare_invoice())
for line in self.recurring_invoice_line_ids:
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
if invoice_line_vals:

13
contract/tests/test_contract.py

@ -303,3 +303,16 @@ class TestContract(TestContractBase):
self.assertTrue(self.contract.create_invoice_visibility)
self.contract.date_end = '2016-01-01'
self.assertFalse(self.contract.create_invoice_visibility)
def test_extend_invoice(self):
AccountInvoice = self.env['account.invoice']
self.contract.recurring_create_invoice()
invoice = AccountInvoice.search(
[('contract_id', '=', self.contract.id)])
invoice.origin = 'Orig Invoice'
self.contract._create_invoice(invoice)
self.assertEqual(invoice.origin, 'Orig Invoice Test Contract')
invoice_count = AccountInvoice.search_count(
[('contract_id', '=', self.contract.id)])
self.assertEqual(invoice_count, 1)
self.assertEqual(len(invoice.invoice_line_ids), 2)
Loading…
Cancel
Save