This question has been flagged
3 Replies
10014 Views

We have added some extra fields to the model sale.order.line. The values in these fields are needed for some automatic calculations we do in our modules. Our code looks similar to this (minimal example):

class sale_order_line(models.Model):
    _inherit = 'sale.order.line'
    myfield1 = fields.Char(string='License key', required=False)
    myfield2 = fields.Date(string='Start date', required=False)

However we need to show these values on the printed sale order as well. Therefore we tried to extend the sale order template to include these values right behind the name field. This looks like follows:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="my_report_saleorder_document" inherit_id="sale.report_saleorder_document">
            <xpath expr="//span[@t-field='l.name']" position="after">
                <span t-field="l.myfield1"/>
                <span t-field="l.myfield2"/>
            </xpath>
        </template>
    </data>
</openerp>

Unfortunately this extended template seems to have no effect. Odoo still uses the standard template and our custom fields are not shown. How can we tell Odoo to use the modified template?

 

EDIT: In the meantime we investigated a little more on the inner workings of sale order printing. It seems to be the case that Odoo has a template 'sale.report_saleorder' which in turn includes the template 'sale.report_saleorder_document':

<template id="report_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_saleorder_document')"/>
        </t>
    </t>
</template>

Our inherited version of the included template of course has a different ID 'mymodule.my_report_saleorder_document'. Maybe the problem is that the "master template" still includes the old version of the "inner template" instead of our new inherited version? But this would mean that there are two different types of "inheritance" in Odoo? Also the module sale_layout seems to do it the same way we do it? We are confused...

 

Avatar
Discard
Best Answer

I applied same logic but my field value is not displaying and parent view can not be located error occurs

Avatar
Discard
Best Answer
  1. Probably you need a record:

    'depends': [ 'sale' ],

in your module, in __openerp__.py

2. You change

myfield1 = fields.Char()
myfield2 = fields.Date()

by

myfield1 = fields.Char('FOO NAME')
myfield2 = fields.Date('FOO DATE NAME')

3. Probably the values in these fields are empty and therefore do not see them in report

Avatar
Discard
Author

We already have that in our module: "depends" : [ "base", "web", "account", "sale" ]

You have installed sale_layout module?

Author

No, we did not have sale_layout installed. We have catched up with that now, but apparently it does not make any difference whether it is installed or not.

Answer updated

Author

Okay, apparently we reduced the code too much to provide a minimal example. We have changed the example code above to be closer to our actual production code. We also added another thought above.

You code works without any problem in my test system.

You inherit sale.order in other custom module? Eg. if sale_layout is installed he would replace a part of the report template (this with your code).

Best Answer

Hello Peter Nietz,

Use below code may be help you.

<template id="my_report_saleorder_document" inherit_id="sale.report_saleorder_document">
                <xpath expr="//table[@class='table table-condensed']/thead/tr/th[1]" position="after">
                       <th>License key</th>
                       <th>Start date</th>
                </xpath>
                <xpath expr="//table[@class='table table-condensed']/tbody[@class='sale_tbody']/tr/td[1]" position="after">
                       <td><span t-field="l.myfield1"/></td>              
                       <td><span t-field="l.myfield2"/></td>
                </xpath>
        </template>

if you find this answer helpful, please give me a thumbs up vote

Regards,

Ankit H Gandhi

Avatar
Discard