<\/script>')

Openerp context in act_window

In OpenERP 6.1, this act_window:

<act_window domain="[('id', '=', student)]" id="act_schedule_student" name="Student" res_model="school.student" src_model="school.schedule"/> 

creates a Student button in the Schedule form, which opens a student tree view showing only the suitable student.

My goal is to directly open the corresponding student form view instead of the tree view with the appropriate student filter. I tried adding view_mode="form,tree" , but it opens a new form instead of the one I want. I assume this can be achieved by adding context to act_window ? Maybe record_id , but I tried this with active_id and it didn't work.

+6
source share
2 answers

The magical (and probably undocumented) way to have an OpenERP action directly opens the form view for this record, is to set an additional res_id attribute for the action.

Unfortunately, in OpenERP 6.1 [1], the res_id attribute res_id not part of the act_window data act_window , so it cannot be set directly in the XML declaration.

Most official add-ons use the <button type="object" ... /> binding to the Python method, which sets the res_id attribute in the returned action. Examples are pretty easy to find in this source code of the official modules, and you can see one in this related question .

Quick / untested example:

You would add this to your school.schedule form:

 <button name="open_student_form" type="object" string="Student"/> 

And the following method in the school.schedule model:

 def open_student_form(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids, context=context)[0] return { 'type': 'ir.actions.act_window', 'name': 'Student', 'view_mode': 'form', 'view_type': 'form', 'res_model': 'school.student', 'nodestroy': 'true', 'res_id': this.student.id, # assuming the many2one is (mis)named 'student' 'views': [(False, 'form')], } 

Now, if you really wanted to do this using the "sidebar" (ie, using <act_window/> ), this gets a little more complicated because you cannot directly bind the sidebar button to the Python method; it must be associated with an action that is stored in the database. It is still possible, for example, through the ir.actions.server action, which can be attached to your <act_window/> and calls your Python method or something like that. The trick with ir.actions.server is that it can be defined as a Python block that can return the definition of a dynamic action by assigning an action dictionary to the action variable. If you want to follow this path, search the addersp source code for ir.actions.server (some of which may do similar things) and methods that return actions with the res_id attribute.

[1] As in OpenERP 7.0, the res_id column res_id explicitly available in the data model, so you can directly set it.

+15
source

Try the following:

You can provide a domain in action. Whenever a student clicks on this menu, the action receives a trigger and sets the domain as follows:

 <record id="action_id" model="ir.actions.act_window" > <field name="name">Sample</field> <field name="res_model">model.name</field> <field name="view_type">form</field> <field name='domain'>[('employee_id.user_id','=',uid)]</field> <field name="context" >{'context_value':True}</field> <!--if required --> </record> 
0
source

All Articles