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
Empty file.
32 changes: 32 additions & 0 deletions product_currency/demo/product_currency_demo.py
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`"""
Comment on lines +4 to +8
Copy link

Copilot AI Mar 11, 2026

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__.py del módulo (ni desde models). 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 a models/ o importar explícitamente from . import demo (y en demo/__init__.py importar product_currency_demo).

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El demo está asignando force_currency_id a la misma moneda de la compañía (company.currency_id), por lo que el test no valida el caso real de “forzar una moneda distinta a la de la compañía” (pasaría incluso si _compute_currency_id no hiciera nada). Para que el test tenga valor, elegí una moneda distinta (p. ej. USD/EUR) y, si coincide con la de la compañía, caé en una alternativa.

Copilot uses AI. Check for mistakes.
}
]
}

# 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
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.env["account.chart.template"] va a fallar si el módulo account no está instalado (y product_currency no depende de account). Además _load_data es un método interno. Para mantener el addon instalable solo con product, registrá el XML ID creando el ir.model.data del registro demo (o volvé a definir el demo en XML). Alternativamente, si realmente querés depender de ese loader, agregá account a depends.

Copilot uses AI. Check for mistakes.
17 changes: 7 additions & 10 deletions product_currency/demo/product_product_demo.xml
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')"/>
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El XML está referenciando base.company_ri, pero no hay otros usos en el repo y sí hay referencias a base.main_company. Si ese XML ID no existe en la base, la carga de demo va a fallar. Cambiá el ref(...) por un XML ID garantizado (p. ej. base.main_company) o evitá pasar una compañía fija y resolvela en Python con self.env.company.

Suggested change
<arg eval="ref('base.company_ri')"/>
<arg eval="ref('base.main_company')"/>

Copilot uses AI. Check for mistakes.
</function>
</data>
</odoo>
1 change: 1 addition & 0 deletions product_currency/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Package for tests
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El paquete product_currency.tests no está importando el módulo de tests, así que test_product_currency_demo.py probablemente no se ejecuta. En este repositorio los tests/__init__.py suelen hacer from . import <test_module> (ver otros addons). Añadí el import correspondiente para asegurar que el runner cargue estos tests.

Suggested change
# Package for tests
# Package for tests
from . import test_product_currency_demo

Copilot uses AI. Check for mistakes.
39 changes: 39 additions & 0 deletions product_currency/tests/test_product_currency_demo.py
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
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En setUpClass se está capturando Exception al hacer env.ref(...) y luego se hace skipTest, lo que puede ocultar errores reales (no solo “XML ID no encontrado”). Sería mejor capturar el error esperado (normalmente ValueError) y, para saltar desde setUpClass, levantar unittest.SkipTest explícitamente.

Copilot uses AI. Check for mistakes.

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",
)
Loading