We want to inject the following 3 fields in the generated ..ubl_bis3.xml files in Odoo 17 Community edition.
<cbc:ID> (bt13 = identifier of a referenced purchase order, issued by the Buyer)
<cbc:AccountingCost> (bt19 = A textual value that specifies where to book the relevant data into the Buyer's financial accounts.)
<cbc:Note> (bt22 = textual note that gives unstructured information that is relevant to the Invoice as a whole.)
The data of the 3 xml-nodes is present in the database model account_move as the fields
<cbc:ID> = buyer_reference
<cbc:AccountingCost> = accounting_cost
<cbc:Note> = invoice_note
How can we inject these 3 xml-nodes in the generated ..ubl_bis3.xml, that is send via PEPPOL? We would like to write code in a custom module to archieve this.
--- Update
Thx Christoph for pointing me in the right direction.
In my module I added to the class
class AccountMove(models.Model):
_inherit = 'account.move'
def _export_invoice_vals(self, invoice):
vals = super()._export_invoice_vals(invoice)
vals['vals'].update({
'accounting_cost': invoice.accounting_cost,
'invoice_note': invoice.invoice_note,
'contract_document_reference_vals': [{
'id': invoice.buyers_reference if invoice.buyers_reference else 'N/A',
# 'issue_date': invoice.contract_id.date_start if invoice.contract_id else None,
}],
})
return vals
In the in ubl_20_template.xml
I added two lines in the section
<template id="ubl_20_CommonType">
(...)
<cbc:AccountingCost t-out="vals.get('accounting_cost')" />
<cbc:Note t-out="vals.get('invoice_note')"/>
But stil I don't get the desired result?
I've followed your instructions, but without getting the desired result. We are using the Community edition, and it seems as if the creation of the ubl_bis3.xml slightly different.
In the whole files in the /addons directory in odoo I cannot locate the method '_export_as_ubl_invoice' that You mention. Therefore the proposed code does not give the desired result.
This is, because it's just AI generated without any proof-reading whatsoever...
_export_invoice_vals() is nowhere defined in account.move but, for example, account.edi.xml.ubl_20, your inherit needs to reflect that. Also, I don't know what you template modification looks with just that snippet.
Hi there,
Did you manage to sort this out? I have been facing the exact same issue and still cannot get the fields inserted in the final xml
I am probably using the wrong hook in the template.xml, or odoo redoes the xml always, not sure
Cheers
Any help will be greatly appreciated