From 21a019928d4f15d963d786b5f49bce96940eefbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Lizana=20Ram=C3=ADrez?= Date: Fri, 8 Nov 2024 17:56:56 +0100 Subject: [PATCH 1/2] [TEST] contract: Add test to reproduce issue with incorrect customer assignment on invoice generation from cron --- contract/tests/test_contract.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index 8f756b4f2b..a36f0ee127 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -1744,6 +1744,26 @@ def test_cron_recurring_create_invoice(self): len(invoice_lines), ) + def test_cron_recurring_create_invoice_several_partners(self): + self.acct_line.date_start = "2018-01-01" + self.acct_line.recurring_invoicing_type = "post-paid" + self.acct_line.date_end = "2018-03-15" + other_partner = self.env.ref('base.res_partner_1') + contracts = self.contract2 + contracts |= self.contract.copy({'partner_id': other_partner.id}) + self.env["contract.contract"].cron_recurring_create_invoice() + invoice_lines = self.env["account.move.line"].search( + [("contract_line_id", "in", contracts.mapped("contract_line_ids").ids)] + ) + self.assertEqual( + len(contracts.mapped("contract_line_ids")), + len(invoice_lines), + ) + self.assertEqual(len(invoice_lines.mapped('move_id')), 2) + self.assertEqual(len(invoice_lines.mapped('move_id.partner_id')), 2) + self.assertIn( + other_partner, invoice_lines.mapped('move_id.partner_id')) + def test_recurring_create_invoice(self): self.acct_line.date_start = "2024-01-01" self.acct_line.recurring_invoicing_type = "pre-paid" From 10fc78b87d0efeec5d8913101549e6b752e33875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Lizana=20Ram=C3=ADrez?= Date: Fri, 8 Nov 2024 18:23:14 +0100 Subject: [PATCH 2/2] [TEST] contract: Add unit test for invoicing multiple contracts with different customers --- contract/tests/test_contract.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index a36f0ee127..2c0c0fd7ba 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -1745,12 +1745,9 @@ def test_cron_recurring_create_invoice(self): ) def test_cron_recurring_create_invoice_several_partners(self): - self.acct_line.date_start = "2018-01-01" - self.acct_line.recurring_invoicing_type = "post-paid" - self.acct_line.date_end = "2018-03-15" - other_partner = self.env.ref('base.res_partner_1') - contracts = self.contract2 - contracts |= self.contract.copy({'partner_id': other_partner.id}) + other_partner = self.env.ref("base.res_partner_1") + contracts = self.contract + contracts |= self.contract.copy({"invoice_partner_id": other_partner.id}) self.env["contract.contract"].cron_recurring_create_invoice() invoice_lines = self.env["account.move.line"].search( [("contract_line_id", "in", contracts.mapped("contract_line_ids").ids)] @@ -1759,10 +1756,9 @@ def test_cron_recurring_create_invoice_several_partners(self): len(contracts.mapped("contract_line_ids")), len(invoice_lines), ) - self.assertEqual(len(invoice_lines.mapped('move_id')), 2) - self.assertEqual(len(invoice_lines.mapped('move_id.partner_id')), 2) - self.assertIn( - other_partner, invoice_lines.mapped('move_id.partner_id')) + self.assertEqual(len(invoice_lines.mapped("move_id")), 2) + self.assertEqual(len(invoice_lines.mapped("move_id.partner_id")), 2) + self.assertIn(other_partner, invoice_lines.mapped("move_id.partner_id")) def test_recurring_create_invoice(self): self.acct_line.date_start = "2024-01-01"