details: https://code.tryton.org/tryton/commit/9b78bdacf182
branch: default
user: Cédric Krier <[email protected]>
date: Mon Aug 31 12:06:40 2026 +0200
description:
Set the company on the invoice before assigning the party
The party of the invoice must have the invoice's company in the context
to
correctly set the account when calling on_change_party.
Closes #15049
diffstat:
modules/edocument_ubl/edocument.py | 47
++++++---
modules/edocument_ubl/tests/scenario_ubl_2_credit_note_parse.rst | 2 +-
modules/edocument_ubl/tests/scenario_ubl_2_invoice_parse.rst | 2 +-
3 files changed, 31 insertions(+), 20 deletions(-)
diffs (110 lines):
diff -r 06643f7ecb59 -r 9b78bdacf182 modules/edocument_ubl/edocument.py
--- a/modules/edocument_ubl/edocument.py Thu Sep 03 00:02:28 2026 +0200
+++ b/modules/edocument_ubl/edocument.py Mon Aug 31 12:06:40 2026 +0200
@@ -321,11 +321,24 @@
type_code=type_code))
invoice = Invoice(type='in')
+
+ if (customer_party := root.find('./{*}AccountingCustomerParty')
+ ) is not None:
+ invoice.company = cls._parse_2_company(customer_party)
+ else:
+ invoice.company = Invoice.default_company()
+ if not invoice.company:
+ raise InvoiceError(gettext(
+ 'edocument_ubl.msg_company_not_found',
+ company=etree.tostring(
+ customer_party, pretty_print=True).decode()
+ if customer_party else ''))
+
invoice.reference = root.findtext('./{*}ID')
invoice.invoice_date = dt.date.fromisoformat(
root.findtext('./{*}IssueDate'))
invoice.party = cls._parse_2_supplier(
- root.find('./{*}AccountingSupplierParty'), create=True)
+ root.find('./{*}AccountingSupplierParty'), create=True).id
payees = [invoice.party]
invoice.set_journal()
invoice.on_change_party()
@@ -341,17 +354,6 @@
supplier = cls._parse_2_supplier(seller)
else:
supplier = invoice.party
- if (customer_party := root.find('./{*}AccountingCustomerParty')
- ) is not None:
- invoice.company = cls._parse_2_company(customer_party)
- else:
- invoice.company = Invoice.default_company()
- if not invoice.company:
- raise InvoiceError(gettext(
- 'edocument_ubl.msg_company_not_found',
- company=etree.tostring(
- customer_party, pretty_print=True).decode()
- if customer_party else ''))
if (payee_party := root.find('./{*}PayeeParty')) is not None:
party = cls._parse_2_party(payee_party)
@@ -659,11 +661,24 @@
type_code=type_code))
invoice = Invoice(type='in')
+
+ if (customer_party := root.find('./{*}AccountingCustomerParty')
+ ) is not None:
+ invoice.company = cls._parse_2_company(customer_party)
+ else:
+ invoice.company = Invoice.default_company()
+ if not invoice.company:
+ raise InvoiceError(gettext(
+ 'edocument_ubl.msg_company_not_found',
+ company=etree.tostring(
+ customer_party, pretty_print=True).decode()
+ if customer_party else ''))
+
invoice.reference = root.findtext('./{*}ID')
invoice.invoice_date = dt.date.fromisoformat(
root.findtext('./{*}IssueDate'))
invoice.party = cls._parse_2_supplier(
- root.find('./{*}AccountingSupplierParty'), create=True)
+ root.find('./{*}AccountingSupplierParty'), create=True).id
payees = [invoice.party]
invoice.set_journal()
invoice.on_change_party()
@@ -671,11 +686,7 @@
supplier = cls._parse_2_supplier(seller)
else:
supplier = invoice.party
- if (customer_party := root.find('./{*}AccountingCustomerParty')
- ) is not None:
- invoice.company = cls._parse_2_company(customer_party)
- else:
- invoice.company = Invoice.default_company()
+
if (payee_party := root.find('./{*}PayeeParty')) is not None:
party = cls._parse_2_party(payee_party)
if not party:
diff -r 06643f7ecb59 -r 9b78bdacf182
modules/edocument_ubl/tests/scenario_ubl_2_credit_note_parse.rst
--- a/modules/edocument_ubl/tests/scenario_ubl_2_credit_note_parse.rst Thu Sep
03 00:02:28 2026 +0200
+++ b/modules/edocument_ubl/tests/scenario_ubl_2_credit_note_parse.rst Mon Aug
31 12:06:40 2026 +0200
@@ -62,7 +62,7 @@
>>> with file_open(
... 'edocument_ubl/tests/UBL-CreditNote-2.1-Example.xml',
... mode='rb') as fp:
- ... invoice_id = EInvoice.parse(fp.read(), config.context)
+ ... invoice_id = EInvoice.parse(fp.read(), {**config.context,
'company': None})
>>> invoice = Invoice(invoice_id)
diff -r 06643f7ecb59 -r 9b78bdacf182
modules/edocument_ubl/tests/scenario_ubl_2_invoice_parse.rst
--- a/modules/edocument_ubl/tests/scenario_ubl_2_invoice_parse.rst Thu Sep
03 00:02:28 2026 +0200
+++ b/modules/edocument_ubl/tests/scenario_ubl_2_invoice_parse.rst Mon Aug
31 12:06:40 2026 +0200
@@ -62,7 +62,7 @@
>>> with file_open(
... 'edocument_ubl/tests/UBL-Invoice-2.1-Example.xml',
... mode='rb') as fp:
- ... invoice_id = EInvoice.parse(fp.read(), config.context)
+ ... invoice_id = EInvoice.parse(fp.read(), {**config.context,
'company': None})
>>> invoice = Invoice(invoice_id)