[FIX] account_edi_ubl_cii: import with missing unit prices

Sometimes, the net price and the gross price are not present in the
invoice line, but the line subtotal is (for instance, with some xml from
Billit). In this case, it is still possible to infer the Odoo unit price
and parse the xml correctly.

opw-3384704

closes odoo/odoo#128338

X-original-commit: a8c82e6e4e47d951601364f1714a4150fa63f62a
Signed-off-by: Laurent Smet (las) <las@odoo.com>
Signed-off-by: Julien Van Roy (juvr) <juvr@odoo.com>
This commit is contained in:
Julien Van Roy
2023-07-13 08:28:22 +02:00
parent 11eebe12bf
commit 0bb419cf11
4 changed files with 185 additions and 4 deletions
@@ -686,7 +686,8 @@ msgstr ""
#. odoo-python
#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0
#, python-format
msgid "No gross price nor net price found for line in xml"
msgid ""
"No gross price, net price nor line subtotal amount found for line in xml"
msgstr ""
#. module: account_edi_ubl_cii
@@ -621,8 +621,10 @@ class AccountEdiCommon(models.AbstractModel):
price_unit = gross_price_unit / basis_qty
elif net_price_unit is not None:
price_unit = (net_price_unit + rebate) / basis_qty
elif price_subtotal is not None:
price_unit = (price_subtotal + allow_charge_amount) / billed_qty
else:
raise UserError(_("No gross price nor net price found for line in xml"))
raise UserError(_("No gross price, net price nor line subtotal amount found for line in xml"))
# discount
discount = 0
@@ -0,0 +1,168 @@
<?xml version='1.0' encoding='UTF-8'?>
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0</cbc:CustomizationID>
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID>INV/2017/01/0002</cbc:ID>
<cbc:IssueDate>2017-01-01</cbc:IssueDate>
<cbc:DueDate>2017-02-28</cbc:DueDate>
<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
<cbc:Note>test narration</cbc:Note>
<cbc:DocumentCurrencyCode>USD</cbc:DocumentCurrencyCode>
<cbc:BuyerReference>ref_partner_2</cbc:BuyerReference>
<cac:OrderReference>
<cbc:ID>ref_move</cbc:ID>
</cac:OrderReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="9925">BE0202239951</cbc:EndpointID>
<cac:PartyName>
<cbc:Name>partner_1</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Chaussée de Namur 40</cbc:StreetName>
<cbc:CityName>Ramillies</cbc:CityName>
<cbc:PostalZone>1367</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>BE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>BE0202239951</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>partner_1</cbc:RegistrationName>
<cbc:CompanyID>BE0202239951</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:Name>partner_1</cbc:Name>
</cac:Contact>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cbc:EndpointID schemeID="9925">BE0477472701</cbc:EndpointID>
<cac:PartyName>
<cbc:Name>partner_2</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Rue des Bourlottes 9</cbc:StreetName>
<cbc:CityName>Ramillies</cbc:CityName>
<cbc:PostalZone>1367</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>BE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>BE0477472701</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>partner_2</cbc:RegistrationName>
<cbc:CompanyID>BE0477472701</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:Name>partner_2</cbc:Name>
</cac:Contact>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:PaymentMeans>
<cbc:PaymentMeansCode name="credit transfer">30</cbc:PaymentMeansCode>
<cbc:PaymentID>+++000/0000/26268+++</cbc:PaymentID>
<cac:PayeeFinancialAccount>
<cbc:ID>BE15001559627230</cbc:ID>
</cac:PayeeFinancialAccount>
</cac:PaymentMeans>
<cac:PaymentTerms>
<cbc:Note>30% Advance End of Following Month</cbc:Note>
</cac:PaymentTerms>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="USD">482.22</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">1782.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">374.22</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>21.0</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">900.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">108.00</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>12.0</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="USD">2682.00</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID="USD">2682.00</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID="USD">3164.22</cbc:TaxInclusiveAmount>
<cbc:PrepaidAmount currencyID="USD">0.00</cbc:PrepaidAmount>
<cbc:PayableAmount currencyID="USD">3164.22</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>901</cbc:ID>
<cbc:InvoicedQuantity unitCode="DZN">2.0</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="USD">1782.00</cbc:LineExtensionAmount>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:AllowanceChargeReasonCode>95</cbc:AllowanceChargeReasonCode>
<cbc:Amount currencyID="USD">198.00</cbc:Amount>
</cac:AllowanceCharge>
<cac:Item>
<cbc:Description>product_a</cbc:Description>
<cbc:Name>product_a</cbc:Name>
<cac:ClassifiedTaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>21.0</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cbc:ID>902</cbc:ID>
<cbc:InvoicedQuantity unitCode="C62">10.0</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="USD">1000.00</cbc:LineExtensionAmount>
<cac:Item>
<cbc:Description>product_b</cbc:Description>
<cbc:Name>product_b</cbc:Name>
<cac:ClassifiedTaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>12.0</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cbc:ID>903</cbc:ID>
<cbc:InvoicedQuantity unitCode="C62">-1.0</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="USD">-100.00</cbc:LineExtensionAmount>
<cac:Item>
<cbc:Description>product_b</cbc:Description>
<cbc:Name>product_b</cbc:Name>
<cac:ClassifiedTaxCategory>
<cbc:ID>S</cbc:ID>
<cbc:Percent>12.0</cbc:Percent>
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
</cac:InvoiceLine>
</Invoice>
@@ -442,8 +442,18 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon):
self.assertTrue(created_bill)
def test_import_invoice_xml(self):
self._assert_imported_invoice_from_file(subfolder='tests/test_files/from_odoo', filename='bis3_out_invoice.xml',
amount_total=3164.22, amount_tax=482.22, list_line_subtotals=[1782, 1000, -100], currency_id=self.currency_data['currency'].id)
kwargs = {
'subfolder': 'tests/test_files/from_odoo',
'amount_total': 3164.22,
'amount_tax': 482.22,
'list_line_subtotals': [1782, 1000, -100],
'list_line_price_unit': [990, 100, 100],
'list_line_discount': [10, 0, 0],
'currency_id': self.currency_data['currency'].id,
}
self._assert_imported_invoice_from_file(filename='bis3_out_invoice.xml', **kwargs)
# same as the file above, but the <cac:Price> are missing in the invoice lines
self._assert_imported_invoice_from_file(filename='bis3_out_invoice_no_prices.xml', **kwargs)
def test_import_invoice_xml_open_peppol_examples(self):
# Source: https://github.com/OpenPEPPOL/peppol-bis-invoice-3/tree/master/rules/examples