From 188175adb8be44e87b9ee85c3d73fa39858a56d5 Mon Sep 17 00:00:00 2001 From: smdc-odoo Date: Mon, 24 Apr 2023 11:21:31 +0000 Subject: [PATCH] [FIX] l10n_mx: Fix account tags for COA SAT(XML) export Steps to reproduce: 1. Install l10n_mx 2. Go to Accounting > Reporting > Trial balance. 3. Click the COA SAT(XML) export button. 4. Warnings are raised. Problem: the report should work out-of-the-box on new databases. Cause: 1. Some tags are missing on auto-generated accounts. 2. Some data were not correct and had the wrong tag. 102 accounts in particular should be debit and not credit. This PR migrate the incorrect data and add a default naive computation of the tag on newly created accounts. opw-3283746 closes odoo/odoo#155762 Enterprise: https://github.com/odoo/enterprise/pull/57531 X-original-commit: c7b971d5540f86f987fdaeada9481d6f46d41c49 Related: odoo/enterprise#57732 Signed-off-by: Laurent Smet (las) --- addons/l10n_mx/__manifest__.py | 2 +- .../data/template/account.account-mx.csv | 2 +- addons/l10n_mx/migrations/2.1/post-migrate.py | 15 +++++++++++++++ addons/l10n_mx/models/__init__.py | 2 +- addons/l10n_mx/models/account_account.py | 18 ++++++++++++++++++ addons/l10n_mx/models/account_journal.py | 16 ---------------- addons/l10n_mx/models/template_mx.py | 4 ---- 7 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 addons/l10n_mx/migrations/2.1/post-migrate.py create mode 100644 addons/l10n_mx/models/account_account.py delete mode 100644 addons/l10n_mx/models/account_journal.py diff --git a/addons/l10n_mx/__manifest__.py b/addons/l10n_mx/__manifest__.py index 1c833c36d92..c0634bbaee5 100644 --- a/addons/l10n_mx/__manifest__.py +++ b/addons/l10n_mx/__manifest__.py @@ -4,7 +4,7 @@ 'website': 'https://www.odoo.com/documentation/17.0/applications/finance/fiscal_localizations/mexico.html', 'icon': '/account/static/description/l10n.png', 'countries': ['mx'], - 'version': '2.0', + 'version': '2.1', 'author': 'Vauxoo', 'category': 'Accounting/Localizations/Account Charts', 'description': """ diff --git a/addons/l10n_mx/data/template/account.account-mx.csv b/addons/l10n_mx/data/template/account.account-mx.csv index 4f0e010ff5e..9f14b38c318 100644 --- a/addons/l10n_mx/data/template/account.account-mx.csv +++ b/addons/l10n_mx/data/template/account.account-mx.csv @@ -1,5 +1,5 @@ "id","name","code","account_type","reconcile","tag_ids","name@es" -"cuenta102_02","Foreign currency bank transfers","102.02.01","asset_current","True","l10n_mx.tag_credit_balance_account","Transferencias bancarias moneda extranjera" +"cuenta102_02","Foreign currency bank transfers","102.02.01","asset_current","True","l10n_mx.tag_debit_balance_account","Transferencias bancarias moneda extranjera" "cuenta105_01","Domestic customers","105.01.01","asset_receivable","True","l10n_mx.tag_debit_balance_account","Clientes nacionales" "cuenta105_02","National customers (PoS)","105.01.02","asset_receivable","True","l10n_mx.tag_debit_balance_account","Clientes nacionales (PoS)" "cuenta107_05_01","Goods Shipped - No Invoices","107.05.01","asset_current","True","l10n_mx.tag_debit_balance_account","MercancĂ­as Enviadas - No Facturas" diff --git a/addons/l10n_mx/migrations/2.1/post-migrate.py b/addons/l10n_mx/migrations/2.1/post-migrate.py new file mode 100644 index 00000000000..a31713642c1 --- /dev/null +++ b/addons/l10n_mx/migrations/2.1/post-migrate.py @@ -0,0 +1,15 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import api, Command, SUPERUSER_ID + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + # Migrate wrong data tag on account cuenta102_02 + debit_tag = env.ref('l10n_mx.tag_debit_balance_account') + credit_tag = env.ref('l10n_mx.tag_credit_balance_account') + account_102_ids = env['ir.model.data'].search([ + ('name', 'ilike', '%_cuenta102_02'), + ('model', '=', 'account.account'), + ]).mapped('res_id') + accounts_102 = env['account.account'].browse(account_102_ids) + accounts_102.tag_ids = [Command.unlink(credit_tag.id), Command.link(debit_tag.id)] diff --git a/addons/l10n_mx/models/__init__.py b/addons/l10n_mx/models/__init__.py index f98f00df9ca..c520efc1e42 100644 --- a/addons/l10n_mx/models/__init__.py +++ b/addons/l10n_mx/models/__init__.py @@ -1,6 +1,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import template_mx +from . import account_account from . import account_tax -from . import account_journal from . import res_bank from . import res_config_settings diff --git a/addons/l10n_mx/models/account_account.py b/addons/l10n_mx/models/account_account.py new file mode 100644 index 00000000000..e1d824383c3 --- /dev/null +++ b/addons/l10n_mx/models/account_account.py @@ -0,0 +1,18 @@ +from odoo import Command, models + + +class AccountAccount(models.Model): + _inherit = 'account.account' + + def create(self, vals_list): + # EXTENDS account - ensure there is a tag on created MX accounts + # The computation is a bit naive and might not be correct in all cases. + accounts = super().create(vals_list) + debit_tag = self.env.ref('l10n_mx.tag_debit_balance_account') + credit_tag = self.env.ref('l10n_mx.tag_credit_balance_account') + mx_account_no_tags = accounts.filtered(lambda a: a.company_id.country_code == 'MX' and not a.tag_ids & (credit_tag + debit_tag)) + DEBIT_CODES = ['1', '5', '6', '7'] # all other codes are considered "credit" + for account in mx_account_no_tags: + tag_id = debit_tag.id if account.code[0] in DEBIT_CODES else credit_tag.id + account.tag_ids = [Command.link(tag_id)] + return accounts diff --git a/addons/l10n_mx/models/account_journal.py b/addons/l10n_mx/models/account_journal.py deleted file mode 100644 index c415e2e9699..00000000000 --- a/addons/l10n_mx/models/account_journal.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- - -from odoo import models, api, Command - - -class AccountJournal(models.Model): - _inherit = "account.journal" - - @api.model - def _prepare_liquidity_account_vals(self, company, code, vals): - account_vals = super()._prepare_liquidity_account_vals(company, code, vals) - if company.account_fiscal_country_id.code != 'MX': - return account_vals - # Ensure Cash account has the correct tags in order to export the COA - account_vals.setdefault('tag_ids', []).append(Command.link(self.env.ref('l10n_mx.tag_credit_balance_account').id)) - return account_vals diff --git a/addons/l10n_mx/models/template_mx.py b/addons/l10n_mx/models/template_mx.py index 49c33e5de7e..1cc0ad8f4e4 100644 --- a/addons/l10n_mx/models/template_mx.py +++ b/addons/l10n_mx/models/template_mx.py @@ -52,7 +52,3 @@ class AccountChartTemplate(models.AbstractModel): 'show_on_dashboard': True, } } - - def _setup_utility_bank_accounts(self, template_code, company, template_data): - super()._setup_utility_bank_accounts(template_code, company, template_data) - company.account_journal_suspense_account_id.tag_ids = self.env.ref('l10n_mx.tag_credit_balance_account')