This question has been flagged
2 Replies
5159 Views

Hello,

I want to change the column of my sales order. I want for exemple to add the column default_code (internal reference). I tried to update the xml of the FormView but unsuccessfully by adding this in <tree></tree>

<field name="default_code" />

In fact I know why, the default_code field does not exist in the sale_order_line but it exists in the product.product model. How can I display a value of an object with a relation many2one ?

My environment : 

Odoo v8

 

Thank you

Avatar
Discard
Best Answer

first you need to create new fields(custom fields) in

                    class sale_order_line(osv.osv):              in   sale.py file

and then add your custom fields

(here i added product_category,image_medium,payment_id   fields )

in sale_view.xml file

-----------------------

 <notebook>
                        <page string="Order Lines">
                            <field name="order_line">
                                <form string="Sales Order Lines" version="7.0">
                                    <header groups="base.group_user">
                                        <button name="%(action_view_sale_order_line_make_invoice)d" states="confirmed" string="Invoice" type="action" icon="terp-document-new"/>
                                        <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done" statusbar_colors='{"exception":"red","cancel":"red"}'/>
                                    </header>
                                    <group>
                                        <group>
                                            <field name="product_category"/>   <!--  custom field  -->

                                            <field name="product_id" domain="[('categ_id','=',product_category)]"                                           context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'image_medium':image_medium, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                                groups="base.group_user"
                                                on_change="product_id_change(parent.pricelist_id, product_id,image_medium, product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)" />
                                            <label for="product_uom_qty"/>
                                            <div>
                                                <field
                                                    context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                                    name="product_uom_qty" class="oe_inline"
                                                    on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                                <field name="product_uom" groups="product.group_uom" class="oe_inline oe_no_button"

                                                    on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/>
                                            </div>
                                            <label for="product_uos_qty" groups="product.group_uos"/>
                                            <div groups="product.group_uos">
                                                <field name="product_uos_qty" class="oe_inline"/>
                                                <field name="product_uos" options='{"no_open": True}' class="oe_inline"/>
                                            </div>
                                            <field name="price_unit"/>
                                            <label for="discount" groups="sale.group_discount_per_so_line"/>
                                            <div name="discount" groups="sale.group_discount_per_so_line">
                                                <field name="discount" class="oe_inline"/> %%
                                            </div>
       <!--  custom field  -->
                        <field name="image_medium" widget="image"  class="oe_avatar oe_left"/>

                                        </group>
                                        <group>
                                            <field name="tax_id" invisible="1" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
                                            <field name="type"/>
                                            <field name="th_weight"/>
                                            <!-- we should put a config wizard for these two fields -->
                                            <field name="address_allotment_id"/>
                                            <field name="remarks"/>
                                            <field name="expire_date"/>
                                        </group>
                                    </group>
                                    <label for="name"/>
                                    <field name="name"/>
                                    <div groups="base.group_no_one">
                                        <label for="invoice_lines"/>
                                        <field name="invoice_lines"/>
                                    </div>
                                </form>
                                <tree string="Sales Order Lines" editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="state" invisible="1"/>
                                    <field name="th_weight" invisible="1"/>
                <!--   <field name="image_medium" widget="image" />  -->
                                    <field name="product_id"
                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                        groups="base.group_user" 
                                        on_change="product_id_change(parent.pricelist_id, product_id,  product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
                                    <field name="name"/>

                                    <field name="product_uom_qty"
                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                                        on_change="product_id_change(parent.pricelist_id, product_id, image_medium, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                    <field name="product_uom"
                                        on_change="product_uom_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, context)"
                                        groups="product.group_uom" options='{"no_open": True}'/>
                                    <field name="product_uos_qty" groups="product.group_uos" invisible="1"/>
                                    <field name="product_uos" string="UoS" groups="product.group_uos" invisible="1"/>
                                    <field name="tax_id" invisible="1"  widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
                                    <field name="price_unit"/>
                                    <field name="discount" groups="sale.group_discount_per_so_line"/>
                                    <field name="price_subtotal"/>
                                </tree>
                            </field>
                            <group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
                                <field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                                <field name="amount_tax" invisible="1"  widget='monetary' options="{'currency_field': 'currency_id'}"/>
                                <div class="oe_subtotal_footer_separator oe_inline">
                                    <label for="amount_total" />
                                    <button name="button_dummy"
                                        states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
                                </div>
                                <field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            </group>
                            <div class="oe_clear"/>
                            <field name="note" class="oe_inline" placeholder="Terms and conditions..."/>
                        </page>
                        <page string="Other Information" groups="base.group_user">
                            <group>
                                <group name="sales_person" groups="base.group_user">
                                    <field name="user_id"/>
                                    <field groups="base.group_no_one" name="origin"/>
                                </group>
                                <group name="sale_pay">
    
                                   <field name="payment_id" widget="selection"/>  <!--  custom field  -->

                                    <field name="payment_term" domain="[['parent_id','=',payment_id]]" />
                                    <field name="fiscal_position" widget="selection" invisible="1"/>
                                    <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                                </group>
                                <group>
                                    <field name="invoiced"/>
                                    <field name="invoice_exists" invisible="1"/>
                                </group>
                            </group>
                        </page>
                    </notebook>

Avatar
Discard