diff --git a/product_currency/demo/__init__.py b/product_currency/demo/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/product_currency/demo/product_currency_demo.py b/product_currency/demo/product_currency_demo.py new file mode 100644 index 000000000..350319d91 --- /dev/null +++ b/product_currency/demo/product_currency_demo.py @@ -0,0 +1,32 @@ +from odoo import models + + +class ProductTemplateDemo(models.Model): + _inherit = "product.template" + + def _install_product_currency_demo(self, company): + """Create minimal demo using `account.chart.template._load_data`""" + self = self.with_company(company) + + currency = company.currency_id or self.env["res.currency"].search([], limit=1) + data = { + "product.template": [ + { + "xml_id": "demo_product_1", + "values": { + "name": "Demo Product (force currency)", + "type": "consu", + "company_id": company.id, + "force_currency_id": currency.id, + }, + } + ] + } + + # Require account.chart.template._load_data to register XML IDs + chart_template = self.env["account.chart.template"] + if not hasattr(chart_template, "_load_data"): + raise RuntimeError("account.chart.template._load_data is required to load demo data") + + # Use chart template loader with company context to register XML IDs + chart_template.with_company(company)._load_data(data) diff --git a/product_currency/demo/product_product_demo.xml b/product_currency/demo/product_product_demo.xml index 1f2f1ab35..5722dd0a9 100644 --- a/product_currency/demo/product_product_demo.xml +++ b/product_currency/demo/product_product_demo.xml @@ -1,12 +1,9 @@ - - - Product with forced currency (EUR) - - 50 - 100 - - - consu - + + + + + + + diff --git a/product_currency/tests/__init__.py b/product_currency/tests/__init__.py new file mode 100644 index 000000000..4bcce808f --- /dev/null +++ b/product_currency/tests/__init__.py @@ -0,0 +1 @@ +# Package for tests diff --git a/product_currency/tests/test_product_currency_demo.py b/product_currency/tests/test_product_currency_demo.py new file mode 100644 index 000000000..f858f2786 --- /dev/null +++ b/product_currency/tests/test_product_currency_demo.py @@ -0,0 +1,39 @@ +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + + +@tagged("post_install", "-at_install") +class TestProductCurrencyDemo(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.company + + loader = cls.env["product.template"] + # Install the module demo data dynamically + loader._install_product_currency_demo(cls.company) + + # Require the XML id to be registered by chart template loader + try: + cls.demo_product = cls.env.ref("product_currency.demo_product_1") + except Exception: + cls.skipTest("Demo XML id not registered: product_currency.demo_product_1") + + def test_01_force_currency_applies(self): + """Verifica que cuando existe `force_currency_id`, `currency_id` se fuerza.""" + prod = self.demo_product.copy() + self.assertEqual( + prod.force_currency_id.id, + prod.currency_id.id, + "El currency_id debe ser igual a force_currency_id", + ) + + def test_02_modifying_copy_does_not_change_demo(self): + """Modificar una copia no debe afectar al registro demo original.""" + prod_copy = self.demo_product.copy() + prod_copy.write({"name": "Modified copy"}) + self.assertNotEqual( + self.demo_product.name, + prod_copy.name, + "Modificar la copia no debe cambiar el demo original", + )