Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Passing active_id to action window in openerp7

By
Behairy
on 3/17/14, 4:17 AM 3,782 views

I building a custom module in openerp version 7. I'm facing problems in trying to link an anchor tag in a kanban view item to an action window which will open the clicked on item in a form view.

Here's a sinppet of the kanban view

<a  type="action"  name="myaction">
     <img t-att-src="kanban_image('vessel', 'image_medium', record.id.value)" class="oe_employee_picture" />
</a>

Here's the action that will be invoked on click

<record model="ir.actions.act_window" id="myaction">
  <field name="name">Vessel</field>     
  <field name="res_model">vessel</field>
  <field name="view_type">form</field>
  <field name="view_id" ref="crew_management.view_crew_management_vessels_form"/>
  <field name="view_mode">form</field>
  <field name="context">{'id': active_id}</field>
</record>

Currently when clicking on the link it opens the correct form view but empty. It seems that the active id of the selected item is not passed somehow.

0
Behairy
On 3/27/14, 9:47 PM

Thanks David. Actually I found the solution which turned out to be really simple without using any model logic.

You need to set res_id to the current active_Id in the object's context. See the example below

To pass the active id of an object use res_id instead.

<field name="context">{'res_id': active_id}</field>

The complete code would be

<a  type="action"  name="action_id">
       <!-- Anything Here -->
</a

<record model="ir.actions.act_window" id="action_id">
  <field name="name">demo</field>     
  <field name="res_model">demo</field>
  <field name="view_type">form</field>
  <field name="view_id" ref="my_module.demo_view_id"/>
  <field name="view_mode">form</field>
  <field name="context">{'res_id': active_id}</field>
</record>

I hope this helps you as well.

Thanks

Great, thanks for sharing

David
on 3/28/14, 8:51 AM
0
David
On 3/18/14, 1:12 AM

I had to do the same thing before. Setting context or domain didn't work.

You need to set the valueres_id of your action dynamically. The way I found is through a server action, that returns a window. Your action would be something like:

<record model="ir.actions.server" id="myaction">
    <field name="type">ir.actions.server</field>
    <field name="name">Vessel</field>
    <field name="state">code</field>
    <field name="model_id" ref="model_your_current_model"/>
    <field name="code">action = object.open_form_test()</field>
</record>

notice the ref parameter of model_id must start with "model_"

And in your_current_model class add the function:

def open_form_test(self, cr, uid, ids, context=None):
    id = context["active_id"]
    return {
        'type': 'ir.actions.act_window',
        'res_model': 'crew_management',
        'res_id': your_id,
        'view_mode': 'form',
        'view_type': 'form',
        'target': 'new',
    }

The active_id is passed in the context. You need to add logic to get the id you want in your model.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/17/14, 4:17 AM
Seen: 3782 times
Last updated: 7/6/15, 5:47 PM