diff --git a/subscription_oca/__manifest__.py b/subscription_oca/__manifest__.py index 58335fe6eb..e765feb89f 100644 --- a/subscription_oca/__manifest__.py +++ b/subscription_oca/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Subscription management", "summary": "Generate recurring invoices.", - "version": "19.0.1.0.0", + "version": "19.0.1.1.0", "development_status": "Beta", "category": "Subscription Management", "website": "https://github.com/OCA/contract", @@ -23,6 +23,7 @@ "data/sale_subscription_data.xml", "wizard/close_subscription_wizard.xml", "security/ir.model.access.csv", + "security/security.xml", ], "installable": True, "application": True, diff --git a/subscription_oca/models/sale_subscription.py b/subscription_oca/models/sale_subscription.py index e44e9da11f..2dda1240f9 100644 --- a/subscription_oca/models/sale_subscription.py +++ b/subscription_oca/models/sale_subscription.py @@ -300,6 +300,7 @@ def _prepare_account_move(self, line_ids): } if self.journal_id: values["journal_id"] = self.journal_id.id + values["currency_id"] = self.pricelist_id.currency_id.id return values def create_invoice(self): @@ -308,6 +309,7 @@ def create_invoice(self): self.check_access("write") except AccessError: return self.env["account.move"] + self = self.with_company(self.company_id) line_ids = [] for line in self.sale_subscription_line_ids: line_values = line._prepare_account_move_line() diff --git a/subscription_oca/security/security.xml b/subscription_oca/security/security.xml new file mode 100644 index 0000000000..9750ca103f --- /dev/null +++ b/subscription_oca/security/security.xml @@ -0,0 +1,11 @@ + + + + Multi-Company Subscription Management + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + diff --git a/subscription_oca/tests/test_subscription_oca.py b/subscription_oca/tests/test_subscription_oca.py index 29d301ee1f..011194d1c4 100644 --- a/subscription_oca/tests/test_subscription_oca.py +++ b/subscription_oca/tests/test_subscription_oca.py @@ -791,3 +791,58 @@ def test_manual_discount_persistence(self): 10.0, "Manual discount was lost after changing the quantity (Bug #1320)", ) + + def test_prepare_account_move_sets_pricelist_currency(self): + """Test that the invoice currency matches + the subscription pricelist currency.""" + subscription = self.create_sub( + { + "pricelist_id": self.pricelist2.id, + } + ) + vals = subscription._prepare_account_move([]) + expected_currency_id = subscription.pricelist_id.currency_id.id + self.assertIn("currency_id", vals) + self.assertEqual( + vals["currency_id"], + expected_currency_id, + "The currency_id field must be equal to the currency of the pricelist.", + ) + + def test_create_invoice_uses_subscription_company(self): + """Test that the invoice is created in the subscription's company + and with the correct currency.""" + company_alt = self.env["res.company"].create( + {"name": "Another Company", "currency_id": self.env.ref("base.USD").id} + ) + sale_journal_alt = self.env["account.journal"].create( + { + "name": "Sale Journal Alt", + "type": "sale", + "code": "SALT", + "company_id": company_alt.id, + } + ) + pricelist = self.env["product.pricelist"].create( + {"name": "Pricelist EUR", "currency_id": self.env.ref("base.EUR").id} + ) + subscription = self.create_sub( + { + "company_id": company_alt.id, + "pricelist_id": pricelist.id, + "journal_id": sale_journal_alt.id, + } + ) + invoice = subscription.create_invoice() + self.assertTrue(invoice, "The invoice should have been created successfully.") + self.assertEqual( + invoice.company_id, + subscription.company_id, + "The invoice must belong to the subscription's company (with_company).", + ) + self.assertEqual( + invoice.currency_id, + subscription.pricelist_id.currency_id, + """The invoice must have the currency of the pricelist + defined in the subscription.""", + )