openerp-community team mailing list archive
-
openerp-community team
-
Mailing list archive
-
Message #00841
Re: setting the context in act_window
On 01/30/2012 11:38 AM, Viktor Nagy wrote:
> is it possible to set the context from a database query in an
> ir.actions.act_window definition?
>
> my example code is here http://pastebin.com/kciDSURZ
Not really, no. Quoting your example:
<field name="context" eval="{'search_default_draft': 1,'order_date':
self.pool.get('res.company').get_value(cr, uid, 'order_date', context)}" />
The `eval` attribute is statically evaluated when the record is loaded,
at module installation time. I'm not sure, but based on the rest of your
example it seems you want a dynamic value to be used for filtering records.
A few solutions come to mind which may perhaps better suit your needs:
- Dynamic actions: link a menuitem to a server action that executes some
python code to load the values you need from the database, then returns
a dynamic action dict (by assigning a value to an 'action' variable)
with the appropriate context/domain you need. You could see this as a
dynamic action loader.
- Dynamic search views: alternatively, override the fields_view_get()
method of purchase.order to dynamically customize the search view by
adding an appropriate `filter` element (using any DB value you like).
This is less elegant because it requires some XML-level tinkering with
the result of the super() call, but is an effective way to implement
dynamic views.
HTH,
References