Răsfoiți Sursa

string variables

vnc-console 3 luni în urmă
părinte
comite
83f0f229f2
1 a modificat fișierele cu 15 adăugiri și 6 ștergeri
  1. 15 6
      tests/test_sale_invoice.py

+ 15 - 6
tests/test_sale_invoice.py

@@ -16,6 +16,13 @@ class Test(unittest.TestCase):
     template = templates.get_template('bolt_sale_invoice.txt')
     template2 = templates.get_template('partners.txt')
 
+    code_string = r'(?<=Cod TVA: )[a-zA-Z0-9]*|(?<=VAT no.: )[a-zA-Z0-9]*|(?<=Reg. code: )[a-zA-Z0-9]*|(?<=Cod unic de înregistrare: )[a-zA-Z0-9]*'
+    name_string = r'[a-zA-Z0-9. ]*(?=\nRidewave SRL)'
+    value_string = r'(?<=otal \(RON\):\n)[a-zA-Z0-9.]*'
+    docn_string = r'(?<=Factura nr. )[a-zA-Z\n0-9-]*|(?<=Invoice no. )[a-zA-Z\n0-9-]*'
+    note_string = r'(?<=Pornire: )[a-zA-Z \n,.\(\):0-9-]*|(?<=Start: )[a-zA-Z \n,.\(\):0-9-]*'
+    date_string = r'(?<=Dată: )[0-9.]*|(?<=Date: )[0-9.]*'
+
     def test_bolt_inv(self) -> None:
         names = []
         codes = []
@@ -32,17 +39,19 @@ class Test(unittest.TestCase):
                         txt = page.get_text()
                         texts.append(txt)
                         # print(texts)
-                        buyer_name = re.search(r'[a-zA-Z0-9. ]*(?=\nRidewave SRL)', txt)
-                        buyer_code = re.search(r'(?<=Cod TVA: )[a-zA-Z0-9]*|(?<=Reg. code: )[a-zA-Z0-9]*', txt).group() # noqa E:if match None
+                        buyer_name = re.search(self.name_string, txt)
+                        buyer_code = re.search(self.code_string, txt).group() # noqa E:if match None
                         if buyer_code == '49340170':
                             buyer_code = input(f'enter code manually for {buyer_name.group()}') # noqa E:if match None
+                        elif buyer_code == '14532901':
+                            buyer_code = '42717800'
 
-                        total_value = re.search(r'(?<=otal \(RON\):\n)[a-zA-Z0-9.]*', txt)
-                        doc_number = re.search(r'(?<=Factura nr. )[a-zA-Z\n0-9-]*|(?<=Invoice no. )[a-zA-Z\n0-9-]*', txt)
+                        total_value = re.search(self.value_string, txt)
+                        doc_number = re.search(self.docn_string, txt)
                         doc_number = doc_number.group().strip().replace('\n', '')[-3:] # noqa E:if match None
-                        doc_notes = re.search(r'(?<=Pornire: )[a-zA-Z \n,.\(\):0-9-]*|(?<=Start: )[a-zA-Z \n,.\(\):0-9-]*', txt)
+                        doc_notes = re.search(self.note_string, txt)
                         doc_notes = doc_notes.group().strip().replace('\n', '') # noqa E:if match None
-                        doc_data = re.search(r'(?<=Dată: )[0-9.]*|(?<=Date: )[0-9.]*', txt)
+                        doc_data = re.search(self.date_string, txt)
                         names.append(buyer_name.group()) # noqa E:if match None
                         codes.append(buyer_code)
                         values.append(total_value.group()) # noqa E:if match None