Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
8648 Lượt xem

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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks, wowas!

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 22
3699
2
thg 11 20
17798
2
thg 11 19
6648
1
thg 3 15
5686
1
thg 5 21
4641