diff --git a/models/account_invoice.py b/models/account_invoice.py index 276cb1d82829e3531e295f78d149b1b64919518d..7cb9fb4e346ebee0563a53d46ba3f8622a8b9444 100644 --- a/models/account_invoice.py +++ b/models/account_invoice.py @@ -168,16 +168,22 @@ class AccountInvoice(models.Model): } @api.onchange('partner_id') - def cons_partner(self): - for rec in self: - lst = [1, 2, 3, 51, 52, 53, 201, 202, 203, 206, 207, 208] - voucher_type = rec._get_voucher_type() - if int(voucher_type) in lst: - if rec.partner_id.document_type_id.name != 'CUIT'\ - or not rec.partner_id.vat: - raise exceptions.UserError( - _("The client has a type of document other than CUIT") - ) + def _onchange_partner_id(self): + res = super(AccountInvoice, self)._onchange_partner_id() + if not self.partner_id: + return res + caea_lst = [1, 2, 3, 51, 52, 53, 201, 202, 203, 206, 207, 208] + try: + voucher_type = self._get_voucher_type() + except Exception: + return res + if int(voucher_type) in caea_lst: + cuit_type = self.env.ref('base_vat_ar.document_cuit') + if self.partner_id.document_type_id != cuit_type or not self.partner_id.vat: + raise exceptions.UserError( + _("The client has a type of document other than CUIT") + ) + return res # Constraints @api.multi