import xml.etree.cElementTree as ET from datetime import date, timedelta from tools.pyntrastat import Company, ContactPerson, Intrastat # decl = ET.parse('xml/17259191_A_20201.xml') # root = decl.getroot() ns = ET.register_namespace('InsNewArrival', 'http://www.intrastat.ro/xml/InsSchema') back_period = timedelta(days=28) ref_period = date.today() - back_period ref_period = ref_period.strftime('%Y-%m') person = ContactPerson('LEVENTE', 'MARTON', 'levente.marton@mzk.ro', '0730690044', '0264592211', 'CONTABIL') company = Company('0017259191', 'SC MOZAIK CONSULTING SRL', RefPeriod=ref_period, # '2020-06' ApplicationRef='4836218') # company_dict = vars(company) # person_dict = vars(person) versions = {'CountryVer': '2007', 'EuCountryVer': '2007', 'CnVer': '2020', 'ModeOfTransportVer': '2005', 'DeliveryTermsVer': '2011', 'NatureOfTransactionAVer': '2010', 'NatureOfTransactionBVer': '2010', 'CountyVer': '1', 'LocalityVer': '06/2006', 'UnitVer': '1'} header = ('InsCodeVersions', 'InsDeclarationHeader') a_attribs = {'xmlns': 'http://www.intrastat.ro/xml/InsSchema', 'SchemaVersion': '1.0'} # set of codes for whitch we have suppl. units supplunitcodes = { '84433900', '84433939', '84513000', '84596110', '84561190', '84431920', '84561290', '90221900', '85258099', '59113219', '90221300', '85286200', '84601900', '85141980' } # we will edit the file after parse so we don't need this here # we parse the file separate # parse_intrastat('tools/intrastat_art.xlsx', 'tools/Export.xlsx', 'tools/intrastat_part.xlsx') intrastat = Intrastat(company=company, person=person, versions=versions, header=header, elem_attribs=a_attribs, supplucodes=supplunitcodes) intrastat.make_arrival() intrastat.make_arrival_items('tools/intrastat.xlsx') intrastat.write_xml()