mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract_invoice_merge_by_partner: Tests and improvements.
This commit is contained in:
@@ -18,7 +18,11 @@ To install this module you need *account_invoice_merge*, available in:
|
||||
Usage
|
||||
=====
|
||||
|
||||
#. Go to ...
|
||||
#. Go to *Sales > Contracts* and create some contrats with same partner
|
||||
#. Go to *Settings > Automation > Scheduled Actions*
|
||||
#. Select *Generate Recurring Invoices from Contracts*
|
||||
#. Set previous time that now in *Next Execution Date*
|
||||
#. Go to *Invoicing > Customer Invoices* and show merged invoice
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
|
||||
@@ -10,7 +10,8 @@ class PurchaseOrderLine(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _recurring_create_invoice(self, automatic=False):
|
||||
invoices = self.env['account.invoice'].browse(
|
||||
invoice_obj = self.env['account.invoice']
|
||||
invoices = invoice_obj.browse(
|
||||
super(PurchaseOrderLine, self)._recurring_create_invoice(automatic)
|
||||
)
|
||||
res = []
|
||||
@@ -22,7 +23,9 @@ class PurchaseOrderLine(models.Model):
|
||||
keep_references=True, date_invoice=False)
|
||||
res.extend(invoices_info.keys())
|
||||
for inv_ids_list in invoices_info.values():
|
||||
unlink_list.append(inv_ids_list)
|
||||
unlink_list.extend(inv_ids_list)
|
||||
else:
|
||||
res.append(inv_to_merge.id)
|
||||
if unlink_list:
|
||||
invoice_obj.browse(unlink_list).unlink()
|
||||
return res
|
||||
|
||||
@@ -9,3 +9,36 @@ class TestContractInvoiceMergeByPartner(TransactionCase):
|
||||
""" Use case : Prepare some data for current test case """
|
||||
def setUp(self):
|
||||
super(TestContractInvoiceMergeByPartner, self).setUp()
|
||||
#self.partner = self.env.ref('base.res_partner_2')
|
||||
self.partner = self.env['res.partner'].create(
|
||||
{'customer': True,
|
||||
'name': "Test Customer"
|
||||
})
|
||||
self.product = self.env.ref('product.product_product_consultant')
|
||||
self.uom = self.env.ref('product.product_uom_hour')
|
||||
self.contract1 = self.env['account.analytic.account'].create({
|
||||
'name': 'Test contract',
|
||||
'partner_id': self.partner.id,
|
||||
'type': 'contract',
|
||||
'recurring_invoices': True,
|
||||
'recurring_rule_type': 'monthly',
|
||||
'recurring_interval': 1,
|
||||
'recurring_invoice_line_ids': [
|
||||
(0, 0, {'quantity': 2.0,
|
||||
'price_unit': 100.0,
|
||||
'name': self.product.name,
|
||||
'product_id': self.product.id,
|
||||
'uom_id': self.uom.id})],
|
||||
})
|
||||
self.contract2 = self.contract1.copy()
|
||||
self.contract3 = self.contract1.copy()
|
||||
self.contract4 = self.contract1.copy()
|
||||
|
||||
def test_invoices_merged(self):
|
||||
self.env['account.analytic.account']._cron_recurring_create_invoice()
|
||||
invoices = self.env['account.invoice'].search(
|
||||
[('partner_id', '=', self.partner.id)])
|
||||
inv_draft = invoices.filtered(lambda x: x.state == 'draft')
|
||||
self.assertEqual(len(inv_draft), 1)
|
||||
inv_cancel = invoices.filtered(lambda x: x.state == 'cancel')
|
||||
self.assertFalse(inv_cancel)
|
||||
|
||||
Reference in New Issue
Block a user