[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) <las@odoo.com>
This commit is contained in:
committed by
Claire Bretton (clbr)
parent
6bfd133dbb
commit
188175adb8
@@ -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': """
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
@@ -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)]
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user