add legal id of seller
This commit is contained in:
parent
214cbb086f
commit
d065f74482
2 changed files with 81 additions and 1 deletions
26
mixin.py
26
mixin.py
|
@ -239,4 +239,30 @@ class EdocumentMixin(object):
|
||||||
if text:
|
if text:
|
||||||
return html.escape(text)
|
return html.escape(text)
|
||||||
|
|
||||||
|
def _party_legal_types(self):
|
||||||
|
""" get list of identifier-types to be used as
|
||||||
|
legal-ids
|
||||||
|
"""
|
||||||
|
return ['de_handelsregisternummer']
|
||||||
|
|
||||||
|
def party_legal_ids(self, party, address):
|
||||||
|
""" get list of legal-ids of party
|
||||||
|
|
||||||
|
Args:
|
||||||
|
party (record): model party.party
|
||||||
|
address (record): model party.address
|
||||||
|
"""
|
||||||
|
result = super().party_legal_ids(party, address)
|
||||||
|
|
||||||
|
legal_types = self._party_legal_types()
|
||||||
|
if party and party.identifiers:
|
||||||
|
for x in party.identifiers:
|
||||||
|
if x.type in legal_types:
|
||||||
|
if x.address:
|
||||||
|
if x.address == address:
|
||||||
|
result.append((x.rec_name, {'schemeID': '0002'}))
|
||||||
|
else:
|
||||||
|
result.append((x.rec_name, {'schemeID': '0002'}))
|
||||||
|
return result
|
||||||
|
|
||||||
# end EdocumentMixin
|
# end EdocumentMixin
|
||||||
|
|
|
@ -78,6 +78,11 @@ class EdocTestCase(ModuleTestCase):
|
||||||
|
|
||||||
company = create_company('m-ds')
|
company = create_company('m-ds')
|
||||||
Party.write(*[[company.party], {
|
Party.write(*[[company.party], {
|
||||||
|
'identifiers': [('create', [
|
||||||
|
# post.de
|
||||||
|
{'type': 'de_handelsregisternummer', 'code': 'Bonn HRB 6792'},
|
||||||
|
{'type': 'de_vat', 'code': 'DE 169838187'},
|
||||||
|
])],
|
||||||
'addresses': [('write', [company.party.addresses[0]], {
|
'addresses': [('write', [company.party.addresses[0]], {
|
||||||
'country': country_de.id})]}])
|
'country': country_de.id})]}])
|
||||||
|
|
||||||
|
@ -121,6 +126,7 @@ class EdocTestCase(ModuleTestCase):
|
||||||
}])
|
}])
|
||||||
|
|
||||||
currency1, = Currency.search([('code', '=', 'usd')])
|
currency1, = Currency.search([('code', '=', 'usd')])
|
||||||
|
Currency.write(*[[currency1], {'code': 'USD'}])
|
||||||
|
|
||||||
tax, = Taxes.search([('name', '=', '20% VAT')])
|
tax, = Taxes.search([('name', '=', '20% VAT')])
|
||||||
Taxes.write(*[
|
Taxes.write(*[
|
||||||
|
@ -169,7 +175,7 @@ class EdocTestCase(ModuleTestCase):
|
||||||
inv_lst.save()
|
inv_lst.save()
|
||||||
Invoice.validate_invoice([inv_lst])
|
Invoice.validate_invoice([inv_lst])
|
||||||
Invoice.post([inv_lst])
|
Invoice.post([inv_lst])
|
||||||
self.assertEqual(inv_lst.currency.code, 'usd')
|
self.assertEqual(inv_lst.currency.code, 'USD')
|
||||||
self.assertEqual(len(inv_lst.move.lines), 3)
|
self.assertEqual(len(inv_lst.move.lines), 3)
|
||||||
return inv_lst
|
return inv_lst
|
||||||
|
|
||||||
|
@ -273,9 +279,44 @@ class EdocTestCase(ModuleTestCase):
|
||||||
fhdl.write(invoice_string)
|
fhdl.write(invoice_string)
|
||||||
|
|
||||||
invoice_xml = etree.fromstring(invoice_string)
|
invoice_xml = etree.fromstring(invoice_string)
|
||||||
|
|
||||||
|
# check values in xml
|
||||||
|
nodes = invoice_xml.xpath(self._readxml_xpath([
|
||||||
|
'rsm:CrossIndustryInvoice', 'rsm:SupplyChainTradeTransaction',
|
||||||
|
'ram:ApplicableHeaderTradeAgreement', 'ram:SellerTradeParty',
|
||||||
|
'ram:SpecifiedLegalOrganization', 'ram:ID']),
|
||||||
|
namespaces=invoice_xml.nsmap)
|
||||||
|
self.assertEqual(nodes[0].text, 'Bonn HRB 6792')
|
||||||
|
|
||||||
|
nodes = invoice_xml.xpath(self._readxml_xpath([
|
||||||
|
'rsm:CrossIndustryInvoice', 'rsm:SupplyChainTradeTransaction',
|
||||||
|
'ram:IncludedSupplyChainTradeLineItem',
|
||||||
|
'ram:SpecifiedLineTradeSettlement',
|
||||||
|
'ram:SpecifiedTradeSettlementLineMonetarySummation',
|
||||||
|
'ram:LineTotalAmount']),
|
||||||
|
namespaces=invoice_xml.nsmap)
|
||||||
|
self.assertEqual(nodes[0].text, '100.00')
|
||||||
|
|
||||||
schema = etree.XMLSchema(etree.parse(schema_file))
|
schema = etree.XMLSchema(etree.parse(schema_file))
|
||||||
schema.assertValid(invoice_xml)
|
schema.assertValid(invoice_xml)
|
||||||
|
|
||||||
|
def _readxml_xpath(self, tags):
|
||||||
|
""" generate xpath
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tags (list): list of string or integer to build path
|
||||||
|
"""
|
||||||
|
parts = []
|
||||||
|
for x in tags:
|
||||||
|
if isinstance(x, str):
|
||||||
|
parts.append(x)
|
||||||
|
elif isinstance(x, int):
|
||||||
|
if parts[-1].endswith(']'):
|
||||||
|
raise ValueError('multiple list selector')
|
||||||
|
parts[-1] += '[%d]' % x
|
||||||
|
result = '/' + '/'.join(parts)
|
||||||
|
return result
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_xrechn_export_facturx(self):
|
def test_xrechn_export_facturx(self):
|
||||||
""" run export - factur-x
|
""" run export - factur-x
|
||||||
|
@ -291,6 +332,10 @@ class EdocTestCase(ModuleTestCase):
|
||||||
|
|
||||||
template = Template(invoice)
|
template = Template(invoice)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
template.party_legal_ids(invoice.company_party, None),
|
||||||
|
[('Bonn HRB 6792', {'schemeID': '0002'})])
|
||||||
|
|
||||||
schema_file = os.path.join(
|
schema_file = os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
'Factur-X_1.07.2_EXTENDED',
|
'Factur-X_1.07.2_EXTENDED',
|
||||||
|
@ -298,6 +343,15 @@ class EdocTestCase(ModuleTestCase):
|
||||||
|
|
||||||
invoice_string = template.render('Factur-X-1.07.2-extended')
|
invoice_string = template.render('Factur-X-1.07.2-extended')
|
||||||
invoice_xml = etree.fromstring(invoice_string)
|
invoice_xml = etree.fromstring(invoice_string)
|
||||||
|
|
||||||
|
# check values in xml
|
||||||
|
nodes = invoice_xml.xpath(self._readxml_xpath([
|
||||||
|
'rsm:CrossIndustryInvoice', 'rsm:SupplyChainTradeTransaction',
|
||||||
|
'ram:ApplicableHeaderTradeAgreement', 'ram:SellerTradeParty',
|
||||||
|
'ram:SpecifiedLegalOrganization', 'ram:ID']),
|
||||||
|
namespaces=invoice_xml.nsmap)
|
||||||
|
self.assertEqual(nodes[0].text, 'Bonn HRB 6792')
|
||||||
|
|
||||||
schema = etree.XMLSchema(etree.parse(schema_file))
|
schema = etree.XMLSchema(etree.parse(schema_file))
|
||||||
schema.assertValid(invoice_xml)
|
schema.assertValid(invoice_xml)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue