Skip to Content
मेन्यू
This question has been flagged
3 Replies
457 Views

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?

Avatar
Discard
Author

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

Best Answer

You're interested in investigating the module account_edi_ubl_cii from core: https://github.com/odoo/odoo/tree/17.0/addons/account_edi_ubl_cii

More so, probably in the function _export_invoice_vals() of account.edi.xml.ubl_20 at https://github.com/odoo/odoo/blob/17.0/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py#L521

In here, further down the line a dictionary is defined that holds the data that then is used in the actual template: https://github.com/odoo/odoo/blob/17.0/addons/account_edi_ubl_cii/data/ubl_20_templates.xml


Avatar
Discard
Best Answer

Life saver!!!

Thanks a trillion!

Avatar
Discard
Author Best Answer

Hi,

after a lot of try and error and the help of AI we got it to work.

our account_edi_xml_ubl_bis3_extension.py

from odoo import models


class AccountEdiXmlUBLBIS3Extension(models.AbstractModel):

    _inherit = "account.edi.xml.ubl_bis3"


    def _export_invoice_vals(self, invoice):

        vals = super()._export_invoice_vals(invoice)


        # Inject custom fields into the nested 'vals' dictionary

        vals['vals']['accounting_cost'] = invoice.l10n_lu_mddi_engagement_ref

        vals['vals']['note_vals'] = [{'note': invoice.l10n_lu_mddi_general_info}]

        vals['vals']['order_reference'] = invoice.l10n_lu_mddi_order_ref or '-'

        vals['vals']['buyer_reference'] = invoice.l10n_lu_mddi_order_ref or '-'


        return vals



the views/account_edi_templates.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template id="ubl_21_invoice_type_inherit_l10n_lu_mddi" inherit_id="account_edi_ubl_cii.ubl_21_InvoiceType">
            <xpath expr="//*[local-name()='BuyerReference']" position="before">
                <t xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
                    <cbc:AccountingCost t-if="vals.get('accounting_cost')">
                        <t t-esc="vals.get('accounting_cost')"/>
                    </cbc:AccountingCost>
                </t>
            </xpath>
        </template>
    </data>
</odoo>

the views/account_move_view.xml

<?xml version='1.0' encoding='utf-8'?>
<odoo>
    <data>
        <record id="view_move_form_l10n_lu_mddi" model="ir.ui.view">
            <field name="name">account.move.form.l10n_lu_mddi</field>
            <field name="model">account.move</field>
            <field name="inherit_id" ref="account.view_move_form"/>
            <field name="arch" type="xml">
                <xpath expr="//notebook" position="inside">
                    <page string="MDDI" name="mddi">
                        <group>
                            <field name="l10n_lu_mddi_engagement_ref"/>
                            <field name="l10n_lu_mddi_general_info"/>
                            <field name="l10n_lu_mddi_order_ref"/>
                        </group>
                    </page>
                </xpath>
            </field>
        </record>
    </data>
</odoo>


You need to adapt the script to Your needs. 
I had to give the field 'l10n_lu_mddi_order_ref' from the relation account_move a default value '_'. Otherwise Odoo complains that this field cannot be empty.
Good luck 

Avatar
Discard