Skip to content

Conversation

@cav-adhoc
Copy link
Contributor

@cav-adhoc cav-adhoc commented Dec 22, 2025

This commit creates demo data for testing exchange rate differences in Odoo invoices for Argentinian companies. It:

  1. Sets up exchange rates: Creates USD/ARS rates for today and past 3 months (1300, 1200, 1100, 1000)

  2. Creates 3 customer invoices in USD with different amounts and tax combinations:

  • Invoice 1: 237.5 USD @ rate 1000
  • Invoice 2: 753.5 USD @ rate 1100
  • Invoice 3: 121 USD @ rate 1000 (different partner)
  1. Creates payments at different exchange rates to generate exchange differences:
  • Payment 1: 991 USD @ rate 1200 (for invoices 1 & 2)
  • Payment 2: 121 USD @ rate 1100 (for invoice 3)

Copilot AI review requested due to automatic review settings December 22, 2025 20:16
@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 agrega datos de demostración (demo data) al módulo account_exchange_difference_invoice para facilitar las pruebas y demostraciones de funcionalidad de diferencias de cambio en facturas.

Cambios principales:

  • Se crea un sistema de demo data programático vía Python en lugar del anterior basado únicamente en XML
  • Se generan tasas de cambio USD/ARS para diferentes períodos, facturas en USD con impuestos argentinos, y un pago que genera diferencias de cambio
  • Se reemplaza el archivo demo/demo_data.xml anterior por una nueva estructura modular

Reviewed changes

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

Show a summary per file
File Description
__manifest__.py Mueve la referencia del archivo demo de la sección 'demo' a 'data' y vacía la lista 'demo'
__init__.py Importa el nuevo módulo demo para registrar los modelos extendidos
demo/__init__.py Registra el módulo account_exchange_demo
demo/account_exchange_demo.xml Define la función XML que invoca la creación programática de demo data
demo/account_exchange_demo.py Implementa la lógica completa para crear tasas de cambio, facturas y pagos de demostración

Comment on lines +161 to +175
# Set exchange rate to 1000 before posting
if currency_usd:
invoice1.write({"currency_id": currency_usd.id})
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Se hace write() de currency_id inmediatamente después de crear la factura con currency_id ya asignado. Esta operación es redundante porque el campo ya se estableció en el create(). Si el propósito era forzar algún recompute, debería documentarse; de lo contrario, puede eliminarse.

Suggested change
# Set exchange rate to 1000 before posting
if currency_usd:
invoice1.write({"currency_id": currency_usd.id})

Copilot uses AI. Check for mistakes.
Comment on lines +199 to +212
if currency_usd:
invoice2.write({"currency_id": currency_usd.id})
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Se hace write() de currency_id inmediatamente después de crear la factura con currency_id ya asignado. Esta operación es redundante porque el campo ya se estableció en el create(). Si el propósito era forzar algún recompute, debería documentarse; de lo contrario, puede eliminarse.

Suggested change
if currency_usd:
invoice2.write({"currency_id": currency_usd.id})

Copilot uses AI. Check for mistakes.
limit=1,
)

# Invoice 1: Neto 21% (100) + IVA 21% (21) + Neto 10.5% (100) + IVA 10.5% (10.5) + Percep 3% (6) = 237.5 USD @ TC 1000
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

El comentario indica "# Invoice 1: ... @ TC 1000" pero no hay código que garantice que la tasa de cambio sea 1000 en la fecha de hoy. Aunque el método _create_exchange_rate_demo_data() crea una tasa de 1300 para hoy, el comentario menciona 1000. Esto genera confusión sobre cuál es la tasa esperada.

Suggested change
# Invoice 1: Neto 21% (100) + IVA 21% (21) + Neto 10.5% (100) + IVA 10.5% (10.5) + Percep 3% (6) = 237.5 USD @ TC 1000
# Invoice 1: Neto 21% (100) + IVA 21% (21) + Neto 10.5% (100) + IVA 10.5% (10.5) + Percep 3% (6) = 237.5 USD

Copilot uses AI. Check for mistakes.
invoice1.write({"currency_id": currency_usd.id})
invoice1.action_post()

# Invoice 2: Neto 21% (150) + IVA 21% (31.5) + Neto 10.5% (500) + IVA 10.5% (52.5) + Percep 3% (19.5) = 753.5 USD @ TC 1100
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

El comentario indica "# Invoice 2: ... @ TC 1100" pero no hay código que establezca o valide que la factura use la tasa de cambio de 1100. Aunque se crea una tasa de 1100 para hace 2 meses, la factura se crea con fecha de hoy (date.today()), por lo que usaría la tasa del día actual (1300). Esto genera confusión sobre el propósito del demo.

Copilot uses AI. Check for mistakes.
Comment on lines +225 to +269
# Calculate amounts: 991 USD at rate 1200 = 1,189,200 ARS
usd_currency = self.env.ref("base.USD")
counterpart_amount_usd = 991.0
exchange_rate = 1200.0
amount_ars = counterpart_amount_usd * exchange_rate
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

El comentario dice "Calculate amounts: 991 USD at rate 1200 = 1,189,200 ARS" pero el cálculo real en la línea 229 es correcto (991 * 1200 = 1,189,200). Sin embargo, no queda claro por qué se usa una tasa de 1200 en el código cuando las facturas usan la tasa del día (que sería 1300 según _create_exchange_rate_demo_data). Esto parece inconsistente con el propósito de generar diferencias de cambio.

