Skip to content

[IMP] product_currency: add demo data and tests for product currency#869

Open
cav-adhoc wants to merge 1 commit intoingadhoc:19.0from
adhoc-dev:19.0-t-64641-cav
Open

[IMP] product_currency: add demo data and tests for product currency#869
cav-adhoc wants to merge 1 commit intoingadhoc:19.0from
adhoc-dev:19.0-t-64641-cav

Conversation

@cav-adhoc
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings March 11, 2026 14:34
@roboadhoc
Copy link

Pull request status dashboard

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Este PR busca añadir datos demo y tests automatizados para validar el comportamiento de “moneda forzada” en product.template dentro del addon product_currency.

Changes:

  • Añade un test transaccional que intenta instalar/cargar datos demo y verificar el efecto de force_currency_id.
  • Sustituye el demo XML de producto por una llamada a una función Python que genera demo data.
  • Incorpora el generador de demo data en Python.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

File Description
product_currency/tests/test_product_currency_demo.py Nuevos tests para validar moneda forzada y aislamiento al copiar registros demo.
product_currency/tests/init.py Inicialización del paquete de tests.
product_currency/demo/product_product_demo.xml Cambia demo XML directo por ejecución de función Python para cargar demo.
product_currency/demo/product_currency_demo.py Implementa el loader Python que crea el producto demo y pretende registrar XML IDs.

Comment on lines +11 to +21
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,
},
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.
Comment on lines +16 to +20
# 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")
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.
@@ -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.
Comment on lines +4 to +8
class ProductTemplateDemo(models.Model):
_inherit = "product.template"

def _install_product_currency_demo(self, company):
"""Create minimal demo using `account.chart.template._load_data`"""
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.
<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.
Comment on lines +26 to +32
# 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)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants