This question has been flagged
2 Replies
11086 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'),

    }

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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.

Avatar
Discard