Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
33019 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer

very good

Beste antwoord

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

Avatar
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
dec. 24
21175
0
sep. 24
1045
3
aug. 24
2156
0
feb. 24
1472
0
feb. 24
1018