Files
odoo_source/addons/l10n_co/models/res_partner.py
T
Victor Feyens 1b67affe7d [FIX] *: avoid direct references to countries
Ensure the code works fine even if countries are deleted.

Also consider "re"-created countries after deletion, by only considering
the country code, not the data reference.

This should reduce support requests related to deleted countries, and
ease the resolution of such problems by the users themselves.

TASK ID - 2368842

closes odoo/odoo#60558

X-original-commit: 037012bc4e2935eb00a7f353529bb7ec55066733
Related: odoo/enterprise#14347
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-10-22 16:17:26 +00:00

21 lines
941 B
Python

# 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