Odoo Help

0

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

By
wizardz
on 9/25/15, 5:58 AM 2,313 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--
9615
| 8 8 8
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--

4253
| 5 4 7
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>
0
Sehrish
On 2/13/18, 4:16 AM

In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.

The purpose of inheritance or why we need inheritance is given below:

  1. To change attributes of some fields which exists on existing/custom model (e.g. making fields readonly,invisible)

  2. To add/modify/delete old or new fields in existing/custom model (e.g. Product, Sales, HR, Fleet Management, Attendance modules model etc)

  3. We can also add buttons in already existing/custom model (form and tree) view by using inheritance

Get .py and .xml code from here:

http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/25/15, 5:58 AM
Seen: 2313 times
Last updated: 2/13/18, 4:16 AM