From c554872409593acca946b8b09dad102b9a6b8edd Mon Sep 17 00:00:00 2001
From: joel <joemaglioni1@gmail.com>
Date: Thu, 1 Aug 2024 16:18:58 -0300
Subject: [PATCH] [Fix] fix vat for external companies with lettering.

---
 model/account_invoice_qr.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/model/account_invoice_qr.py b/model/account_invoice_qr.py
index 48847e0..675064e 100644
--- a/model/account_invoice_qr.py
+++ b/model/account_invoice_qr.py
@@ -23,6 +23,7 @@ import json
 import base64
 from openerp import models, fields, api
 import os
+import re
 import logging
 _logger = logging.getLogger(__name__)
 
@@ -70,6 +71,8 @@ class account_invoice(models.Model):
     def force_qr(self):
         return self._compute_qr()
 
+    def search_letters(self, string):
+        return bool(re.search(r'[a-zA-Z]', string))
     @api.multi
     @api.depends('cae')
     def _compute_qr(self):
@@ -99,8 +102,14 @@ class account_invoice(models.Model):
                 ctz = inv_id.currency_rate
             else:
                 ctz = 1
+
             tipoDocRec = int(partner.document_type_id.afip_code or 0)
-            nroDocRec = int((partner.vat or '0').replace('-', ''))
+            if tipoDocRec == 99 or self.search_letters(partner.vat):
+                nroDocRec = 0
+            else:
+                vat_clean = partner.vat.replace('-', '') if partner.vat else '0'
+                nroDocRec = int(vat_clean)
+
             codAut = inv_id.cae
 
             result_json = {
-- 
GitLab