Odoo Help

0

How to set value in field order line while selecting a value in drop downlist

By
shameem
on 2/13/15, 6:17 AM 910 views

I have two custom field defined in two classes. one class is inherit from 'sale.order' another class can inherit from 'sale.order.line'. so while selecting value from dropdown list filed of first class, then it can be set to filed of second class. How it's possible

this is code

.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 {}

 

class ship_line(osv.osv):

    _inherit = 'sale.order.line'

    _columns = {

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

    }

 

.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">
                </xpath>
                <xpath expr="//tree/field[@name='product_uom_qty']" position="after">
                        <field name="ship_no"/>
                </xpath>
            </field>
       </record>

    </data>
</openerp>

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

1 follower(s)

Stats

Asked: 2/13/15, 6:17 AM
Seen: 910 times
Last updated: 3/16/15, 8:10 AM