Openerp set default value of popup form from one2many field parent

class definition (shop.py), please note the magic active_id


class item(osv.osv):
_name = "shop.item"
_columns = {
"item_id": fields.many2one("shop.cart", "Cart"),
}
_defaults = {
"item_id": lambda self, cr, uid, c: c.get('item_id', False),
}

class cart(osv.osv):
_name = “shop.cart”
_columns = {
“item_ids”: one2many(“shop.item”, “item_id”, “Items”),
}

In the view definition for the one2many field (shop_view.xml)

<field name=”item_ids” domain=”[‘item_id’, ‘=’, active_id]” context=”{‘item_id’: active_id}” />

 

Advertisements

Published by

paragasu

Different. In a good way

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s