depency edocument_unece, fix quantity-unit

This commit is contained in:
Frederik Jaeckel 2025-01-22 11:51:30 +01:00
parent c5843caf00
commit 7b0ca66b42
4 changed files with 212 additions and 18 deletions

View file

@ -25,14 +25,14 @@ from trytond.protocols.jsonrpc import JSONEncoder
xml_types = [ xml_types = [
(['xsd', 'Factur-X_1.07.2_MINIMUM', 'Factur-X_1.07.2_MINIMUM.xsd'], (['xsd', 'Factur-X_1.07.2_MINIMUM', 'Factur-X_1.07.2_MINIMUM.xsd'],
'Factur-X minimum', 'facturx_minimal'), 'Factur-X minimum', 'facturx_minimal'),
(['xsd', 'Factur-X_1.07.2_EXTENDED', 'Factur-X_1.07.2_EXTENDED.xsd'],
'Factur-X extended', 'facturx_extended'),
(['xsd', 'Factur-X_1.07.2_EN16931', 'Factur-X_1.07.2_EN16931.xsd'],
'Factur-X EN16931', ''),
(['xsd', 'Factur-X_1.07.2_BASIC', 'Factur-X_1.07.2_BASIC.xsd'], (['xsd', 'Factur-X_1.07.2_BASIC', 'Factur-X_1.07.2_BASIC.xsd'],
'Factur-X basic', ''), 'Factur-X basic', 'facturx_basic'),
(['xsd', 'Factur-X_1.07.2_BASICWL', 'Factur-X_1.07.2_BASICWL.xsd'], (['xsd', 'Factur-X_1.07.2_BASICWL', 'Factur-X_1.07.2_BASICWL.xsd'],
'Factur-X basic-wl', ''), 'Factur-X basic-wl', ''),
(['xsd', 'Factur-X_1.07.2_EN16931', 'Factur-X_1.07.2_EN16931.xsd'],
'Factur-X EN16931', ''),
(['xsd', 'Factur-X_1.07.2_EXTENDED', 'Factur-X_1.07.2_EXTENDED.xsd'],
'Factur-X extended', 'facturx_extended'),
(['xsd', 'CII D22B XSD', 'CrossIndustryInvoice_100pD22B.xsd'], (['xsd', 'CII D22B XSD', 'CrossIndustryInvoice_100pD22B.xsd'],
'CrossIndustryInvoice D22', ''), 'CrossIndustryInvoice D22', ''),
(['xsd', 'os-UBL-2.1', 'xsd/maindoc', 'UBL-Invoice-2.1.xsd'], (['xsd', 'os-UBL-2.1', 'xsd/maindoc', 'UBL-Invoice-2.1.xsd'],
@ -416,11 +416,13 @@ class Incoming(metaclass=PoolMeta):
'document_incoming_invoice_xml.msg_convert_error', 'document_incoming_invoice_xml.msg_convert_error',
msg='factur-x minimal not supported')) msg='factur-x minimal not supported'))
def _readxml_facturx_basic(self, xmltree):
""" read facturx - basic
"""
self._readxml_facturx_extended(xmltree)
def _readxml_facturx_extended(self, xmltree): def _readxml_facturx_extended(self, xmltree):
""" read factur-x extended """ read factur-x extended
Returns:
record: model account.invoice
""" """
Configuration = Pool().get('document.incoming.configuration') Configuration = Pool().get('document.incoming.configuration')
@ -501,7 +503,6 @@ class Incoming(metaclass=PoolMeta):
create_party=False) create_party=False)
if buyer_party: if buyer_party:
self.parsed_data['buyer_party'] = buyer_party self.parsed_data['buyer_party'] = buyer_party
print('\n# buyer_party-read:', buyer_party)
# invoice - lines # invoice - lines
# rsm:CrossIndustryInvoice/ # rsm:CrossIndustryInvoice/
@ -690,11 +691,9 @@ class Incoming(metaclass=PoolMeta):
# uom # uom
xml_uom = Uom(ModelData.get_id('product', 'uom_unit')) xml_uom = Uom(ModelData.get_id('product', 'uom_unit'))
for x_attr in line_data.get('attributes', []): unit_code = line_data.get('quantity', {}).pop('unit_code', None)
x_uom = x_attr.get('uom', None) if unit_code:
if not x_uom: units = Uom.search([('unece_code', '=', unit_code)])
continue
units = Uom.search([('symbol', '=', x_uom)])
if units: if units:
xml_uom = units[0] xml_uom = units[0]
@ -940,6 +939,8 @@ class Incoming(metaclass=PoolMeta):
('ram:ChargeFreeQuantity', 'chargefree', Decimal), ('ram:ChargeFreeQuantity', 'chargefree', Decimal),
('ram:PackageQuantity', 'package', Decimal), ('ram:PackageQuantity', 'package', Decimal),
])[0] ])[0]
result['quantity']['unit_code'] = self._readxml_getattrib(
xmldata, xpath_quantity + ['ram:BilledQuantity'], 'unitCode')
# notice ignored fields # notice ignored fields
for x in [ for x in [
'ShipToTradeParty', 'UltimateShipToTradeParty', 'ShipToTradeParty', 'UltimateShipToTradeParty',

192
tests/facturx-basic.xml Normal file
View file

@ -0,0 +1,192 @@
<?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:basic</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
<rsm:ExchangedDocument>
<ram:ID>RE2024.01234</ram:ID>
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime>
<udt:DateTimeString format="102">20240617</udt:DateTimeString>
</ram:IssueDateTime>
<ram:IncludedNote>
<ram:Content>Description of invoice</ram:Content>
</ram:IncludedNote>
<ram:IncludedNote>
<ram:Content>Some notes to the customer.</ram:Content>
</ram:IncludedNote>
<ram:IncludedNote>
<ram:Content>Goes to field comment.</ram:Content>
<ram:SubjectCode>42</ram:SubjectCode>
</ram:IncludedNote>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>1</ram:LineID>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:Name>Name of Product 1</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">1350.00</ram:ChargeAmount>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="KGM">1.0</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount currencyID="EUR">1350.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>2</ram:LineID>
<ram:IncludedNote>
<ram:Content>Description of Line 2</ram:Content>
</ram:IncludedNote>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:GlobalID>3</ram:GlobalID>
<ram:Name>Name of Product 2</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement>
<ram:GrossPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">950.00</ram:ChargeAmount>
<ram:BasisQuantity unitCode="C62">1.0</ram:BasisQuantity>
</ram:GrossPriceProductTradePrice>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">800.00</ram:ChargeAmount>
<ram:BasisQuantity unitCode="C62">1.0</ram:BasisQuantity>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="KGM">1.5</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount currencyID="EUR">1200.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>3</ram:LineID>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:Name>Name of Product 3</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">150.00</ram:ChargeAmount>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="MTR">2.0</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>7.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount currencyID="EUR">300.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:ApplicableHeaderTradeAgreement>
<ram:SellerTradeParty>
<ram:Name>Name of the Supplier</ram:Name>
<ram:SpecifiedLegalOrganization>
</ram:SpecifiedLegalOrganization>
<ram:PostalTradeAddress>
<ram:PostcodeCode>12345</ram:PostcodeCode>
<ram:LineOne>Street of Supplier No 1</ram:LineOne>
<ram:CityName>Berlin</ram:CityName>
<ram:CountryID>DE</ram:CountryID>
<ram:CountrySubDivisionName>Berlin</ram:CountrySubDivisionName>
</ram:PostalTradeAddress>
</ram:SellerTradeParty>
<ram:BuyerTradeParty>
<ram:Name>Our Company</ram:Name>
<ram:SpecifiedLegalOrganization>
</ram:SpecifiedLegalOrganization>
<ram:PostalTradeAddress>
<ram:PostcodeCode>23456</ram:PostcodeCode>
<ram:LineOne>Address Line 1</ram:LineOne>
<ram:LineTwo>Address Line 2</ram:LineTwo>
<ram:CityName>Potsdam</ram:CityName>
<ram:CountryID>DE</ram:CountryID>
<ram:CountrySubDivisionName>Brandenburg</ram:CountrySubDivisionName>
</ram:PostalTradeAddress>
</ram:BuyerTradeParty>
<ram:BuyerOrderReferencedDocument>
<ram:IssuerAssignedID/>
</ram:BuyerOrderReferencedDocument>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery>
</ram:ApplicableHeaderTradeDelivery>
<ram:ApplicableHeaderTradeSettlement>
<ram:PaymentReference>RE2024.01234</ram:PaymentReference>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
<ram:SpecifiedTradeSettlementPaymentMeans>
<ram:TypeCode>30</ram:TypeCode>
<ram:PayerPartyDebtorFinancialAccount>
<ram:IBANID>DE02300209000106531065</ram:IBANID>
</ram:PayerPartyDebtorFinancialAccount>
<ram:PayeePartyCreditorFinancialAccount>
<ram:IBANID>DE02300209000106531065</ram:IBANID>
</ram:PayeePartyCreditorFinancialAccount>
</ram:SpecifiedTradeSettlementPaymentMeans>
<ram:ApplicableTradeTax>
<ram:CalculatedAmount currencyID="EUR">484.5</ram:CalculatedAmount>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:BasisAmount>2550.0</ram:BasisAmount>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:ApplicableTradeTax>
<ram:CalculatedAmount currencyID="EUR">21.0</ram:CalculatedAmount>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:BasisAmount>300.0</ram:BasisAmount>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>7.00</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradePaymentTerms>
<ram:Description>Payment description</ram:Description>
<ram:DueDateDateTime>
<udt:DateTimeString format="102">20240701</udt:DateTimeString>
</ram:DueDateDateTime>
<ram:DirectDebitMandateID>mandat id</ram:DirectDebitMandateID>
</ram:SpecifiedTradePaymentTerms>
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
<ram:LineTotalAmount currencyID="EUR">1350.00</ram:LineTotalAmount>
<ram:TaxBasisTotalAmount currencyID="EUR">2850.00</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount currencyID="EUR">505.5</ram:TaxTotalAmount>
<ram:GrandTotalAmount currencyID="EUR">3355.50</ram:GrandTotalAmount>
<ram:DuePayableAmount currencyID="EUR">3355.50</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>

View file

@ -44,7 +44,7 @@
</ram:NetPriceProductTradePrice> </ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement> </ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery> <ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="C62">1.0</ram:BilledQuantity> <ram:BilledQuantity unitCode="KGM">1.0</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery> </ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement> <ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax> <ram:ApplicableTradeTax>
@ -117,8 +117,8 @@
</ram:NetPriceProductTradePrice> </ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement> </ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery> <ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="C62">1.5</ram:BilledQuantity> <ram:BilledQuantity unitCode="KGM">1.5</ram:BilledQuantity>
<ram:PackageQuantity unitCode="C62">1.5</ram:PackageQuantity> <ram:PackageQuantity unitCode="KGM">1.5</ram:PackageQuantity>
<ram:ActualDeliverySupplyChainEvent> <ram:ActualDeliverySupplyChainEvent>
<ram:OccurrenceDateTime> <ram:OccurrenceDateTime>
<udt:DateTimeString format="102">20240101</udt:DateTimeString> <udt:DateTimeString format="102">20240101</udt:DateTimeString>
@ -150,7 +150,7 @@
</ram:NetPriceProductTradePrice> </ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement> </ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery> <ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="C62">2.0</ram:BilledQuantity> <ram:BilledQuantity unitCode="MTR">2.0</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery> </ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement> <ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax> <ram:ApplicableTradeTax>

View file

@ -2,6 +2,7 @@
version=7.0.0 version=7.0.0
depends: depends:
document_incoming_invoice document_incoming_invoice
edocument_unece
xml: xml:
message.xml message.xml
configuration.xml configuration.xml