Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to add a new field "Shipment Cost" after "Unit Price" in purchase order create form? [Closed]

By
Md. Shah Jalal
on 7/19/13, 3:58 PM 2,734 views

The Question has been closed

by
Sudhir Arya (SA)
on 07/20/2013 14:05:50

HI, I'm new to openerp. I'm using Openerp v7 on windows 7. I want to add a new field "Shipment Cost" after the field "Unit Price" in the Purchase Order create form. I've developed a custom module to do this. I've installed the module successfully, restarted the openerp server and logged in again in openerp. But the new field is not showing in the form. Please help me to solve this issue. below is the code :

module folder: purchase_shipment

file 1: _init_.py

import purchase_shipment

file 2:_openerp_.py

{ "name" : "Purchase Order Lines With Shipment Cost", "author" : "Sjalal", "version" : "1.0", "category" : "Generic Modules/Sales & Purchases", "depends" : ["base", "purchase"], "demo_xml" : [], "update_xml" : ["purchase_shipment_view.xml"], "active": False, "installable": True }

file 3: purchase_shipment.py

from openerp.osv import fields, osv from openerp import netsvc

class purchase_order_line(osv.osv): _name = 'purchase.order.line' _inherit = "purchase.order.line" _columns = { 'shipment_cost': fields.float('Shipment Cost', size=30, store=True), } purchase_order_line()

file 4: purchase_shipment_view.xml

<openerp> <data> <record model="ir.ui.view" id="view_purchase_form1"> <field name="name">purchase.order.line.form.inherit</field> <field name="model">purchase.order.line</field> <field name="type">form</field> <field name="inherit_id" ref="purchase.purchase_order_line_form"/> <field name="arch" type="xml"> <field name="price_unit" position="after"> <field name="shipment_cost"/> </field> </field> </record> </data> </openerp>

you should use <xpath> for you to add your field afte this: <field name="arch" type="xml"> <xpath expr="//field[@name='price_unit']" position="after"><field name="shipment_cost"/></xpath>

Lady Sharmane Udtuhan
on 7/20/13, 2:00 AM
1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 7/20/13, 1:24 PM

Hello Md. Shah,

Your code seems fine except xml. You want to add field in Purchase Order Line in Purchase Order form. So you need to inherit purchase.order form view and then add your custom field using xpath.

Try this:

<record model="ir.ui.view" id="view_purchase_form1">
    <field name="name">purchase.order.form.inherit</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="after">
            <field name="shipment_cost"/>
        </xpath>
    </field>
</record>

Now, update your module and then you can see your field in Purchase Order Line tree in Purchase Order form.

I hope this will solve your problem.

Thank you Sudhir for your extra ordinary help. Your solution worked superbly. You just saved me.

Md. Shah Jalal
on 7/20/13, 1:54 PM

Pleasure is mine.

Sudhir Arya (SA)
on 7/20/13, 2:05 PM

hi Sudhir How to calculate shipment cost in unit_price

Atul Kumar jain
on 2/18/14, 6:19 AM
0

you should use <xpath> for you to add your field afte this: <field name="arch" type="xml"> <xpath expr="//field[@name='price_unit']" position="after"><field name="shipment_cost"/></xpath>

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/19/13, 3:58 PM
Seen: 2734 times
Last updated: 7/25/15, 8:30 AM