diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/l10n_mx/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/l10n_mx/models')
| -rw-r--r-- | addons/l10n_mx/models/__init__.py | 9 | ||||
| -rw-r--r-- | addons/l10n_mx/models/account.py | 57 | ||||
| -rw-r--r-- | addons/l10n_mx/models/account_tax.py | 38 | ||||
| -rw-r--r-- | addons/l10n_mx/models/chart_template.py | 49 | ||||
| -rw-r--r-- | addons/l10n_mx/models/res_bank.py | 21 | ||||
| -rw-r--r-- | addons/l10n_mx/models/res_config_settings.py | 9 |
6 files changed, 183 insertions, 0 deletions
diff --git a/addons/l10n_mx/models/__init__.py b/addons/l10n_mx/models/__init__.py new file mode 100644 index 00000000..81b9491a --- /dev/null +++ b/addons/l10n_mx/models/__init__.py @@ -0,0 +1,9 @@ +# coding: utf-8 +# Copyright 2016 Vauxoo (https://www.vauxoo.com) <info@vauxoo.com> +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import account +from . import account_tax +from . import res_bank +from . import res_config_settings +from . import chart_template diff --git a/addons/l10n_mx/models/account.py b/addons/l10n_mx/models/account.py new file mode 100644 index 00000000..7c038c12 --- /dev/null +++ b/addons/l10n_mx/models/account.py @@ -0,0 +1,57 @@ +# coding: utf-8 +# Copyright 2016 Vauxoo (https://www.vauxoo.com) <info@vauxoo.com> +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +import re +from odoo import models, api, fields, _ + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + def _prepare_liquidity_account_vals(self, company, code, vals): + # OVERRIDE + account_vals = super()._prepare_liquidity_account_vals(company, code, vals) + + if company.country_id.code == 'MX': + # When preparing the values to use when creating the default debit and credit accounts of a + # liquidity journal, set the correct tags for the mexican localization. + account_vals.setdefault('tag_ids', []) + account_vals['tag_ids'] += [(4, tag_id) for tag_id in self.env['account.account'].mx_search_tags(code).ids] + + return account_vals + + +class AccountAccount(models.Model): + _inherit = 'account.account' + + @api.model + def mx_search_tags(self, code): + account_tag = self.env['account.account.tag'] + #search if the code is compliant with the regexp we have for tags auto-assignation + re_res = re.search( + '^(?P<first>[1-8][0-9][0-9])[,.]' + '(?P<second>[0-9][0-9])[,.]' + '(?P<third>[0-9]{2,3})$', code) + if not re_res: + return account_tag + + #get the elements of that code divided with separation declared in the regexp + account = re_res.groups() + return account_tag.search([ + ('name', '=like', "%s.%s%%" % (account[0], account[1])), + ('color', '=', 4)], limit=1) + + @api.onchange('code') + def _onchange_code(self): + if self.company_id.country_id.code == "MX" and self.code: + tags = self.mx_search_tags(self.code) + self.tag_ids = tags + + +class AccountAccountTag(models.Model): + _inherit = 'account.account.tag' + + nature = fields.Selection([ + ('D', 'Debitable Account'), ('A', 'Creditable Account')], + help='Used in Mexican report of electronic accounting (account nature).') diff --git a/addons/l10n_mx/models/account_tax.py b/addons/l10n_mx/models/account_tax.py new file mode 100644 index 00000000..a435a9ea --- /dev/null +++ b/addons/l10n_mx/models/account_tax.py @@ -0,0 +1,38 @@ +# coding: utf-8 +from odoo import models, fields + + +class AccountTaxTemplate(models.Model): + _inherit = 'account.tax.template' + + l10n_mx_tax_type = fields.Selection( + selection=[ + ('Tasa', "Tasa"), + ('Cuota', "Cuota"), + ('Exento', "Exento"), + ], + string="Factor Type", + default='Tasa', + help="The CFDI version 3.3 have the attribute 'TipoFactor' in the tax lines. In it is indicated the factor " + "type that is applied to the base of the tax.") + + def _get_tax_vals(self, company, tax_template_to_tax): + # OVERRIDE + res = super()._get_tax_vals(company, tax_template_to_tax) + res['l10n_mx_tax_type'] = self.l10n_mx_tax_type + return res + + +class AccountTax(models.Model): + _inherit = 'account.tax' + + l10n_mx_tax_type = fields.Selection( + selection=[ + ('Tasa', "Tasa"), + ('Cuota', "Cuota"), + ('Exento', "Exento"), + ], + string="Factor Type", + default='Tasa', + help="The CFDI version 3.3 have the attribute 'TipoFactor' in the tax lines. In it is indicated the factor " + "type that is applied to the base of the tax.") diff --git a/addons/l10n_mx/models/chart_template.py b/addons/l10n_mx/models/chart_template.py new file mode 100644 index 00000000..d267febb --- /dev/null +++ b/addons/l10n_mx/models/chart_template.py @@ -0,0 +1,49 @@ +# coding: utf-8 +# Copyright 2016 Vauxoo (https://www.vauxoo.com) <info@vauxoo.com> +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models, api, _ + + +class AccountChartTemplate(models.Model): + _inherit = "account.chart.template" + + @api.model + def generate_journals(self, acc_template_ref, company, journals_dict=None): + """Set the tax_cash_basis_journal_id on the company""" + res = super(AccountChartTemplate, self).generate_journals( + acc_template_ref, company, journals_dict=journals_dict) + if not self == self.env.ref('l10n_mx.mx_coa'): + return res + journal_basis = self.env['account.journal'].search([ + ('company_id', '=', company.id), + ('type', '=', 'general'), + ('code', '=', 'CBMX')], limit=1) + company.write({'tax_cash_basis_journal_id': journal_basis.id}) + return res + + def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None): + """Create the tax_cash_basis_journal_id""" + res = super(AccountChartTemplate, self)._prepare_all_journals( + acc_template_ref, company, journals_dict=journals_dict) + if not self == self.env.ref('l10n_mx.mx_coa'): + return res + account = acc_template_ref.get(self.env.ref('l10n_mx.cuenta118_01').id) + res.append({ + 'type': 'general', + 'name': _('Effectively Paid'), + 'code': 'CBMX', + 'company_id': company.id, + 'default_account_id': account, + 'show_on_dashboard': True, + }) + return res + + @api.model + def _prepare_transfer_account_for_direct_creation(self, name, company): + res = super(AccountChartTemplate, self)._prepare_transfer_account_for_direct_creation(name, company) + if company.country_id.code == 'MX': + xml_id = self.env.ref('l10n_mx.account_tag_102_01').id + res.setdefault('tag_ids', []) + res['tag_ids'].append((4, xml_id)) + return res diff --git a/addons/l10n_mx/models/res_bank.py b/addons/l10n_mx/models/res_bank.py new file mode 100644 index 00000000..ee751c7f --- /dev/null +++ b/addons/l10n_mx/models/res_bank.py @@ -0,0 +1,21 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Bank(models.Model): + _inherit = "res.bank" + + l10n_mx_edi_code = fields.Char( + "ABM Code", + help="Three-digit number assigned by the ABM to identify banking " + "institutions (ABM is an acronym for Asociación de Bancos de México)") + + +class ResPartnerBank(models.Model): + _inherit = "res.partner.bank" + + l10n_mx_edi_clabe = fields.Char( + "CLABE", help="Standardized banking cipher for Mexico. More info " + "wikipedia.org/wiki/CLABE") diff --git a/addons/l10n_mx/models/res_config_settings.py b/addons/l10n_mx/models/res_config_settings.py new file mode 100644 index 00000000..a0776b70 --- /dev/null +++ b/addons/l10n_mx/models/res_config_settings.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + module_l10n_mx_edi = fields.Boolean('Mexican Electronic Invoicing') |
