Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
33005 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit

very good

Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
pro 24
21164
0
zář 24
1039
3
srp 24
2150
0
úno 24
1466
0
úno 24
1016