Suggested change
# Calculate amounts: 991 USD at rate 1200 = 1,189,200 ARS
usd_currency = self.env.ref("base.USD")
counterpart_amount_usd = 991.0
exchange_rate = 1200.0
amount_ars = counterpart_amount_usd * exchange_rate
# Calculate amounts for 991 USD using the current exchange rate
usd_currency = self.env.ref("base.USD")
counterpart_amount_usd = 991.0
amount_ars = usd_currency._convert(
counterpart_amount_usd,
self.env.company.currency_id,
self.env.company,
date.today(),
)

Copilot uses AI. Check for mistakes.

payment.action_post()

_logger.info("Created demo payment: %s", payment.name)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Falta el return statement. El método debería retornar el pago creado para mantener consistencia con _create_exchange_difference_demo_invoices() que retorna las facturas, y para facilitar posibles extensiones o debugging.

Suggested change
_logger.info("Created demo payment: %s", payment.name)
_logger.info("Created demo payment: %s", payment.name)
return payment

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +105
partner = self.env.ref("base.res_partner_12", raise_if_not_found=False)
if not partner:
partner = self.env["res.partner"].search([("company_id", "=", self.env.company.id)], limit=1)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

El método _get_demo_partner() en la línea 77-84 duplica la lógica que ya existe en las líneas 98-100. Esta búsqueda de partner debería reutilizarse llamando al método _get_demo_partner() en lugar de duplicar el código.

Suggested change
partner = self.env.ref("base.res_partner_12", raise_if_not_found=False)
if not partner:
partner = self.env["res.partner"].search([("company_id", "=", self.env.company.id)], limit=1)
partner = self._get_demo_partner()

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +118
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "ilike", "Percepciones CABA"), ("company_id", "=", self.env.company.id)],
limit=1,
)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

El método _get_caba_fiscal_position() en la línea 86-91 duplica la lógica que ya existe en las líneas 103-106. Esta búsqueda de posición fiscal debería reutilizarse llamando al método _get_caba_fiscal_position() en lugar de duplicar el código.

Suggested change
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "ilike", "Percepciones CABA"), ("company_id", "=", self.env.company.id)],
limit=1,
)
fiscal_position = self._get_caba_fiscal_position()

Copilot uses AI. Check for mistakes.
company = self.env.company
exchange_rate_model = self.env["res.currency.rate"]
today = date.today()
rates = [1300, 1200, 1100, 1000] # today, 1 month ago, 2 months ago, 3 months ago
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Los números 1300, 1200, 1100, 1000 son valores mágicos sin explicación clara. Deberían definirse como constantes con nombres descriptivos al inicio del método o del archivo para mejorar la mantenibilidad y claridad del código.

Copilot uses AI. Check for mistakes.
Comment on lines 23 to 43
# self._create_exchange_product_demo_data()
self._create_exchange_rate_demo_data()
invoices = self._create_exchange_difference_demo_invoices()
self._create_exchange_difference_demo_payment(invoices)

# def _create_exchange_product_demo_data(self):
# """Create the exchange difference product used in the demo data."""
# product = self.env["product.product"].create(
# {
# "name": "Exchange Rate Difference",
# "type": "service",
# "sale_ok": False,
# "purchase_ok": False,
# "standard_price": 0.0,
# "list_price": 0.0,
# "default_code": "EXC-DIFF",
# "company_id": self.env.company.id,
# }
# )
# self.env.company.exchange_difference_product = product

Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

This comment appears to contain commented-out code.

Suggested change
# self._create_exchange_product_demo_data()
self._create_exchange_rate_demo_data()
invoices = self._create_exchange_difference_demo_invoices()
self._create_exchange_difference_demo_payment(invoices)
# def _create_exchange_product_demo_data(self):
# """Create the exchange difference product used in the demo data."""
# product = self.env["product.product"].create(
# {
# "name": "Exchange Rate Difference",
# "type": "service",
# "sale_ok": False,
# "purchase_ok": False,
# "standard_price": 0.0,
# "list_price": 0.0,
# "default_code": "EXC-DIFF",
# "company_id": self.env.company.id,
# }
# )
# self.env.company.exchange_difference_product = product
self._create_exchange_rate_demo_data()
invoices = self._create_exchange_difference_demo_invoices()
self._create_exchange_difference_demo_payment(invoices)

Copilot uses AI. Check for mistakes.
@cav-adhoc cav-adhoc force-pushed the 18.0-t-61301-cav branch 2 times, most recently from a63b65f to 9601a75 Compare December 23, 2025 13:56
@cav-adhoc cav-adhoc changed the title [WIP] account_exchange_difference_invoice: Add demo data for exchange… [WIP] account_exchange_difference_invoice: Add demo data Dec 23, 2025
@cav-adhoc cav-adhoc force-pushed the 18.0-t-61301-cav branch 10 times, most recently from 627e559 to 0727ebe Compare December 26, 2025 17:43
This commit creates demo data for testing exchange rate differences in Odoo invoices for Argentinian companies. It:

1. Sets up exchange rates: Creates USD/ARS rates for today and past 3 months (1300, 1200, 1100, 1000)

2. Creates 3 customer invoices in USD with different amounts and tax combinations:
- Invoice 1: 237.5 USD @ rate 1000
- Invoice 2: 753.5 USD @ rate 1100
- Invoice 3: 121 USD @ rate 1000 (different partner)

3. Creates payments at different exchange rates to generate exchange differences:
- Payment 1: 991 USD @ rate 1200 (for invoices 1 & 2)
- Payment 2: 121 USD @ rate 1100 (for invoice 3)
@cav-adhoc cav-adhoc changed the title [WIP] account_exchange_difference_invoice: Add demo data [IMP] account_exchange_difference_invoice: Add demo data Dec 30, 2025
@cav-adhoc
Copy link
Contributor Author

Sigue en #860

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.

2 participants