Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subscription_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions subscription_oca/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="subscription_multi_company_rule" model="ir.rule">
<field name="name">Multi-Company Subscription Management</field>
<field name="model_id" ref="subscription_oca.model_sale_subscription" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]" />
</record>
</odoo>
55 changes: 55 additions & 0 deletions subscription_oca/tests/test_subscription_oca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.""",
)
Loading