-
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
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| from . import models | ||
| from . import wizards | ||
| from . import demo |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import account_exchange_demo |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,315 @@ | ||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||
| from datetime import date | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from dateutil.relativedelta import relativedelta | ||||||||||||||||||||||||||||||
| from odoo import api, models | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _logger = logging.getLogger(__name__) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class AccountChartTemplate(models.AbstractModel): | ||||||||||||||||||||||||||||||
| _inherit = "account.chart.template" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @api.model | ||||||||||||||||||||||||||||||
| def _install_exchange_diff_demo(self, companies): | ||||||||||||||||||||||||||||||
| # Just ARG companies for now | ||||||||||||||||||||||||||||||
| if not companies: | ||||||||||||||||||||||||||||||
| _logger.info("No companies provided for exchange demo data creation, skipping.") | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _logger.info("Creating exchange demo data for companies: %s", companies.mapped("name")) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| for company in companies.filtered(lambda x: x.country_code == "AR"): | ||||||||||||||||||||||||||||||
| self = self.with_company(company) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Skip if demo data already exists to avoid duplicates on reinstall | ||||||||||||||||||||||||||||||
| # Check for a specific XML ID created by this module's demo data | ||||||||||||||||||||||||||||||
| demo_marker = self.env.ref( | ||||||||||||||||||||||||||||||
| "account_exchange_difference_invoice.demo_exchange_diff_installed_%s" % company.id, | ||||||||||||||||||||||||||||||
| raise_if_not_found=False, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| if demo_marker: | ||||||||||||||||||||||||||||||
| _logger.info("Demo data already exists for company %s, skipping creation", company.name) | ||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self._create_exchange_rate_demo_data() | ||||||||||||||||||||||||||||||
| invoices = self._create_exchange_difference_demo_invoices() | ||||||||||||||||||||||||||||||
| self._create_exchange_difference_demo_payment(invoices) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Create marker to indicate demo data has been installed for this company | ||||||||||||||||||||||||||||||
| self.env["ir.model.data"].create( | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "name": "demo_exchange_diff_installed_%s" % company.id, | ||||||||||||||||||||||||||||||
| "module": "account_exchange_difference_invoice", | ||||||||||||||||||||||||||||||
| "model": "res.company", | ||||||||||||||||||||||||||||||
| "res_id": company.id, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def _create_exchange_rate_demo_data(self): | ||||||||||||||||||||||||||||||
| """Create some USD exchange rates for demo purposes for today and the past 3 months.""" | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| """Create some USD exchange rates for demo purposes for today and the past 3 months.""" | |
| """Create USD exchange rates for demo purposes for today and 1, 2, and 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.
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() |
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() |
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 |
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}) |
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.
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}) |
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 valores 991.0 y 1200.0 son números mágicos sin contexto. Deberían definirse como constantes con nombres descriptivos que expliquen por qué se usan esos valores específicos para el demo.
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(), | |
| ) |
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.
Si no se encuentra un journal de tipo 'bank', el método fallará con un error al intentar acceder a bank_journal.id cuando bank_journal es un recordset vacío. Se debería validar que se encontró un journal y, en caso contrario, registrar un warning o crear/usar un journal por defecto.
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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <function model="account.chart.template" name="_install_exchange_diff_demo"> | ||
| <value model="res.company" eval="obj().search([('chart_template', '=', 'ar_ri')])"/> | ||
| </function> | ||
| </odoo> |
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 archivo demo está siendo agregado en la sección 'data' en lugar de en la sección 'demo'. Los archivos de datos de demostración deben estar en la sección 'demo' del manifest para que solo se carguen cuando se instale el módulo con demo data habilitada.