This question has been flagged
2 Replies
8142 Views

I have read odoo official documentation on Qweb Report but still not clear enough if i want to add or modify the layout of qweb pdf report by through a custom module, especially which file to place the mentioned code in the documentation, and to which folder i should place the file? I search the web a lot for this but almost all of them just mimic the official doc without adding this lack of information.

to be more tangible i would like to have an example:

said i want to add new sales order pdf report for sales order or quotation, name it  as  "Custom Quotation/Order" this new report :

1.change the layout above the table (positioning)

2.and in below of the table, add "total amount before discount", "total amount of discount" add "amount to text" as well other text div.

I want to do it by creating a custom modul named  "sale_order_custom", so from standard module structure and from learning a sale module structure i create module structure :

addons/sale_custom_report/

|-- __init__.py

|-- __openerp__.py

|-- sale_custom_report_report.xml

|-- models/

| |-- __init__.py

| `-- sale_order_custom.py

|-- report/

| |-- __init__.py

| |-- ??

|-- views/

| |-- report_custom_saleorder.xml

in file    sale_order_custom_report.xml     i put the following code:

    <?xml version="1.0" encoding="utf-8"?>

    <openerp>

         <data>

                <report

                    id="report_custom_sale_order"

                     string="Custom Quotation / Order"

                     model="sale.order"

                     report_type="qweb-pdf"

                     file="sale_order_custom.report_custom_saleorder"

                     name="sale_order_custom.report_custom_saleorder"

                />

            </data>

      </openerp>

in file    report_custom_salorder.xml     i put the following code:

<?xml version="1.0"?>

<openerp>

    <data>

        <template id="report_custom_saleorder">

            <t t-call="report.html_container">

            <t t-foreach="doc_ids" t-as="doc_id">

            <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_custom_saleorder_document')"/>

            </t>

        </t>

</template>

    <template id="sale.report_custom_saleorder_document">

        <t t-call="report.external_layout">

            <div class="page">

                <!--Report Architecture -->

                <div class="row">

                    ......

                    ......

                </div>

         </div>

      </t>

    </template>

   </data>

</openerp>

in  /models/ sale_order_custom.py    i put the following code:

# -*- coding: utf-8 -*-

from openerp import models, fields, api

from openerp.tools import amount_to_text

class sale_order(models.Model):

    _inherit = 'sale.order'

@api.multi

    def amount_to_text(self,amount,currency='Idr'):

    return amount_to_text(amount,currency)

But i am not sure whether it correct to put it under models folder, and what to put in /report/ folder ?

in  __openerp__.py  i put below code:

# -*- coding: utf-8 -*-

{

'name': "custom_sale_order",

'summary': """

Short (1 phrase/line) summary of the module's purpose, used as

subtitle on modules listing or apps.openerp.com""",

'description': """

Long description of module's purpose

""",

'author': "Your Company",

'website': "http://www.yourcompany.com",

'category': 'Uncategorized',

'version': '0.1',

'depends': ['base','sale'],

'data': [

'models/sale_custom_report.py',

'views/report_custom_saleorder.xml',

'report/<?????>',

'sale_order_custom_report.xml',

],

}

Please somebody help to get all file correctly coded,  i believe this will help others people learning to build qweb report from module correctly and respecting odoo module structure.

Avatar
Discard
Author Best Answer

Hi Daniel Rodriguez,

Thank you for your response and guidance and help, it answer about structure, i will try it soon.

There is a function i need to call in the custom_salorder_report (i believe it is not available to call in current existing report of odoo), that is  amount_to_text_en.py function which will display amount total in text. The file is already available in openerp/tools/ folder.

the other, i need to calculate  and display the total amount before discount and total amount of discount if there is discount in order lines ( current standard report display only total of discounted amount before tax, total text, and total amount), i am not sure where to define this function correctly (inheriting sale.order model and add compute fields) or defining a function in report parser.

if i not wrong or misunderstand the documentation, we can use custom report. i quoted the documentation below :

Quote

Custom Reports

The report model has a default get_html function that looks for a model named report.module.report_name. If it exists, it will use it to call the QWeb engine; otherwise a generic function will be used. If you wish to customize your reports by including more things in the template (like records of others models, for example), you can define this model, overwrite the function render_html and pass objects in the docargs dictionary:

from openerp import api, models

class ParticularReport(models.AbstractModel):
    _name = 'report.module.report_name'
    @api.multi
    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name('module.report_name')
        docargs = {
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        return report_obj.render('module.report_name', docargs)

Unquote

Please share and help how to do it in each  method? and which method is preferable / better?

 

Avatar
Discard
Best Answer

Hi, I think yout structure is not correctly.

The correctly structure must be:

1.__init__.py

1.__openerp__.py

1.reports

2.sale_custom_report_report.xml

With this should be enough.

In __openerp__.py, you can add to data attribute:

'data': [

'reports/sale_custom_report_report.xml',

]

in sale_custom_report_report.xml at the bottom os this file you can add this:

<template id="report_custom_saleorder">

<t t-call="report.html_container">

<t t-foreach="doc_ids" t-as="doc_id">

<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_custom_saleorder_document')"/>

</t>

</t>

</template>

<report

id="report_custom_sale_order"

string="Custom Quotation / Order"

model="sale.order"

report_type="qweb-pdf"

file="sale_order_custom.report_custom_saleorder"

name="sale_order_custom.report_custom_saleorder"

attachment="(object.state in ('open','paid')) and ('Example_report_'+(object.number or '').replace('/','')+'.pdf')"

/>


With this could be enought, but if you have any problem tell me and I try yo help you

Avatar
Discard