跳至内容
菜单
此问题已终结

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> 
形象
丢弃
最佳答案

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.

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

最佳答案

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>
形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
8月 23
2820
2
4月 25
1011
0
3月 15
5104
2
7月 25
3978
2
3月 21
2927