# -*- coding: utf-8 -*- # Copyright 2021 Joan MarĂ­n # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, _ from odoo.exceptions import ValidationError class ResPartner(models.Model): _inherit = "res.partner" def _get_partner_basic_values(self): msg1 = _("'%s' does not have a DIAN document type established.") msg2 = _("'%s' does not have a verification digit established.") msg3 = _("'%s' does not have a identification document established.") identification_document = self.ref_num if not self.ref_type_id: raise ValidationError(msg1 % self.name) document_type_code = self.ref_type_id.code_dian if (document_type_code == '31' and not self.verification_code and str(self.verification_code) != '0'): raise ValidationError(msg2 % self.name) if not identification_document: raise ValidationError(msg3 % self.name) return { 'TipoDocumento': document_type_code, 'RazonSocial': self.name, 'NIT': identification_document, 'DV': self.verification_code} def _get_partner_values(self): values = self._get_partner_basic_values() msg1 = _("'%s' does not have a city established.") msg2 = _("'%s' does not have a state established.") msg3 = _("'%s' does not have a country established.") if self.country_id: if self.country_id.code == 'CO': if not self.city_id: raise ValidationError(msg1 % self.name) elif not self.state_id: raise ValidationError(msg2 % self.name) else: raise ValidationError(msg3 % self.name) values['Pais'] = self.country_id.code values['DepartamentoEstado'] = self.state_id.code or '' values['MunicipioCiudad'] = self.state_id.code + self.city_id.code values['Direccion'] = self.street or '' return values def _get_employee_values(self, wage): values = self._get_partner_values() values['Sueldo'] = wage values['PrimerApellido'] = self.first_surname values['SegundoApellido'] = self.second_surname or '' values['PrimerNombre'] = self.first_name if self.second_name: values['OtrosNombres'] = self.second_name return values