diff --git a/sale_automatic_workflow/models/automatic_workflow_job.py b/sale_automatic_workflow/models/automatic_workflow_job.py index 1352bf17155..8d777671f54 100644 --- a/sale_automatic_workflow/models/automatic_workflow_job.py +++ b/sale_automatic_workflow/models/automatic_workflow_job.py @@ -155,6 +155,7 @@ def _register_payments(self, payment_filter): return def _register_payment_invoice(self, invoice): + self = self.with_company(invoice.company_id) payment = self.env["account.payment"].create( self._prepare_dict_account_payment(invoice) ) diff --git a/sale_automatic_workflow/tests/test_multicompany.py b/sale_automatic_workflow/tests/test_multicompany.py index 50f45abe5d6..bd8c3331ffc 100644 --- a/sale_automatic_workflow/tests/test_multicompany.py +++ b/sale_automatic_workflow/tests/test_multicompany.py @@ -47,3 +47,22 @@ def test_sale_order_multicompany(self): self.assertEqual( invoice_fr_daughter.journal_id.company_id, order_fr_daughter.company_id ) + + # Test payment register + self.auto_wkf.register_payment = True + self.env["automatic.workflow.job"].run() + self.assertIn(invoice_fr.payment_state, ["in_payment", "paid"]) + self.assertIn(invoice_ch.payment_state, ["in_payment", "paid"]) + self.assertIn(invoice_be.payment_state, ["in_payment", "paid"]) + self.assertIn(invoice_fr_daughter.payment_state, ["in_payment", "paid"]) + # Check payment journal company matches the order company + payment_fr = invoice_fr.matched_payment_ids + payment_ch = invoice_ch.matched_payment_ids + payment_be = invoice_be.matched_payment_ids + payment_fr_daughter = invoice_fr_daughter.matched_payment_ids + self.assertEqual(payment_fr.journal_id.company_id, order_fr.company_id) + self.assertEqual(payment_ch.journal_id.company_id, order_ch.company_id) + self.assertEqual(payment_be.journal_id.company_id, order_be.company_id) + self.assertEqual( + payment_fr_daughter.journal_id.company_id, order_fr_daughter.company_id + )