Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
33013 Widoki

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





Awatar
Odrzuć
Najlepsza odpowiedź

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,

Awatar
Odrzuć

very good

Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
gru 24
21170
0
wrz 24
1043
3
sie 24
2155
0
lut 24
1469
0
lut 24
1017