flectra/addons/l10n_co/models/res_partner.py

43 lines
2.0 KiB
Python
Raw Normal View History

# coding: utf-8
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
2018-01-16 11:34:37 +01:00
from flectra import api, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
l10n_co_document_type = fields.Selection([('rut', 'RUT'),
('id_card', 'Tarjeta de Identidad'),
('passport', 'Pasaporte'),
('foreign_id_card', 'Cedula de Extranjeria'),
('external_id', 'ID del Exterior')], string='Document Type',
help='Indicates to what document the information in here belongs to.')
l10n_co_verification_code = fields.Char(compute='_compute_verification_code', string='VC',
help='Redundancy check to verify the vat number has been typed in correctly.')
@api.depends('vat')
def _compute_verification_code(self):
multiplication_factors = [71, 67, 59, 53, 47, 43, 41, 37, 29, 23, 19, 17, 13, 7, 3]
for partner in self.filtered(lambda partner: partner.vat and partner.country_id == self.env.ref('base.co') and
len(partner.vat) <= len(multiplication_factors)):
number = 0
padded_vat = partner.vat
while len(padded_vat) < len(multiplication_factors):
padded_vat = '0' + padded_vat
# if there is a single non-integer in vat the verification code should be False
try:
for index, vat_number in enumerate(padded_vat):
number += int(vat_number) * multiplication_factors[index]
number %= 11
if number < 2:
partner.l10n_co_verification_code = number
else:
partner.l10n_co_verification_code = 11 - number
except ValueError:
partner.l10n_co_verification_code = False