Odoo Help


set a value in order line field when clicking button in openerp

on 2/12/15, 1:45 AM 3,486 views

I will add fields under customer and order line form.

then I will select value in dropdown list ship field, after clicking button ,value will show on ship field of order line form. How it possible. this is my code

.xml file

<?xml version="1.0" encoding="UTF-8"?>

       <record model="ir.ui.view" id="view_order_tree_inherit">
            <field name="name">sale.order.tree</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_tree"/>
            <field name="arch" type="xml">
                <field name="partner_id" position="after">
                    <field name="ship_id"/>

       <record model="ir.ui.view" id="view_order_form_inherit">
            <field name="name">sale.order.form.inherit</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/group/group/field[@name='partner_id']" position="after">
                    <field name="ship_id" on_change="onchange_ship_id(ship_id)"/>
                    <field name="hull_no"/>
                    <field name="engn_no"/>
                <xpath expr="//sheet/group" position="inside">
                    <button name="get_update" string="Update to Order Line" type="object" context="{'ship_id':'ship_id'}"/>
                <xpath expr="//tree/field[@name='product_uom_qty']" position="after">
                        <field name="ship_no"/>


.py file

from openerp.osv import osv
from openerp.osv import fields

class ship_so(osv.osv):

    _inherit = 'sale.order'

    _columns = {

        'ship_id': fields.many2one('ship.info', 'Ship Field '),
        'hull_no': fields.char('Hull Number',size=25),
        'engn_no': fields.char('Engine Number',size=25),

    def onchange_ship_id(self, cr, uid, ids, ship_id, context=None):
        if ship_id:
            ship = self.pool.get('ship.info').browse(cr, uid, ship_id, context=context)
            return {'value': {'hull_no': ship.hullno, 'engn_no': ship.enginno}}
        return {}

    def get_update(self, cr, uid, ids, context='ship_id'):
        ship = self.browse(cr, uid, ids, context=context)
        val = ship.ship_id.imo
        line = self.pool.get('sale.order_line')
        self.write(cr, uid, ids, {line.ship_no: val})
        return True


class ship_line(osv.osv):

    _inherit = 'sale.order.line'

    _columns = {

        'ship_no': fields.text('Ship Field'),





| 5 3 8
Pondicherry, India
On 2/12/15, 3:06 AM

hi.you try this method in your code:

    def get_update(self, cr, uid, ids, context='ship_id'):
        order_line_obj = self.pool.get('sale.order.line')
        for order in self.browse(cr, uid, ids, context=context):
            for line in order.order_line:
                order_line_obj.write(cr, uid, [line.id], {'shop_no':val})
        return True

Martin Pishpecki
On 9/19/16, 9:24 AM

Is this the only way to set value to a grid. I cannot believe that a modern framework does not have the most basic functionality on click of a button set values to tree.

I tried using the method oncahnge() set on a filed - this works, but if this method is called by a button - it does not work

Also I have tried using the defaults - again it work on create, but when I call the method by a button - it fails to fill the tree.

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.


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

1 follower(s)


Asked: 2/12/15, 1:45 AM
Seen: 3486 times
Last updated: 9/19/16, 9:24 AM