Odoo Help

Welcome!

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.

0

How to add a specific column on sale.order table?

By
wizardz
on 9/25/15, 5:58 AM 888 views

Hello,

I want to make a new column after product_id here in sale.order (see screenshot)

http://diezcode.ch/spalte-einsetzten.PNG


I have made a module with a new field(char) for product. But I want it in the column in sale.order , 



Ok I found a way like this:

With this way you can add a column in the sale.order.line and then you can edit it with no problems:

 <record model="ir.ui.view" id="sale_margin_percent_1"> 
    <field name="name">sale.margin.percent.view.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
         <xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="before">
            <field name="new_field"/>
        </xpath>
     </field> </record>
<record model="ir.ui.view" id="sale_margin_percent_2">
    <field name="name">sale.order.line.tree.margin.view.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="before">
            <field name="new_field"/>
        </xpath>
    </field>
</record> 
1

Yenthe

--Yenthe--
6706
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 9/25/15, 6:15 AM

Hi Stephane,

You should inherit that view and use an xpath to add the custom field in it. An example that adds a field:

    <record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//tree[@string='Sales Order Lines']/field[@name='name']" position="after">
<field name="yourCustomField"/>
</xpath>
</field>
</record>

Yenthe

and how I make it when the field comes from product.product ? It says to me that the field does not exist. I wanna put the field from product to sale.order lines.

wizardz
on 9/25/15, 7:14 AM

I have also same problem . See https://www.odoo.com/fr_FR/forum/help-1/question/how-to-add-a-new-field-in-a-class-from-another-which-is-already-inherited-91356

Maurice Agée
on 9/25/15, 8:20 AM
1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/8/15, 7:24 AM

Hi,

So you have defined the new Char field in product.product right?

Then one option is to define a new related field in sale.order.line. And call that related field, like Yenthe described above.

Hope you are working v8.

For eg:

in your py file:

class sale_order_line(models.Model):

_inherit = 'sale.order.line'

new_field = fields.Char(related='product_id.your_field', string='New Field')

in your xml file, like Yenthe told:

<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//tree[@string='Sales Order Lines']/field[@name='name']" position="after">
<field name="new_field"/>
</xpath>
</field>
</record>

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

1 follower(s)

Stats

Asked: 9/25/15, 5:58 AM
Seen: 888 times
Last updated: 10/8/15, 9:04 AM