Skip to content
Snippets Groups Projects
Commit f4ca2350 authored by Raúl's avatar Raúl
Browse files

[REF] l10n_ec: Message validation for VAT


- We refactored the VAT validation from a validation error to a warning that is stored in l10n_ec_vat_error
- Remove the "-" and "EC" from the base_vat in the EC validation/example
- Only validate the length in the base_vat
- Add compute field with the warning message in the l10n_ec

closes odoo/odoo#121099

Signed-off-by: default avatarJosse Colpaert <jco@odoo.com>
parent 65f6d123
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ _ref_vat = { ...@@ -39,7 +39,7 @@ _ref_vat = {
'de': 'DE123456788', 'de': 'DE123456788',
'dk': 'DK12345674', 'dk': 'DK12345674',
'do': 'DO1-01-85004-3 or 101850043', 'do': 'DO1-01-85004-3 or 101850043',
'ec': 'EC1792060346-001', 'ec': '1792060346001 or 1792060346',
'ee': 'EE123456780', 'ee': 'EE123456780',
'el': 'EL12345670', 'el': 'EL12345670',
'es': 'ESA12345674', 'es': 'ESA12345674',
...@@ -328,15 +328,8 @@ class ResPartner(models.Model): ...@@ -328,15 +328,8 @@ class ResPartner(models.Model):
def is_valid_ruc_ec(self, vat): def is_valid_ruc_ec(self, vat):
ci = stdnum.util.get_cc_module("ec", "ci") if len(vat) in (10, 13) and vat.isdecimal():
ruc = stdnum.util.get_cc_module("ec", "ruc") return True
if len(vat) == 10:
return ci.is_valid(vat)
elif len(vat) == 13:
if vat[2] == "6" and ci.is_valid(vat[:10]):
return True
else:
return ruc.is_valid(vat)
return False return False
def check_vat_ec(self, vat): def check_vat_ec(self, vat):
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details. # Part of Odoo. See LICENSE file for full copyright and licensing details.
{ {
"name": "Ecuadorian Accounting", "name": "Ecuadorian Accounting",
"version": "3.4", "version": "3.5",
"description": """ "description": """
Functional Functional
---------- ----------
...@@ -73,6 +73,7 @@ Master Data: ...@@ -73,6 +73,7 @@ Master Data:
"views/l10n_latam_document_type_view.xml", "views/l10n_latam_document_type_view.xml",
"views/l10n_ec_sri_payment.xml", "views/l10n_ec_sri_payment.xml",
"views/account_journal_view.xml", "views/account_journal_view.xml",
"views/res_partner_view.xml",
# Try loading CoA # Try loading CoA
"data/account_chart_template_configure_data.xml", "data/account_chart_template_configure_data.xml",
], ],
......
...@@ -251,6 +251,12 @@ msgstr "Consumos Especiales (ICE)" ...@@ -251,6 +251,12 @@ msgstr "Consumos Especiales (ICE)"
msgid "Special Consumptions Tax (ICE)" msgid "Special Consumptions Tax (ICE)"
msgstr "Impuesto a los Consumos Especiales (ICE)" msgstr "Impuesto a los Consumos Especiales (ICE)"
#. module: l10n_ec
#: model:ir.model.fields,help:l10n_ec.field_res_partner__l10n_ec_vat_validation
#: model:ir.model.fields,help:l10n_ec.field_res_users__l10n_ec_vat_validation
msgid "Error message when validating the Ecuadorian VAT"
msgstr "Mensaje de error al validar la Cédula/RUC Ecuatoriana"
#. module: l10n_ec #. module: l10n_ec
#: model:ir.model,name:l10n_ec.model_account_tax #: model:ir.model,name:l10n_ec.model_account_tax
msgid "Tax" msgid "Tax"
...@@ -312,22 +318,22 @@ msgstr "Desconocido" ...@@ -312,22 +318,22 @@ msgstr "Desconocido"
#: code:addons/l10n_ec/models/res_partner.py:0 #: code:addons/l10n_ec/models/res_partner.py:0
#, python-format #, python-format
msgid "" msgid ""
"VAT %s is not valid for an Ecuadorian DNI, it must be like this form " "The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"1234567897" "(could be an old VAT number)"
msgstr "" msgstr ""
"Cédula %s no es valida para el DNI de Ecuador, debe ser de esta forma " "La Cédula %s parece no ser válida ya que el décimo dígito no cumple con el algoritmo de validación "
"1234567897" "(podría ser un número de cédula antiguo)"
#. module: l10n_ec #. module: l10n_ec
#. odoo-python #. odoo-python
#: code:addons/l10n_ec/models/res_partner.py:0 #: code:addons/l10n_ec/models/res_partner.py:0
#, python-format #, python-format
msgid "" msgid ""
"VAT %s is not valid for an Ecuadorian company, it must be like this form " "The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"1234567897001" "(SRI has stated that this validation is not required anymore for some VAT numbers)"
msgstr "" msgstr ""
"RUC %s no es valida para una compañía ecuatoriana, debe ser de esta forma " "El RUC %s parece no ser válido ya que el décimo dígito no cumple con el algoritmo de validación "
"1234567897001" "(SRI ha declarado que esta validación ya no es necesaria para algunos números de RUC)"
#. module: l10n_ec #. module: l10n_ec
#: model:account.tax.group,name:l10n_ec.tax_group_vat0 #: model:account.tax.group,name:l10n_ec.tax_group_vat0
...@@ -353,6 +359,12 @@ msgstr "IVA 14%" ...@@ -353,6 +359,12 @@ msgstr "IVA 14%"
msgid "VAT 8%" msgid "VAT 8%"
msgstr "" msgstr ""
#. module: l10n_ec
#: model:ir.model.fields,field_description:l10n_ec.field_res_partner__l10n_ec_vat_validation
#: model:ir.model.fields,field_description:l10n_ec.field_res_users__l10n_ec_vat_validation
msgid "VAT Error message validation"
msgstr "Mensaje de error de validación de Cédula/RUC"
#. module: l10n_ec #. module: l10n_ec
#: model:account.tax.group,name:l10n_ec.tax_group_vat_exempt #: model:account.tax.group,name:l10n_ec.tax_group_vat_exempt
#: model:ir.model.fields.selection,name:l10n_ec.selection__account_tax_group__l10n_ec_type__exempt_vat #: model:ir.model.fields.selection,name:l10n_ec.selection__account_tax_group__l10n_ec_type__exempt_vat
......
...@@ -276,6 +276,12 @@ msgstr "" ...@@ -276,6 +276,12 @@ msgstr ""
msgid "Special Consumptions Tax (ICE)" msgid "Special Consumptions Tax (ICE)"
msgstr "" msgstr ""
#. module: l10n_ec
#: model:ir.model.fields,help:l10n_ec.field_res_partner__l10n_ec_vat_validation
#: model:ir.model.fields,help:l10n_ec.field_res_users__l10n_ec_vat_validation
msgid "Error message when validating the Ecuadorian VAT"
msgstr ""
#. module: l10n_ec #. module: l10n_ec
#: model:ir.model,name:l10n_ec.model_account_tax #: model:ir.model,name:l10n_ec.model_account_tax
msgid "Tax" msgid "Tax"
...@@ -332,8 +338,8 @@ msgstr "" ...@@ -332,8 +338,8 @@ msgstr ""
#: code:addons/l10n_ec/models/res_partner.py:0 #: code:addons/l10n_ec/models/res_partner.py:0
#, python-format #, python-format
msgid "" msgid ""
"VAT %s is not valid for an Ecuadorian DNI, it must be like this form " "The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"1234567897" "(could be an old VAT number)"
msgstr "" msgstr ""
#. module: l10n_ec #. module: l10n_ec
...@@ -341,8 +347,8 @@ msgstr "" ...@@ -341,8 +347,8 @@ msgstr ""
#: code:addons/l10n_ec/models/res_partner.py:0 #: code:addons/l10n_ec/models/res_partner.py:0
#, python-format #, python-format
msgid "" msgid ""
"VAT %s is not valid for an Ecuadorian company, it must be like this form " "The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"1234567897001" "(SRI has stated that this validation is not required anymore for some VAT numbers)"
msgstr "" msgstr ""
#. module: l10n_ec #. module: l10n_ec
...@@ -369,6 +375,12 @@ msgstr "" ...@@ -369,6 +375,12 @@ msgstr ""
msgid "VAT 8%" msgid "VAT 8%"
msgstr "" msgstr ""
#. module: l10n_ec
#: model:ir.model.fields,field_description:l10n_ec.field_res_partner__l10n_ec_vat_validation
#: model:ir.model.fields,field_description:l10n_ec.field_res_users__l10n_ec_vat_validation
msgid "VAT Error message validation"
msgstr ""
#. module: l10n_ec #. module: l10n_ec
#: model:account.tax.group,name:l10n_ec.tax_group_vat_exempt #: model:account.tax.group,name:l10n_ec.tax_group_vat_exempt
#: model:ir.model.fields.selection,name:l10n_ec.selection__account_tax_group__l10n_ec_type__exempt_vat #: model:ir.model.fields.selection,name:l10n_ec.selection__account_tax_group__l10n_ec_type__exempt_vat
......
# Part of Odoo. See LICENSE file for full copyright and licensing details. # Part of Odoo. See LICENSE file for full copyright and licensing details.
import enum import enum
import stdnum
from odoo import _, api, models from odoo import _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
...@@ -50,6 +50,12 @@ class ResPartner(models.Model): ...@@ -50,6 +50,12 @@ class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
l10n_ec_vat_validation = fields.Char(
string="VAT Error message validation",
compute="_compute_l10n_ec_vat_validation",
help="Error message when validating the Ecuadorian VAT",
)
@api.constrains("vat", "country_id", "l10n_latam_identification_type_id") @api.constrains("vat", "country_id", "l10n_latam_identification_type_id")
def check_vat(self): def check_vat(self):
it_ruc = self.env.ref("l10n_ec.ec_ruc", False) it_ruc = self.env.ref("l10n_ec.ec_ruc", False)
...@@ -69,22 +75,26 @@ class ResPartner(models.Model): ...@@ -69,22 +75,26 @@ class ResPartner(models.Model):
if partner.l10n_latam_identification_type_id.id == it_ruc.id and len(partner.vat) != 13: if partner.l10n_latam_identification_type_id.id == it_ruc.id and len(partner.vat) != 13:
raise ValidationError(_('If your identification type is %s, it must be 13 digits') raise ValidationError(_('If your identification type is %s, it must be 13 digits')
% it_ruc.display_name) % it_ruc.display_name)
final_consumer = verify_final_consumer(partner.vat)
if final_consumer:
valid = True
else:
valid = self.is_valid_ruc_ec(partner.vat)
if not valid:
error_message = ""
if partner.l10n_latam_identification_type_id.id == it_dni.id:
error_message = _("VAT %s is not valid for an Ecuadorian DNI, "
"it must be like this form 1234567897") % partner.vat
if partner.l10n_latam_identification_type_id.id == it_ruc.id:
error_message = _("VAT %s is not valid for an Ecuadorian company, "
"it must be like this form 1234567897001") % partner.vat
raise ValidationError(error_message)
return super(ResPartner, self - ecuadorian_partners).check_vat() return super(ResPartner, self - ecuadorian_partners).check_vat()
@api.depends("vat", "country_id", "l10n_latam_identification_type_id")
def _compute_l10n_ec_vat_validation(self):
it_ruc = self.env.ref("l10n_ec.ec_ruc", False)
it_dni = self.env.ref("l10n_ec.ec_dni", False)
ruc = stdnum.util.get_cc_module("ec", "ruc")
ci = stdnum.util.get_cc_module("ec", "ci")
for partner in self:
partner.l10n_ec_vat_validation = False
if partner and partner.l10n_latam_identification_type_id in (it_ruc, it_dni) and partner.vat:
final_consumer = verify_final_consumer(partner.vat)
if not final_consumer:
if partner.l10n_latam_identification_type_id.id == it_dni.id and not ci.is_valid(partner.vat):
partner.l10n_ec_vat_validation = _("The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"(could be an old VAT number)") % partner.vat
if partner.l10n_latam_identification_type_id.id == it_ruc.id and not ruc.is_valid(partner.vat):
partner.l10n_ec_vat_validation = _("The VAT %s seems to be invalid as the tenth digit doesn't comply with the validation algorithm "
"(SRI has stated that this validation is not required anymore for some VAT numbers)") % partner.vat
def _l10n_ec_get_identification_type(self): def _l10n_ec_get_identification_type(self):
"""Maps Odoo identification types to Ecuadorian ones. """Maps Odoo identification types to Ecuadorian ones.
Useful for document type domains, electronic documents, ats, others. Useful for document type domains, electronic documents, ats, others.
......
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<div attrs="{'invisible': [('same_vat_partner_id', '=', False)]}" position="after">
<div class="alert alert-warning" role="alert" attrs="{'invisible': [('l10n_ec_vat_validation', '=', False)]}">
<field name="l10n_ec_vat_validation"/>
</div>
</div>
</field>
</record>
</odoo>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment