Saturday, October 6, 2012
_defaults & context when click create object
This topic is very interesting. I'm studying to resolve this problem and I found this solution by my self.
problem :
I have predefined ORM create method in my module for model product.product. Also, I have custom view for that model. My custom view appears only in my module section, but for everything else appears default product.product view.
My problem is when user click on create button, how can I know is that click was generated from my custom view. I need this because some additional processing before creating product.product record.
I find solution via context. So, I put context in some field in my custom form view:
<openerp>
<data>
<record id="custom_form_view" model="ir.ui.view">
....
<field name="is_custom" context="{'identificator':True}" />
.....
</record>
</data>
</openerp>
In my predefined create method I will check this with if/else statement:
if context.has_key('identifikator'):
... aditional code ...
But, this solution doesn't work. I can't see context="{'identificator':True}" in create method, only default context appears.
How can I pass custom context from form view to create method on this or some other way?
Solution is : Add context="{'identificator':True}" in action record like below
<record id="act_obj1" model="ir.actions.act_window">
<field name="name">Obj1</field>
<field name="res_model">test.mod.obj1</field>
<field name="context">context="{'identificator':True}</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
source : http://www.openerp.com/forum/topic34382.html
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment