update tests to check generated xml-data
This commit is contained in:
parent
7f433d9b80
commit
bd39ae228a
2 changed files with 193 additions and 0 deletions
|
@ -5,11 +5,14 @@
|
|||
|
||||
from decimal import Decimal
|
||||
from datetime import date
|
||||
from facturx import get_facturx_xml_from_pdf
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
from trytond.modules.account.tests import create_chart, get_fiscalyear
|
||||
from .xml_data import xml_from_pdf
|
||||
|
||||
|
||||
def set_invoice_sequences(fiscalyear):
|
||||
|
@ -89,6 +92,7 @@ class InvoiceTestCase(ModuleTestCase):
|
|||
'lines': [('create', [{
|
||||
'type': 'line',
|
||||
'quantity': 2.0,
|
||||
'description': 'Product 1',
|
||||
'unit': Uom.search([('symbol', '=', 'u')])[0].id,
|
||||
'unit_price': Decimal('50.0'),
|
||||
'taxes': [('add', [tax_lst[0].id])],
|
||||
|
@ -112,8 +116,15 @@ class InvoiceTestCase(ModuleTestCase):
|
|||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
Party = pool.get('party.party')
|
||||
Country = pool.get('country.country')
|
||||
ActionReport = pool.get('ir.action.report')
|
||||
ExportWiz = pool.get('account_invoice_xrechnung.runrep', type='wizard')
|
||||
Tax = pool.get('account.tax')
|
||||
|
||||
country_de, = Country.create([{
|
||||
'name': 'Germany',
|
||||
'code': 'DE',
|
||||
'code3': 'DEU'}])
|
||||
pty1, = Party.create([{
|
||||
'name': 'Payee',
|
||||
'addresses': [('create', [{
|
||||
|
@ -121,10 +132,18 @@ class InvoiceTestCase(ModuleTestCase):
|
|||
'street': 'Applicant Street 1',
|
||||
'postal_code': '12345',
|
||||
'city': 'Usertown',
|
||||
'country': country_de.id,
|
||||
}])],
|
||||
}])
|
||||
|
||||
company1 = create_company('m-ds')
|
||||
Party.write(*[
|
||||
[company1.party],
|
||||
{'addresses': [(
|
||||
'write',
|
||||
[company1.party.addresses[0]],
|
||||
{'country': country_de.id})]}])
|
||||
|
||||
with set_company(company1):
|
||||
with Transaction().set_context({'company': company1.id}):
|
||||
|
||||
|
@ -141,8 +160,78 @@ class InvoiceTestCase(ModuleTestCase):
|
|||
self.assertEqual(cfg1.xrechn_zugferd_report.name, 'Invoice')
|
||||
create_chart(company=company1, tax=True)
|
||||
self.prep_fiscalyear(company1)
|
||||
|
||||
tax, = Tax.search([('name', '=', '20% VAT')])
|
||||
Tax.write(*[
|
||||
[tax],
|
||||
{'unece_code': 'GST', 'unece_category_code': 'S'}])
|
||||
invoice = self.prep_invoice(pty1)
|
||||
|
||||
# start wizard with two selected records
|
||||
with Transaction().set_context({
|
||||
'active_ids': [invoice.id],
|
||||
'active_id': invoice.id,
|
||||
'active_model': 'account.invoice'}):
|
||||
|
||||
(sess_id, start_state, end_state) = ExportWiz.create()
|
||||
w_obj = ExportWiz(sess_id)
|
||||
self.assertEqual(start_state, 'start')
|
||||
self.assertEqual(end_state, 'end')
|
||||
result = ExportWiz.execute(sess_id, {}, start_state)
|
||||
|
||||
self.assertEqual(
|
||||
list(result['view']['defaults'].keys()), [
|
||||
'as_zip', 'edocument', 'invoice', 'state',
|
||||
'invoice.'])
|
||||
|
||||
data = {}
|
||||
for x in result['view']['defaults'].keys():
|
||||
if '.' in x:
|
||||
continue
|
||||
data[x] = result['view']['defaults'][x]
|
||||
setattr(w_obj.start, x, data[x])
|
||||
self.assertEqual(
|
||||
w_obj.start.edocument,
|
||||
'edocument.facturxext.invoice-ferd')
|
||||
self.assertEqual(w_obj.start.invoice, invoice)
|
||||
self.assertEqual(w_obj.start.as_zip, True)
|
||||
w_obj.start.as_zip = False
|
||||
data['as_zip'] = False
|
||||
|
||||
# (action, data)
|
||||
result = ExportWiz.execute(
|
||||
sess_id, {'start': data}, 'export')
|
||||
self.assertEqual(len(result['actions']), 1)
|
||||
(action, data) = result['actions'][0]
|
||||
|
||||
self.assertEqual(
|
||||
action['report_name'],
|
||||
'account_invoice_xrechnung.export')
|
||||
self.assertEqual(action['type'], 'ir.action.report')
|
||||
self.assertEqual(action['records'], 'selected')
|
||||
|
||||
# 2nd step, wizard told us which report we must execute
|
||||
ReportExport = pool.get(
|
||||
'account_invoice_xrechnung.export',
|
||||
type='report')
|
||||
data2 = {}
|
||||
data2.update(data)
|
||||
data2['action_id'] = action['id']
|
||||
data2['model'] = 'account.invoice'
|
||||
|
||||
(ext, pdfdata, dprint, fname) = ReportExport.execute(
|
||||
[data['invoice']], data2)
|
||||
|
||||
# extract xml
|
||||
(xml_fname, xml_frompdf) = get_facturx_xml_from_pdf(
|
||||
pdfdata)
|
||||
|
||||
self.assertEqual(xml_fname, 'factur-x.xml')
|
||||
self.assertEqual(
|
||||
xml_frompdf.decode('utf8'),
|
||||
xml_from_pdf % {
|
||||
'datetoday': date.today().strftime('%Y%m%d')})
|
||||
ExportWiz.delete(sess_id)
|
||||
|
||||
# end InvoiceTestCase
|
||||
|
||||
|
|
104
tests/xml_data.py
Normal file
104
tests/xml_data.py
Normal file
|
@ -0,0 +1,104 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the account-invoice-xrechnung-module
|
||||
# from m-ds for Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
|
||||
xml_from_pdf = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<rsm:ExchangedDocumentContext>
|
||||
<ram:GuidelineSpecifiedDocumentContextParameter>
|
||||
<ram:ID>urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended</ram:ID>
|
||||
</ram:GuidelineSpecifiedDocumentContextParameter>
|
||||
</rsm:ExchangedDocumentContext>
|
||||
<rsm:ExchangedDocument>
|
||||
<ram:ID>1</ram:ID>
|
||||
<ram:Name>Parts</ram:Name>
|
||||
<ram:TypeCode>380</ram:TypeCode>
|
||||
<ram:IssueDateTime>
|
||||
<udt:DateTimeString format="102">20240701</udt:DateTimeString>
|
||||
</ram:IssueDateTime>
|
||||
</rsm:ExchangedDocument>
|
||||
<rsm:SupplyChainTradeTransaction>
|
||||
<ram:IncludedSupplyChainTradeLineItem>
|
||||
<ram:AssociatedDocumentLineDocument>
|
||||
<ram:LineID>1</ram:LineID>
|
||||
</ram:AssociatedDocumentLineDocument>
|
||||
<ram:SpecifiedTradeProduct>
|
||||
<ram:Name></ram:Name>
|
||||
<ram:Description>Product 1</ram:Description>
|
||||
</ram:SpecifiedTradeProduct>
|
||||
<ram:SpecifiedLineTradeAgreement>
|
||||
<ram:NetPriceProductTradePrice>
|
||||
<ram:ChargeAmount currencyID="usd">50.00</ram:ChargeAmount>
|
||||
</ram:NetPriceProductTradePrice>
|
||||
</ram:SpecifiedLineTradeAgreement>
|
||||
<ram:SpecifiedLineTradeDelivery>
|
||||
<ram:BilledQuantity unitCode="C62">2.0</ram:BilledQuantity>
|
||||
</ram:SpecifiedLineTradeDelivery>
|
||||
<ram:SpecifiedLineTradeSettlement>
|
||||
<ram:ApplicableTradeTax>
|
||||
<ram:TypeCode>GST</ram:TypeCode>
|
||||
<ram:CategoryCode>S</ram:CategoryCode>
|
||||
<ram:RateApplicablePercent>20.0</ram:RateApplicablePercent>
|
||||
</ram:ApplicableTradeTax>
|
||||
<ram:SpecifiedTradeSettlementLineMonetarySummation>
|
||||
<ram:LineTotalAmount currencyID="usd">100.00</ram:LineTotalAmount>
|
||||
</ram:SpecifiedTradeSettlementLineMonetarySummation>
|
||||
</ram:SpecifiedLineTradeSettlement>
|
||||
</ram:IncludedSupplyChainTradeLineItem>
|
||||
<ram:ApplicableHeaderTradeAgreement>
|
||||
<ram:SellerTradeParty>
|
||||
<ram:Name>m-ds</ram:Name>
|
||||
<ram:SpecifiedLegalOrganization>
|
||||
</ram:SpecifiedLegalOrganization>
|
||||
<ram:PostalTradeAddress>
|
||||
<ram:CountryID>DE</ram:CountryID>
|
||||
</ram:PostalTradeAddress>
|
||||
</ram:SellerTradeParty>
|
||||
<ram:BuyerTradeParty>
|
||||
<ram:Name>Payee</ram:Name>
|
||||
<ram:SpecifiedLegalOrganization>
|
||||
</ram:SpecifiedLegalOrganization>
|
||||
<ram:PostalTradeAddress>
|
||||
<ram:PostcodeCode>12345</ram:PostcodeCode>
|
||||
<ram:LineOne>Applicant Street 1</ram:LineOne>
|
||||
<ram:CityName>Usertown</ram:CityName>
|
||||
<ram:CountryID>DE</ram:CountryID>
|
||||
</ram:PostalTradeAddress>
|
||||
</ram:BuyerTradeParty>
|
||||
<ram:BuyerOrderReferencedDocument>
|
||||
<ram:IssuerAssignedID/>
|
||||
</ram:BuyerOrderReferencedDocument>
|
||||
</ram:ApplicableHeaderTradeAgreement>
|
||||
<ram:ApplicableHeaderTradeDelivery>
|
||||
</ram:ApplicableHeaderTradeDelivery>
|
||||
<ram:ApplicableHeaderTradeSettlement>
|
||||
<ram:PaymentReference>1</ram:PaymentReference>
|
||||
<ram:InvoiceCurrencyCode>usd</ram:InvoiceCurrencyCode>
|
||||
<ram:SpecifiedTradeSettlementPaymentMeans>
|
||||
<ram:TypeCode>1</ram:TypeCode>
|
||||
</ram:SpecifiedTradeSettlementPaymentMeans>
|
||||
<ram:ApplicableTradeTax>
|
||||
<ram:CalculatedAmount currencyID="usd">20.00</ram:CalculatedAmount>
|
||||
<ram:TypeCode>GST</ram:TypeCode>
|
||||
<ram:BasisAmount>100.00</ram:BasisAmount>
|
||||
<ram:CategoryCode>S</ram:CategoryCode>
|
||||
<ram:RateApplicablePercent>20.0</ram:RateApplicablePercent>
|
||||
</ram:ApplicableTradeTax>
|
||||
<ram:SpecifiedTradePaymentTerms>
|
||||
<ram:DueDateDateTime>
|
||||
<udt:DateTimeString format="102">%(datetoday)s</udt:DateTimeString>
|
||||
</ram:DueDateDateTime>
|
||||
<ram:PartialPaymentAmount currencyID="usd">120.00</ram:PartialPaymentAmount>
|
||||
</ram:SpecifiedTradePaymentTerms>
|
||||
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
||||
<ram:LineTotalAmount currencyID="usd">100.00</ram:LineTotalAmount>
|
||||
<ram:TaxBasisTotalAmount currencyID="usd">100.00</ram:TaxBasisTotalAmount>
|
||||
<ram:TaxTotalAmount currencyID="usd">20.00</ram:TaxTotalAmount>
|
||||
<ram:GrandTotalAmount currencyID="usd">120.00</ram:GrandTotalAmount>
|
||||
<ram:DuePayableAmount currencyID="usd">120.00</ram:DuePayableAmount>
|
||||
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
||||
</ram:ApplicableHeaderTradeSettlement>
|
||||
</rsm:SupplyChainTradeTransaction>
|
||||
</rsm:CrossIndustryInvoice>"""
|
Loading…
Reference in a new issue