mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract: Add extend existing invoice possibility
This commit is contained in:
committed by
Pedro M. Baeza
parent
80e778f4e7
commit
cd32e53308
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Contracts Management - Recurring',
|
'name': 'Contracts Management - Recurring',
|
||||||
'version': '11.0.2.0.0',
|
'version': '11.0.2.0.1',
|
||||||
'category': 'Contract Management',
|
'category': 'Contract Management',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': "OpenERP SA, "
|
'author': "OpenERP SA, "
|
||||||
|
|||||||
@@ -236,10 +236,30 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
return invoice._convert_to_write(invoice._cache)
|
return invoice._convert_to_write(invoice._cache)
|
||||||
|
|
||||||
@api.multi
|
@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()
|
self.ensure_one()
|
||||||
invoice_vals = self._prepare_invoice()
|
if invoice and invoice.state == 'draft':
|
||||||
invoice = self.env['account.invoice'].create(invoice_vals)
|
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:
|
for line in self.recurring_invoice_line_ids:
|
||||||
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
|
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
|
||||||
if invoice_line_vals:
|
if invoice_line_vals:
|
||||||
|
|||||||
@@ -303,3 +303,16 @@ class TestContract(TestContractBase):
|
|||||||
self.assertTrue(self.contract.create_invoice_visibility)
|
self.assertTrue(self.contract.create_invoice_visibility)
|
||||||
self.contract.date_end = '2016-01-01'
|
self.contract.date_end = '2016-01-01'
|
||||||
self.assertFalse(self.contract.create_invoice_visibility)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user