-
Notifications
You must be signed in to change notification settings - Fork 132
[IMP] account_exchange_difference_invoice: Add demo data #854
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
Conversation
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.
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.xmlanterior 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 |
| # Set exchange rate to 1000 before posting | ||
| if currency_usd: | ||
| invoice1.write({"currency_id": currency_usd.id}) |
Copilot
AI
Dec 22, 2025
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.
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.
| # Set exchange rate to 1000 before posting | |
| if currency_usd: | |
| invoice1.write({"currency_id": currency_usd.id}) |
| if currency_usd: | ||
| invoice2.write({"currency_id": currency_usd.id}) |
Copilot
AI
Dec 22, 2025
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.
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.
| if currency_usd: | |
| invoice2.write({"currency_id": currency_usd.id}) |
| 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 |
Copilot
AI
Dec 22, 2025
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.
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.
| # 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 |
| 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 |
Copilot
AI
Dec 22, 2025
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.
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.
| # 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 |
Copilot
AI
Dec 22, 2025
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.
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.
| # 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(), | |
| ) |
|
|
||
| payment.action_post() | ||
|
|
||
| _logger.info("Created demo payment: %s", payment.name) |
Copilot
AI
Dec 22, 2025
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.
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.
| _logger.info("Created demo payment: %s", payment.name) | |
| _logger.info("Created demo payment: %s", payment.name) | |
| return payment |
| 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) |
Copilot
AI
Dec 22, 2025
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.
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.
| 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() |
| fiscal_position = self.env["account.fiscal.position"].search( | ||
| [("name", "ilike", "Percepciones CABA"), ("company_id", "=", self.env.company.id)], | ||
| limit=1, | ||
| ) |
Copilot
AI
Dec 22, 2025
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.
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.
| 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() |
| 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 |
Copilot
AI
Dec 22, 2025
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.
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.
| # 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 | ||
|
|
Copilot
AI
Dec 22, 2025
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.
This comment appears to contain commented-out code.
| # 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) |
a63b65f to
9601a75
Compare
627e559 to
0727ebe
Compare
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)
0727ebe to
51adc7f
Compare
|
Sigue en #860 |

This commit creates demo data for testing exchange rate differences in Odoo invoices for Argentinian companies. It:
Sets up exchange rates: Creates USD/ARS rates for today and past 3 months (1300, 1200, 1100, 1000)
Creates 3 customer invoices in USD with different amounts and tax combinations: