123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- '''Created 19 Aug 2024 Levi'''
- import unittest
- import os
- from jinja2 import (Environment, PackageLoader)
- import pymupdf # noqa
- from anafapi.en16931 import Invoice
- def extract_numeric(value):
- return ''.join([c for c in value if c.isdigit()])
- def format_date(value):
- return value.strftime('%d.%m.%Y')
- class Test(unittest.TestCase):
- def test_en16931(self) -> None:
- templates = Environment(loader=PackageLoader('py_mentor_imports', 'templates'))
- templates.filters['extract_numeric'] = extract_numeric
- templates.filters['format_date'] = format_date
- template = templates.get_template('en16931.txt')
- template2 = templates.get_template('partners_en16931.txt')
- # inv = Invoice.from_xml(r'c:\Users\vnc-console\git\anafapi\tests\31434328\FACTURA TRIMISA\2024_08\16\31434328\33291356\4393473874.xml')
- invoices = []
- for root, _, files in os.walk(r'C:\Users\vnc-console\git\anafapi\tests\22520381\FACTURA TRIMISA\2024_07'):
- for file in files:
- if file.endswith('.xml') or file.endswith('.xml'.upper()):
- # print(os.path.join(root, file))
- inv = Invoice.from_xml(os.path.join(root, file))
- invoices.append(inv)
- # print(inv.all_lines[0])
- data = {'AnLucru': inv.issue_date.year,
- 'LunaLucru': inv.issue_date.month,
- 'TotalFacturi': len(invoices),
- 'documents': invoices,
- 'Code': 'LSERV',
- 'SerieCarnet': 'GS'
- }
- data2 = {'partners': invoices}
- output = template.render(data)
- output2 = template2.render(data2)
- print(output)
- home = os.path.expanduser('~')
- downloads_dir = os.path.join(home, 'Downloads', 'mentor', 'import', 'GERM')
- output_file = os.path.join(downloads_dir, 'facturi.txt')
- output_file2 = os.path.join(downloads_dir, 'PARTNER.txt')
- with open(output_file, 'w') as text, open(output_file2, 'w') as text2:
- text.write(output)
- text2.write(output2)
- if __name__ == "__main__":
- Test().test_en16931()
|