فهرست منبع

validation steel not working

marton levente 8 ماه پیش
والد
کامیت
8d5ef8b634
2فایلهای تغییر یافته به همراه12 افزوده شده و 8 حذف شده
  1. 6 2
      anafapi/anafoauth.py
  2. 6 6
      tests/test_anafoauth.py

+ 6 - 2
anafapi/anafoauth.py

@@ -50,6 +50,7 @@ class Anafoauth(object):
         return expires_at > datetime.datetime.today()
 
     def get_token(self) -> ujson:
+        # https://chat.openai.com/c/61c5c1c5-298a-4073-88c7-d69ce99a140e
         # oauth = OAuth2Session(self.client_id, redirect_uri=self.redirect_uri)
         authorization_url, _state = self.oauth.authorization_url(self.AUTH_URL)
         #
@@ -127,13 +128,14 @@ class Efactoauth(Anafoauth):
         #
         with open(fp, "r") as file:
             files = file.read()
+            files = files.replace('xmlns:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2../../UBL-2.1(1)/xsd/maindoc/UBL-Invoice-2.1.xsd" ', '')
             headers = {'Content-Type': 'text/plain'}
             # response = requests.post(url, files=files)
             url = self.VALIDATE.format(type_)
-            print(url)
+            # print(url)
             resp = self.oauth.post(url=url, data=files, headers=headers)
             print(resp.status_code, resp.text)
-            print(resp.status_code, resp.json())
+            # print(resp.status_code, resp.json())
             return resp.json()
 
     def transform_to_pdf(self, fp, type_='FACT1', no_validation=False):
@@ -143,6 +145,8 @@ class Efactoauth(Anafoauth):
         #
         with open(fp, "r") as file:
             files = file.read()
+            files = files.replace(r'xmlns:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2../../UBL-2.1(1)/xsd/maindoc/UBL-Invoice-2.1.xsd" ', '')
+            # print(files)
             headers = {'Content-Type': 'text/plain'}
             if no_validation:
                 url = self.TRANSFORM.format(type_, no_validation)

+ 6 - 6
tests/test_anafoauth.py

@@ -4,8 +4,6 @@ import platform
 import unittest
 import os
 
-import schedule
-
 from anafapi.anafoauth import Anafoauth, Efactoauth
 from anafapi import utils
 
@@ -52,7 +50,7 @@ class efactTest(unittest.TestCase):
         self.efactoauth.add_invoice('17259191', 'C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml', env='prod')
 
     def test_transform_to_pdf(self):
-        self.efactoauth.transform_to_pdf('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK24116.xml')
+        self.efactoauth.transform_to_pdf('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK2414.xml')
 
     def test_get_all_messages(self):
         self.efactoauth.get_all_messages('17259191', env='prod', extract=True)
@@ -95,9 +93,11 @@ class efactTest(unittest.TestCase):
 
     def test_validate_invoice(self):
         # print(os.listdir('c:/Users/DECEL/FACT1/MZK/2023.01.03/'))
-        # for file in os.listdir('c:/Users/DECEL/FACT1/MZK/2023.01.03/'):
-        #     self.efactoauth.validate_invoice(os.path.join('c:/Users/DECEL/FACT1/MZK/2023.01.03/', file))
-        self.efactoauth.validate_invoice('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK24116.xml')
+        # for root, dir, files in os.walk('c:/Users/DECEL/FACT1/MZK/2023_01_03/'):
+        #     for file in files:
+        #         print(file)
+        #         self.efactoauth.validate_invoice(os.path.join(root, file))
+        self.efactoauth.validate_invoice('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK2414.xml')
 
 
 if __name__ == "__main__":