From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/l10n_co/models/__init__.py | 5 +++++ .../l10n_co/models/l10n_latam_identification_type.py | 8 ++++++++ addons/l10n_co/models/res_partner.py | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 addons/l10n_co/models/__init__.py create mode 100644 addons/l10n_co/models/l10n_latam_identification_type.py create mode 100644 addons/l10n_co/models/res_partner.py (limited to 'addons/l10n_co/models') diff --git a/addons/l10n_co/models/__init__.py b/addons/l10n_co/models/__init__.py new file mode 100644 index 00000000..5f31f163 --- /dev/null +++ b/addons/l10n_co/models/__init__.py @@ -0,0 +1,5 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import l10n_latam_identification_type +from . import res_partner diff --git a/addons/l10n_co/models/l10n_latam_identification_type.py b/addons/l10n_co/models/l10n_latam_identification_type.py new file mode 100644 index 00000000..a860f632 --- /dev/null +++ b/addons/l10n_co/models/l10n_latam_identification_type.py @@ -0,0 +1,8 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import models, fields + + +class L10nCoDocumentType(models.Model): + _inherit = "l10n_latam.identification.type" + + l10n_co_document_code = fields.Char("Document Code") diff --git a/addons/l10n_co/models/res_partner.py b/addons/l10n_co/models/res_partner.py new file mode 100644 index 00000000..160eacb7 --- /dev/null +++ b/addons/l10n_co/models/res_partner.py @@ -0,0 +1,20 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import models, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.constrains('vat', 'country_id', 'l10n_latam_identification_type_id') + def check_vat(self): + # check_vat is implemented by base_vat which this localization + # doesn't directly depend on. It is however automatically + # installed for Colombia. + if self.sudo().env.ref('base.module_base_vat').state == 'installed': + # don't check Colombian partners unless they have RUT (= Colombian VAT) set as document type + self = self.filtered(lambda partner: partner.country_id.code != "CO" or\ + partner.l10n_latam_identification_type_id.l10n_co_document_code == 'rut') + return super(ResPartner, self).check_vat() + else: + return True -- cgit v1.2.3