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.

2

Changing one2many field via on_change function

By
Alexander
on 6/18/13, 12:00 PM 3,052 views

It is real to change lines in one2many field via on_change function?

For example, I want to set location_id and location_dest_id in move_lines, when user changes this values in stock_picking form.

class stock_picking(osv.osv):
    _name = "stock.picking"
    _inherit = "stock.picking"

    _columns = {
        'location_id': fields.many2one('stock.location', 'Source Location', select=True,states={'done': [('readonly', True)]}),
        'location_dest_id': fields.many2one('stock.location', 'Destination Location', states={'done': [('readonly', True)]}),
        'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, ondelete='CASCADE'),
    }

    def update_move_lines(self, cr, uid, ids, location_id, location_dest_id, move_lines, context=None):
        returnValue = {}
        if move_lines:
            for row in move_lines:
                if type(row[2]) != dict:
                    row[2] = {}
                if location_id:
                    row[2]['location_id'] = location_id
                if location_dest_id:
                    row[2]['location_dest_id'] = location_dest_id
            returnValue['value'] = {'move_lines': move_lines}
        return returnValue


class stock_move(osv.osv):

    _name = "stock.move"
    _inherit = "stock.move"

    _columns = {
        'name': fields.char('Description', required=True, select=True),
        'location_id': fields.many2one('stock.location', 'Source Location', required=True, select=True,states={'done': [('readonly', True)]}),
        'location_dest_id': fields.many2one('stock.location', 'Destination Location', required=True,states={'done': [('readonly', True)]}),
    }



<record id="view_picking_form" model="ir.ui.view">
    <field name="name">stock.picking.form</field>
    <field name="model">stock.picking</field>
    <field eval="12" name="priority"/>
    <field name="arch" type="xml">
        <form string="Internal Picking List" version="7.0">
        <sheet>
            <group>
                <group>
                    <field name="location_id" on_change="onchange_location(location_id, location_dest_id, move_lines)"/>
                    <field name="location_dest_id" on_change="onchange_location(location_id, location_dest_id, move_lines)"/>
                </group>
            </group>
            <notebook>
                <page string="Products">
                    <field name="move_lines" context="{'form_view_ref':'view_move_picking_form', 'tree_view_ref':'view_move_picking_tree', 'picking_type': 'internal'}"/>
                </page>
            </notebook>
        </sheet>
        </form>
    </field>
</record>
1

Vasiliy Birukov

--Vasiliy Birukov--
3446
| 6 6 8
Russian Federation
--Vasiliy Birukov--

Help develop and implement any project on base Odoo.

Vasiliy Birukov
On 6/19/13, 2:49 AM

In your example move_lines is one2many field. If so, please see similar ask for how define o2m value.

Thanks, wowas!

Alexander
on 6/19/13, 3:28 AM

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

0 follower(s)

Stats

Asked: 6/18/13, 12:00 PM
Seen: 3052 times
Last updated: 3/16/15, 8:10 AM