-
Notifications
You must be signed in to change notification settings - Fork 154
[ADD] l10n_ar_payment_bundle: add Argentina demo data #1034
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
base: 19.0
Are you sure you want to change the base?
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,5 +1,6 @@ | ||
| from . import models | ||
| from . import wizard | ||
| from . import demo | ||
|
|
||
|
|
||
| def post_init_hook(env): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import l10n_ar_payment_bundle_demo |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,339 @@ | ||||||
| import logging | ||||||
|
|
||||||
| from odoo import Command, api, fields, models | ||||||
|
|
||||||
| _logger = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| class AccountChartTemplate(models.AbstractModel): | ||||||
| _inherit = "account.chart.template" | ||||||
|
|
||||||
| @api.model | ||||||
| def _install_l10n_ar_payment_bundle_demo(self, companies): | ||||||
| """Crea data demo para argentina""" | ||||||
|
|
||||||
| for company in companies.filtered(lambda x: x.country_code == "AR"): | ||||||
| self = self.with_company(company) | ||||||
| today = fields.Date.today() | ||||||
|
|
||||||
| # Tipo de write-off: cuenta "Rounding adjustment" (base_ajuste_por_redondeo) | ||||||
| write_off_account = self.env.ref(f"account.{company.id}_base_ajuste_por_redondeo", raise_if_not_found=False) | ||||||
| if not write_off_account: | ||||||
| continue | ||||||
|
|
||||||
| write_off_type = self.env["account.write_off.type"].search( | ||||||
| [("account_id", "=", write_off_account.id), ("name", "=", "Diferencia de cambio / ajuste")], | ||||||
| limit=1, | ||||||
| ) | ||||||
| if not write_off_type: | ||||||
| write_off_type = self.env["account.write_off.type"].create( | ||||||
| { | ||||||
| "name": "Diferencia de cambio / ajuste", | ||||||
| "account_id": write_off_account.id, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Factura de proveedor en ARS para cancelar con bundle + write-off | ||||||
| doc_type = self.env.ref("l10n_ar.dc_c_f") # Factura C | ||||||
| partner_adhoc = self.env.ref("l10n_ar.res_partner_adhoc") | ||||||
| invoice = self.env["account.move"].search( | ||||||
| [ | ||||||
| ("move_type", "=", "in_invoice"), | ||||||
| ("company_id", "=", company.id), | ||||||
| ("name", "like", "00001-00000099"), | ||||||
| ("partner_id", "=", partner_adhoc.id), | ||||||
| ], | ||||||
| limit=1, | ||||||
| ) | ||||||
| if not invoice: | ||||||
| invoice = ( | ||||||
| self.env["account.move"] | ||||||
| .with_context(skip_pdf_attachment_generation=True, skip_readonly_check=True) | ||||||
| .create( | ||||||
| { | ||||||
| "move_type": "in_invoice", | ||||||
| "partner_id": partner_adhoc.id, | ||||||
| "currency_id": self.env.ref("base.ARS").id, | ||||||
| "invoice_date": today, | ||||||
| "l10n_latam_document_type_id": doc_type.id, | ||||||
| "l10n_latam_document_number": "0001-00000099", | ||||||
| "invoice_line_ids": [ | ||||||
| Command.create( | ||||||
| { | ||||||
| "product_id": self.env.ref("product.product_product_2").id, | ||||||
| "quantity": 1, | ||||||
| "price_unit": 10000, | ||||||
| "tax_ids": [ | ||||||
| Command.set( | ||||||
| [ | ||||||
| self.env.ref( | ||||||
| f"account.{company.id}_ri_tax_vat_no_corresponde_ventas" | ||||||
| ).id | ||||||
| ] | ||||||
| ) | ||||||
| ], | ||||||
| } | ||||||
| ) | ||||||
| ], | ||||||
| "company_id": company.id, | ||||||
| } | ||||||
| ) | ||||||
| ) | ||||||
| if invoice.state == "draft": | ||||||
| invoice.action_post() | ||||||
|
|
||||||
| # Asegurar que el journal bundle existe (puede no haberse creado si use_payment_pro | ||||||
| # se activó después de la instalación del chart template) | ||||||
| company._create_payment_bundle_journal_if_needed() | ||||||
|
|
||||||
| # Bundle journal y payment method line (misma lógica que los tests) | ||||||
| bundle_journal = self.env["account.journal"].search( | ||||||
| [ | ||||||
| ("outbound_payment_method_line_ids.payment_method_id.code", "=", "payment_bundle"), | ||||||
| ("company_id", "=", company.id), | ||||||
| ], | ||||||
| limit=1, | ||||||
| ) | ||||||
| bundle_pml = bundle_journal.outbound_payment_method_line_ids.filtered( | ||||||
| lambda l: l.payment_method_id.code == "payment_bundle" | ||||||
| ) | ||||||
| bank_journal = self.env["account.journal"].search( | ||||||
| [("type", "=", "bank"), ("company_id", "=", company.id)], limit=1 | ||||||
| ) | ||||||
|
|
||||||
| if not bundle_pml or not bank_journal: | ||||||
| _logger.warning( | ||||||
| "l10n_ar_payment_bundle demo: bundle_journal=%s bundle_pml=%s bank_journal=%s — skipping company %s", | ||||||
| bundle_journal, | ||||||
| bundle_pml, | ||||||
| bank_journal, | ||||||
| company.name, | ||||||
| ) | ||||||
| continue | ||||||
|
|
||||||
| # Línea de deuda del proveedor (solo si tiene saldo pendiente) | ||||||
| invoice.flush_recordset() | ||||||
| debt_line = invoice.line_ids.filtered( | ||||||
| lambda l: l.account_id.account_type == "liability_payable" and l.amount_residual != 0 | ||||||
| ) | ||||||
| if not debt_line: | ||||||
| continue | ||||||
|
|
||||||
| # Pago principal del bundle (amount=0, concentra deuda y write-off) | ||||||
| main_payment = self.env["account.payment"].create( | ||||||
| { | ||||||
| "payment_type": "outbound", | ||||||
| "partner_type": "supplier", | ||||||
| "partner_id": partner_adhoc.id, | ||||||
|
Comment on lines
+123
to
+127
|
||||||
| "amount": 0, | ||||||
| "journal_id": bundle_journal.id, | ||||||
| "payment_method_line_id": bundle_pml.id, | ||||||
| "date": today, | ||||||
| "to_pay_move_line_ids": [Command.set(debt_line.ids)], | ||||||
| "write_off_amount": 100, | ||||||
| "write_off_type_id": write_off_type.id, | ||||||
| "company_id": company.id, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Pago vinculado: tranferencia bancaria cubre el resto (deuda - write-off) | ||||||
|
||||||
| # Pago vinculado: tranferencia bancaria cubre el resto (deuda - write-off) | |
| # Pago vinculado: transferencia bancaria cubre el resto (deuda - write-off) |
Copilot
AI
Apr 27, 2026
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.
Mismo problema de idempotencia: se busca name like '00001-00000100' pero se crea con l10n_latam_document_number='0001-00000100'. Esto impide reutilizar la factura existente y puede duplicar datos demo. Sugerencia: alinear el criterio de búsqueda con el campo l10n_latam_document_number/tipo de documento.
Copilot
AI
Apr 27, 2026
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.
La búsqueda de la factura de cliente usa name like '00002-00000001', pero al crearla se setea l10n_latam_document_number='0002-00000001'. Con ese desfase, en re-ejecuciones del instalador no va a encontrar la existente y puede duplicar la factura demo. Sugerencia: buscar por l10n_latam_document_number (y mantener el mismo formato de número).
| 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_l10n_ar_payment_bundle_demo"> | ||||||||||||||
| <value model="res.company" eval="obj().env.ref('base.company_ri')"/> | ||||||||||||||
|
Comment on lines
+2
to
+4
|
||||||||||||||
| <odoo> | |
| <function model="account.chart.template" name="_install_l10n_ar_payment_bundle_demo"> | |
| <value model="res.company" eval="obj().env.ref('base.company_ri')"/> | |
| <odoo noupdate="1"> | |
| <function model="account.chart.template" name="_install_l10n_ar_payment_bundle_demo"> | |
| <value model="res.company" eval="[obj().env.ref('base.company_ri')]"/> |
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.
La búsqueda de la factura usa
name like '00001-00000099', pero al crearla se seteal10n_latam_document_number='0001-00000099'(4 dígitos). Así la búsqueda no va a matchear y el instalador puede duplicar la factura. Sugerencia: buscar porl10n_latam_document_number(y/ol10n_latam_document_type_id) usando exactamente el mismo número que se crea, en lugar denamecon un patrón distinto.