Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
32981 Vistas

How to Add field in Sale Order Form ??

Right now i have basic knowledge of adding field customer part in sale form

but how do i add field in sale order line ?

suppose i create a new field in product called "Total Weight"

which will take the value from weight in product x qty that has been input

how do i acheieve that please shed me somelight





Avatar
Descartar
Mejor respuesta

Hello Vootipong Limpanitivat,


For that you need to inherit sale.order.line object and use xpath to display in sale order form view. 

In PY:-

class SaleOrderLine(models.Model):

     _inherit = 'sale.order.line'


     x_field = fields.Char('X Field')


In Xml:-

<record model="ir.ui.view" id="sale_order_view_inherit">
    <field name="name">sale.order.view.inherit1</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='name']" position="after">
            <field name="x_field"/>
        </xpath>
    </field>
</record>


This fields shows after Description in the sale order line.


Hope it will helps you.

Thanks,

Avatar
Descartar

very good

Mejor respuesta

Nice video to add custom field from UI Without Code: \https://www.youtube.com/watch?v=BNxfX3zCpts&t=3s

Avatar
Descartar
Mejor respuesta

Similar to Jignesh Metha, but in my code, I use this <xpath>.

<xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='tax_id']" position="after">

  <field name="x_field"/>

</xpath> 

It works for me.

Avatar
Descartar
Mejor respuesta

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:

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

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

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

You can check more details : http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 24
21156
0
sept 24
1031
3
ago 24
2145
0
feb 24
1451
0
feb 24
1012