Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How can I add custom fields to the sale order print template?

Peter Nietz
on 1/19/15, 8:53 AM 1,566 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"?>
        <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"/>

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')"/>

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...



Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
| 5 3 6
Gandhinagar, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 1/21/15, 5:13 AM

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 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>

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


Ankit H Gandhi



| 5 4 7
Lodz, Poland

On 1/19/15, 1:01 PM
  1. Probably you need a record:

    'depends': [ 'sale' ],

in your module, in __openerp__.py

2. You change

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


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

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

Peter Nietz
on 1/20/15, 2:54 AM

You have installed sale_layout module?

on 1/20/15, 5:05 AM

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.

Peter Nietz
on 1/20/15, 9:40 AM

Answer updated

on 1/20/15, 9:48 AM

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.

Peter Nietz
on 1/21/15, 3:45 AM

You code works without any problem in my test system.

on 1/21/15, 3:53 AM

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).

on 1/21/15, 4:01 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 1/19/15, 8:53 AM
Seen: 1566 times
Last updated: 3/16/15, 8:10 AM