Odoo Help

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 3,400 views

The Question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
10906
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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 platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

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