intrastat.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import xml.etree.cElementTree as ET
  2. from datetime import date, timedelta
  3. from tools.pyntrastat import Company, ContactPerson, Intrastat
  4. # decl = ET.parse('xml/17259191_A_20201.xml')
  5. # root = decl.getroot()
  6. ns = ET.register_namespace('InsNewArrival', 'http://www.intrastat.ro/xml/InsSchema')
  7. back_period = timedelta(days=28)
  8. ref_period = date.today() - back_period
  9. ref_period = ref_period.strftime('%Y-%m')
  10. person = ContactPerson('LEVENTE', 'MARTON', 'levente.marton@mzk.ro',
  11. '0730690044', '0264592211', 'CONTABIL')
  12. company = Company('0017259191', 'SC MOZAIK CONSULTING SRL', RefPeriod=ref_period, # '2020-06'
  13. ApplicationRef='4836218')
  14. # company_dict = vars(company)
  15. # person_dict = vars(person)
  16. versions = {'CountryVer': '2007',
  17. 'EuCountryVer': '2007',
  18. 'CnVer': '2020',
  19. 'ModeOfTransportVer': '2005',
  20. 'DeliveryTermsVer': '2011',
  21. 'NatureOfTransactionAVer': '2010',
  22. 'NatureOfTransactionBVer': '2010',
  23. 'CountyVer': '1',
  24. 'LocalityVer': '06/2006',
  25. 'UnitVer': '1'}
  26. header = ('InsCodeVersions',
  27. 'InsDeclarationHeader')
  28. a_attribs = {'xmlns': 'http://www.intrastat.ro/xml/InsSchema',
  29. 'SchemaVersion': '1.0'}
  30. # set of codes for whitch we have suppl. units
  31. supplunitcodes = {
  32. '84433900',
  33. '84433939',
  34. '84513000',
  35. '84596110',
  36. '84561190',
  37. '84431920',
  38. '84561290',
  39. '90221900',
  40. '85258099',
  41. '59113219',
  42. '90221300',
  43. '85286200',
  44. '84601900',
  45. '85141980'
  46. }
  47. # we will edit the file after parse so we don't need this here
  48. # we parse the file separate
  49. # parse_intrastat('tools/intrastat_art.xlsx', 'tools/Export.xlsx', 'tools/intrastat_part.xlsx')
  50. intrastat = Intrastat(company=company, person=person,
  51. versions=versions, header=header, elem_attribs=a_attribs,
  52. supplucodes=supplunitcodes)
  53. intrastat.make_arrival()
  54. intrastat.make_arrival_items('tools/intrastat.xlsx')
  55. intrastat.write_xml()