diff options
| author | Nhomar Hernandez <nhomar@vauxoo.com> | 2016-12-09 13:46:23 +0100 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2016-12-09 13:59:09 +0100 |
| commit | 9a0e3a11dbb30a86fc5e5f2b9b7a6876f1744ca1 (patch) | |
| tree | f8e05734c58141a9dfb48d9d0611929a94fe26d2 /addons/l10n_mx/models | |
| parent | d6ead3dbe0a4a4e8dd8793439b297103ae1c6838 (diff) | |
[IMP] l10n_mx: Completely refactored Mexican CoA Template. Courtesy of Vauxoo.
* Added accounts provided following the structure provided by the SAT
this accounts are only the minimal necessary ones, with the objective
to set the first easiest engagement to new users and tags will represent the actual information
from the document linked.
* The name of the tag is the concatenation of tag.code + tag.name, because the account.tag
model have not the code field.
Note: we will need more accounts but some of them for special operations
which are not basic at all, then it is better just propose the operational accounts
once we understand a proper closing process.
* Set the proper user-types on accounts in order to be able to use it with the official reports this CoA
for operational purpose.
* Added nature field and data in tags to allow set this value in electronic account report, and
set this value with data pre loaded, we did not use user.type for this due to the fact that the same user type can have different nature (if it grows for credit or debit), I do not know if this field brakes the stable rule we can discuse about that.
* Assign the account tags with in the Mexican CoA template installation, and with an onchange(account.code) when manually modifying/creating accounts.
Rationale: If the code of the accounts follows the pattern 111.00.00 or 111-00-00 then it will
set the tag 111.00 if the tag exists, if not then this will be ignored.
* Generate an account tag by each second level account in SAT catalog, and assign to the corresponding account.
Diffstat (limited to 'addons/l10n_mx/models')
| -rw-r--r-- | addons/l10n_mx/models/__init__.py | 6 | ||||
| -rw-r--r-- | addons/l10n_mx/models/account.py | 59 | ||||
| -rw-r--r-- | addons/l10n_mx/models/chart_template.py | 81 |
3 files changed, 146 insertions, 0 deletions
diff --git a/addons/l10n_mx/models/__init__.py b/addons/l10n_mx/models/__init__.py new file mode 100644 index 00000000000..5376a315b04 --- /dev/null +++ b/addons/l10n_mx/models/__init__.py @@ -0,0 +1,6 @@ +# 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 chart_template +from . import account diff --git a/addons/l10n_mx/models/account.py b/addons/l10n_mx/models/account.py new file mode 100644 index 00000000000..b1c691c85f6 --- /dev/null +++ b/addons/l10n_mx/models/account.py @@ -0,0 +1,59 @@ +# 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' + + @api.model + def _prepare_liquidity_account(self, name, company, currency_id, type): + ''' + 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. + ''' + res = super(AccountJournal, self)._prepare_liquidity_account(name, company, currency_id, type) + if company.country_id.id == self.env.ref('base.mx').id: + mx_tags = self.env['account.account'].mx_search_tags(res.get('code', '')) + if mx_tags: + res.update({ + 'tag_ids': [(6, 0, [tag.id for tag in mx_tags])] + }) + return res + +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.id == self.env.ref('base.mx').id 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/chart_template.py b/addons/l10n_mx/models/chart_template.py new file mode 100644 index 00000000000..c4dec8e3f7e --- /dev/null +++ b/addons/l10n_mx/models/chart_template.py @@ -0,0 +1,81 @@ +# 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.multi + def _load_template( + self, company, code_digits=None, transfer_account_id=None, + account_ref=None, taxes_ref=None): + """ + Set the 'use_cash_basis' and 'cash_basis_account' fields on account.account. This hack is needed due to the fact + that the tax template does not have the fields 'use_cash_basis' and 'cash_basis_account'. + + This hunk should be removed in master, as the account_tax_cash_basis module has been merged already in account + module + """ + self.ensure_one() + accounts, taxes = super(AccountChartTemplate, self)._load_template( + company, code_digits=code_digits, + transfer_account_id=transfer_account_id, account_ref=account_ref, + taxes_ref=taxes_ref) + if not self == self.env.ref('l10n_mx.mx_coa'): + return accounts, taxes + account_tax_obj = self.env['account.tax'] + account_obj = self.env['account.account'] + taxes_acc = { + 'ITAX_010-IN': account_obj.search([('code', '=', '208.01.01')]), + 'ITAX_160-IN': account_obj.search([('code', '=', '208.01.01')]), + 'ITAXR_04-OUT': account_obj.search([('code', '=', '216.13.01')]), + 'ITAXR_10-OUT': account_obj.search([('code', '=', '216.13.01')]), + 'ITAX_1067-OUT': account_obj.search([('code', '=', '216.13.01')]), + 'ITAX_167-OUT': account_obj.search([('code', '=', '216.13.01')]), + 'ITAX_010-OUT': account_obj.search([('code', '=', '208.01.01')]), + 'ITAX_160-OUT': account_obj.search([('code', '=', '208.01.01')])} + + for tax in self.tax_template_ids: + if tax.description not in taxes_acc: + continue + account_tax_obj.browse(taxes.get(tax.id)).write({ + 'use_cash_basis': True, + 'cash_basis_account': taxes_acc.get(tax.description).id, + }) + return accounts, taxes + + @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([ + ('type', '=', 'general'), + ('code', '=', 'CBMX')], limit=1) + company.write({'tax_cash_basis_journal_id': journal_basis.id}) + return res + + @api.multi + 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 + res.append({ + 'type': 'general', + 'name': _('Effectively Paid'), + 'code': 'CBMX', + 'company_id': company.id, + 'default_credit_account_id': acc_template_ref.get( + self.income_currency_exchange_account_id.id), + 'default_debit_account_id': acc_template_ref.get( + self.expense_currency_exchange_account_id.id), + 'show_on_dashboard': True, + }) + return res |
