Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
15769 Lượt xem

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> 
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

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

Câu trả lời hay nhất

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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 23
2997
2
thg 4 25
1128
0
thg 3 15
5244
2
thg 7 25
4135
2
thg 3 21
3090