Merge branch 'main' into 6.0

This commit is contained in:
Frederik Jaeckel 2025-06-11 16:13:20 +02:00
commit 377c94e49b
5 changed files with 173 additions and 9 deletions

View file

@ -7,7 +7,8 @@ from lxml import etree
import os
from decimal import Decimal
from datetime import date
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.tests.test_tryton import (
ModuleTestCase, with_transaction, activate_module)
from trytond.pool import Pool
from trytond.modules.company.tests import create_company, set_company
from trytond.modules.account.tests import create_chart, get_fiscalyear
@ -42,6 +43,14 @@ class EdocTestCase(ModuleTestCase):
'Test e-rechnung module'
module = 'edocument_xrechnung'
@classmethod
def setUpClass(cls):
super().setUpClass()
activate_module([
'edocument_uncefact', 'party', 'bank',
'account_invoice', 'sale_point_invoice',
'product_grossprice'], 'en')
def prep_fiscalyear(self, company1):
""" prepare fiscal year, sequences...
"""
@ -69,6 +78,11 @@ class EdocTestCase(ModuleTestCase):
company = create_company('m-ds')
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]], {
'country': country_de.id})]}])
@ -84,7 +98,7 @@ class EdocTestCase(ModuleTestCase):
'number': 'DE02300209000106531065'}])]}])
return company
def prep_invoice(self, credit_note=False):
def prep_invoice(self, credit_note=False, modegross='net'):
""" add invoice
"""
pool = Pool()
@ -112,11 +126,12 @@ class EdocTestCase(ModuleTestCase):
}])
currency1, = Currency.search([('code', '=', 'usd')])
Currency.write(*[[currency1], {'code': 'USD'}])
tax, = Taxes.search([('name', '=', '20% VAT')])
Taxes.write(*[
[tax],
{'unece_code': 'GST', 'unece_category_code': 'S',
{'unece_code': 'VAT', 'unece_category_code': 'S',
'legal_notice': 'Legal Notice'}])
account_lst = Account.search([
@ -130,6 +145,7 @@ class EdocTestCase(ModuleTestCase):
to_create_invoice = [{
'type': 'out',
'modegross': modegross,
'description': 'description of invoice',
'comment': 'note line 1\nnote line 2',
'invoice_date': date(2024, 7, 1),
@ -149,12 +165,17 @@ class EdocTestCase(ModuleTestCase):
'currency': currency1.id,
}])],
}]
if modegross == 'gross':
to_create_invoice[0]['lines'][0][1][0]['unit_gross_price'] = (
Decimal('50.0') * Decimal('1.2'))
inv_lst, = Invoice.create(to_create_invoice)
inv_lst.on_change_lines()
inv_lst.save()
Invoice.validate_invoice([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)
return inv_lst
@ -233,6 +254,69 @@ class EdocTestCase(ModuleTestCase):
{'identifiers': [('delete', [party.identifiers[0].id])]}]
)
@with_transaction()
def test_xrechn_export_facturx_gross(self):
""" run export - factur-x, modegross='gross'
"""
pool = Pool()
Template = pool.get('edocument.facturxext.invoice')
company = self.prep_company()
with set_company(company):
create_chart(company=company, tax=True)
self.prep_fiscalyear(company)
invoice = self.prep_invoice(modegross='gross')
template = Template(invoice)
schema_file = os.path.join(
os.path.dirname(__file__),
'Factur-X_1.07.2_EXTENDED',
'Factur-X_1.07.2_EXTENDED.xsd')
invoice_string = template.render('Factur-X-1.07.2-extended')
with open('gross_invoice_string.xml', 'wb') as fhdl:
fhdl.write(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.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()
def test_xrechn_export_facturx(self):
""" run export - factur-x
@ -248,6 +332,10 @@ class EdocTestCase(ModuleTestCase):
template = Template(invoice)
self.assertEqual(
template.party_legal_ids(invoice.company_party, None),
[('Bonn HRB 6792', {'schemeID': '0002'})])
schema_file = os.path.join(
os.path.dirname(__file__),
'Factur-X_1.07.2_EXTENDED',
@ -255,6 +343,15 @@ class EdocTestCase(ModuleTestCase):
invoice_string = template.render('Factur-X-1.07.2-extended')
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.assertValid(invoice_xml)