Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
4846 Tampilan

I'm looking to generate a customized PDF report for invoices. I've successfully created a similar report for quotes 8and also for invoices within Flectra), but I'm facing some challenges when it comes to invoices.

Could someone kindly guide me on the step-by-step process of creating a custom Invoice PDF report using a module in Odoo 17? I'm particularly interested in understanding the necessary configurations, QWeb templates, and any other relevant details that would help me achieve this.

I want to understand what's the difference in concept bewteen sales order/quote and invoices.

Thnx!

Avatar
Buang
Penulis

In Flectra I had to add a template file with

<template id="report_aime_invoice" inherit_id="account.report_invoice_document">

where I then replaced the PAGE section with

<xpath expr="//div[hasclass('page')]" position="replace">

Jawaban Terbai

Hi 

You can create a report action for the account.move as the model and binding model, and then update the proper template with style and fields.

Create PDF Report in Odoo 17 

PDF Report


Regards

Avatar
Buang
Penulis

Thank you for your answer, but it just explains how to add a custom report, ie. for products. In my case I want to override the invoice report and for that I need direct instructions about how to register the record (from my understanding), like
<record id="custom_invoice_layout" model="ir.actions.report">...
or how to register my qweb template file
<template id="invoice_layout_custom">...

Penulis

from your suggestion it would be something like

<record id="custom_invoice_layout" model="ir.actions.report">
<field name="name">Custom Invoice Layout</field>
<field name="model">account.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">custom_odoo_templates.invoice_layout_custom</field>
<field name="report_file">custom_odoo_templates.invoice_layout_custom</field>
<field name="report_file">account.report_invoice</field>
<!-- <field name="print_report_name">'Invoice_%s' % (object.name)</field> -->
<field name="binding_model_id" ref="account.model_account_move"/>
<field name="binding_type">report</field>
</record>

Penulis

if I use that, I get the error
odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
KeyError: 'doc'
Template: custom_odoo_templates.quote_layout_custom

so for me it looks like the invoice report is being rendered using the (overridden) quote (sale.order) template.

Penulis

I now deleted the <record> and just work with
<template id="invoice_layout_custom" inherit_id="account.report_invoice_with_payments">
I also added t-if="doc" everywhere in the <template id="quote_layout_custom"> tags and it now looks like the rendering reaches the default invoice templat as I now get the KeyError
KeyError: 'o'
Template: account.report_invoice_with_payments
Questions arise like: Why does it renders the sale order template before? And why is there no o-Object any more?

If you need to create a new invoice report try this <record id="action_invoice_report" model="ir.actions.report">
<field name="name">Invoice Report</field>
<field name="model">account.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">invoice_report.report_invoice_template</field>
<field name="report_file">invoice_report.report_invoice_template</field>
<field name="print_report_name">'Report - %s' % (object.name)</field>
<field name="binding_model_id" ref="account.model_account_move"/>
<field name="binding_type">report</field>
</record>

otherwise, if you need to inherit the default invoice report and make changes use inherit_id and call this template account.report_invoice_document
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
inside you can add the updates
</template>

Penulis

trying to inherit the default invoice report with

<record id="custom_invoice_layout" model="ir.actions.report">
<field name="name">Custom Invoice Layout</field>
<field name="model">account.move</field>
<field name="inherit_id">custom_odoo_templates.invoice_layout_custom</field>
</record>

I get the error

ValueError: Invalid field 'inherit_id' on model 'ir.actions.report'

inherit_id is in the report template, not in ir.actions_report model

Post Terkait Replies Tampilan Aktivitas
2
Mar 15
4069
0
Jan 25
1024
4
Jul 23
7216
0
Jun 23
1669
1
Mar 25
2340