Hello everyone,
I’m working on Odoo 18 (enterprise) and I customized the invoice creation logic in sale.order to insert section lines grouping invoice lines by picking (delivery order).
The goal is:
When a customer invoice is created from multiple deliveries,
For each delivery order, insert a section line containing:
"Order No. X – Delivery Note No. Y dated Z"
Then insert all invoice lines related to that picking under that section.
The section lines should appear in the invoice form view (as display_type='line_section'), and also in accounting entries. Here is the code that I did:
def _create_invoices(self, grouped=False, final=False):
invoices = super()._create_invoices(grouped=grouped, final=final)
for inv in invoices:
lines_by_picking = {}
for line in inv.invoice_line_ids:
line_vals = line.copy_data()[0]
picking = line.sale_line_ids.mapped("move_ids").mapped("picking_id")
if picking:
picking = picking[0]
lines_by_picking.setdefault(picking, []).append(line_vals)
inv.write({"invoice_line_ids": [(5, 0, 0)]})
new_lines = []
for picking, line_vals_list in lines_by_picking.items():
section_name = _(
"Order No. %s - Delivery Note No. %s dated %s"
) % (
picking.sale_id.name,
picking.name,
picking.delivery_date.date().strftime('%d/%m/%Y') if picking.delivery_date else "",
)
print(section_name)
new_lines.append((
0, 0, {
"display_type": "line_section",
"name": section_name
}
))
for vals in line_vals_list:
vals.pop("sequence", None)
new_lines.append((0, 0, vals))
inv.write({"invoice_line_ids": new_lines})
return invoicesWhat works:
The section name is correctly generated (I printed it in the logs).
In the accounting entries, the section line does exist, with the correct name and display_type='line_section'.
When generating an invoice from a single delivery, it sometimes appears correctly.
The problem:
The section line does NOT appear in the invoice form view (account.move → tab "Invoice Lines") even though it:
exists in the database
has display_type='line_section'
appears under "Accounting entries" with the correct name
In the form view, the widget used is:
<field name="name" widget="section_and_note_text" optional="show"/>
But the section text stays blank / invisible.
What I suspect:
I think the issue might be related to:
The way invoice lines are recreated ((5,0,0) then reinserting everything)
The widget section_and_note_text not refreshing correctly
The fact that invoice lines created programmatically may miss some required fields or context
A missing value that the section widget expects, but I’m unsure which one
Expected behavior:
The section line should display normally in the invoice UI, as any manual section line does.
Questions:
Is there something missing when creating a section invoice line programmatically?
Does the section widget require a specific field value other than display_type='line_section' and name?
Is recreating all invoice lines ((5,0,0)) the wrong approach in this case?
Is there a better way to group invoice lines by picking when the invoice is generated?
Any help or insight on why the section line does not appear in the invoice form (while it exists in accounting entries) would be greatly appreciated.
Thanks in advance!
Hello,
This app is not fulfil the purpose you shared but it helps to understand the section grouping..
https://apps.odoo.com/apps/modules/18.0/cst_sale_orderline_grouping
Hope it is help.
Thanks