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.

0

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

By
shameem
on 2/12/15, 1:45 AM 1,913 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"?>
<openerp>
    <data>

       <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"/>
                </field>
            </field>
       </record>

       <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>
                <xpath expr="//sheet/group" position="inside">
                    <button name="get_update" string="Update to Order Line" type="object" context="{'ship_id':'ship_id'}"/>
                </xpath>
                <xpath expr="//tree/field[@name='product_uom_qty']" position="after">
                        <field name="ship_no"/>
                </xpath>
            </field>
       </record>

    </data>
</openerp>

.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'),

    }

3

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
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

0
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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

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