From c992f362a5a93ef7fd6f9bfc2485592bb339ae5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gast=C3=B3n=20Bertolani?= <gaston.bertolani@gmail.com>
Date: Tue, 27 Jun 2023 14:45:56 -0300
Subject: [PATCH 1/2] [FIX]Validation

---
 models/account_invoice.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/models/account_invoice.py b/models/account_invoice.py
index 276cb1d..c6c0a01 100644
--- a/models/account_invoice.py
+++ b/models/account_invoice.py
@@ -168,16 +168,19 @@ 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]
+        voucher_type = self._get_voucher_type()
+        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
-- 
GitLab


From 17f1da44a1db390067ea671ae7af5c35e8defde1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gast=C3=B3n=20Bertolani?= <gaston.bertolani@gmail.com>
Date: Tue, 27 Jun 2023 15:05:17 -0300
Subject: [PATCH 2/2] [FIX]Validation

---
 models/account_invoice.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/models/account_invoice.py b/models/account_invoice.py
index c6c0a01..7cb9fb4 100644
--- a/models/account_invoice.py
+++ b/models/account_invoice.py
@@ -173,7 +173,10 @@ class AccountInvoice(models.Model):
         if not self.partner_id:
             return res
         caea_lst = [1, 2, 3, 51, 52, 53, 201, 202, 203, 206, 207, 208]
-        voucher_type = self._get_voucher_type()
+        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:
-- 
GitLab