Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
33004 Vizualizări

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





Imagine profil
Abandonează
Cel mai bun răspuns

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,

Imagine profil
Abandonează

very good

Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
dec. 24
21163
0
sept. 24
1039
3
aug. 24
2150
0
feb. 24
1465
0
feb. 24
1015