[FIX] account_edi_ubl_cii: ensure key existence
**Current behavior:**
Creating a fixed tax with the edi formats ubl_bis3 and nlcius_1
then creating an invoice with this tax tied to a product will
cause a traceback when a user tries to confirm the invoice.
**Expected behavior:**
The invoice will post as any other might.
**Steps to reproduce:**
1. Create a NL company with l10n_nl_edi accounting
2. Create a tax with the following field values:
*tax computation: fixed*
*affect base of subsequent taxes: True*
*base affected by previous taxes: True*
3. In the customer invoices journal for the created company,
go to the 'Advanced Settings' notebook tab and enable the
NLCIUS and Peppol options under 'Electronic Invoicing'
4. Create a new invoice with some product and attach the newly
created tax to it, then try to confirm the invoice to see
the traceback
**Cause of the issue:**
The edi format tags invoke different instances of the
get_invoice_line_allowance_vals_list() method. This method
returns a dict list where the dicts only sometimes contain the
key 'allowance_charge_reason_code'. A subsequent expression
expects this key in the dict which can cause a KeyError.
**Fix:**
Check instead for a 'charge_indicator' key, which is present in
both the ubl_bis3 and nlcius_1 val dicts, allowing the correct
total to be summed and reflected in the EDI document output.
opw-3680527
closes odoo/odoo#157495
X-original-commit: 06a3027ca9f421ccc0081e2c8a5ff538175ef334
Signed-off-by: Laurent Smet (las) <las@odoo.com>
Signed-off-by: Vincent Ethan <etvi@odoo.com>
This commit is contained in:
committed by
Laurent Smet
parent
056e5b3c1c
commit
849edf60df
@@ -362,7 +362,7 @@ class AccountEdiXmlUBL20(models.AbstractModel):
|
||||
total_fixed_tax_amount = sum(
|
||||
vals['amount']
|
||||
for vals in allowance_charge_vals_list
|
||||
if vals['allowance_charge_reason_code'] == 'AEO'
|
||||
if vals.get('charge_indicator') == 'true'
|
||||
)
|
||||
return {
|
||||
'currency': line.currency_id,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo.addons.l10n_account_edi_ubl_cii_tests.tests.common import TestUBLCommon
|
||||
from odoo.tests import tagged
|
||||
from odoo import Command
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install')
|
||||
@@ -68,6 +71,16 @@ class TestUBLNL(TestUBLCommon):
|
||||
'amount': 7,
|
||||
'type_tax_use': 'purchase',
|
||||
'country_id': cls.env.ref('base.nl').id,
|
||||
'sequence': 2,
|
||||
})
|
||||
|
||||
cls.tax_10_fixed = cls.env['account.tax'].create({
|
||||
'name': 'Test Tax',
|
||||
'amount_type': 'fixed',
|
||||
'include_base_amount': True,
|
||||
'country_id': cls.env.ref('base.nl').id,
|
||||
'amount': 10.0,
|
||||
'sequence': 1,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@@ -201,6 +214,24 @@ class TestUBLNL(TestUBLCommon):
|
||||
self.assertEqual(attachment.name[-10:], "nlcius.xml")
|
||||
self._assert_imported_invoice_from_etree(refund, attachment)
|
||||
|
||||
def test_export_fixed_tax(self):
|
||||
"""
|
||||
Ensure that an invoice containing a product with a fixed tax posted to a journal with the peppol and nlcius edi
|
||||
tags generates edi documents with accurate LineExtensionAmount values
|
||||
"""
|
||||
invoice = self._generate_move(
|
||||
self.partner_1, self.partner_2,
|
||||
move_type='out_invoice',
|
||||
invoice_line_ids=[{
|
||||
'name': 'product costing 50.0',
|
||||
'quantity': 1,
|
||||
'price_unit': 50.0,
|
||||
'tax_ids': [Command.set([self.tax_10_fixed.id, self.tax_7_purchase.id])]
|
||||
}]
|
||||
)
|
||||
amount = etree.fromstring(invoice.ubl_cii_xml_id.raw).find('.//{*}LegalMonetaryTotal/{*}LineExtensionAmount').text
|
||||
self.assertEqual(amount, '60.00')
|
||||
|
||||
####################################################
|
||||
# Test import
|
||||
####################################################
|
||||
|
||||
Reference in New Issue
Block a user