-
Notifications
You must be signed in to change notification settings - Fork 104
[IMP] product_currency: add demo data and tests for product currency #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }, | ||
|
Comment on lines
+11
to
+21
|
||
| } | ||
| ] | ||
| } | ||
|
|
||
| # 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) | ||
|
Comment on lines
+26
to
+32
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,9 @@ | ||||||
| <?xml version="1.0" encoding="utf-8"?> | ||||||
| <odoo noupdate="1"> | ||||||
| <record id="product_with_forced_currency" model="product.product"> | ||||||
| <field name="name">Product with forced currency (EUR)</field> | ||||||
| <field name="categ_id" ref="product.product_category_goods"/> | ||||||
| <field name="standard_price">50</field> | ||||||
| <field name="list_price">100</field> | ||||||
| <field name="currency_id" ref="base.USD"/> | ||||||
| <field name="force_currency_id" ref="base.EUR"/> | ||||||
| <field name="type">consu</field> | ||||||
| </record> | ||||||
| <odoo> | ||||||
| <data noupdate="1"> | ||||||
| <!-- Trigger the python demo loader to create minimal demo data --> | ||||||
| <function model="product.template" name="_install_product_currency_demo"> | ||||||
| <arg eval="ref('base.company_ri')"/> | ||||||
|
||||||
| <arg eval="ref('base.company_ri')"/> | |
| <arg eval="ref('base.main_company')"/> |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||
| # Package for tests | ||||||||||
|
||||||||||
| # Package for tests | |
| # Package for tests | |
| from . import test_product_currency_demo |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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") | ||
|
Comment on lines
+16
to
+20
|
||
|
|
||
| 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", | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este método demo está definido en
product_currency/demo/product_currency_demo.py, pero ese directorio no se importa desde el__init__.pydel módulo (ni desdemodels). En instalación con demo, la llamada XML<function ... name="_install_product_currency_demo">y el test van a fallar porque el método no estará en el registry. Solución: mover este mixin amodels/o importar explícitamentefrom . import demo(y endemo/__init__.pyimportarproduct_currency_demo).