Skip to Content
Menu
This question has been flagged
2 Replies
7746 Views

Hello i'm currently using odoo 14.
What i want to do is to create a window action with  a dynamic record ID "res_id", and this last i want it to be the current user "uid".

<record model="ir.actions.act_window" id="action_window_id">
    <field name="name">my_module.model.action</field>
    <field name="res_model">model.model_one</field>
    <field name="view_mode">form</field>
    <field name="res_id" eval="THE CURRENT UID HERE" />
</record>

i've tried "self.env.uid","obj()"... with no result.
do you have any idea about this !
Thank you very much.

Avatar
Discard
Author Best Answer

I have ended this battle, by steps below:

1- Create method in my model which do the logic for res_id field and return a window action.

def alternative_action(self):
    exist = self.sudo().search([["user_id", "=", self.env.uid]], limit=1)
    # user_id is a field declared into my model
    res_id = self.env.uid
    return {
        "type" : "ir.actions.act_window",
        "res_model" : self._name,
        "view_mode": "form", 
        "res_id": exist.id if exist.id else False
    }

2- Create a server action which will call the method below:

<record model="ir.actions.server" id="id_act_server"> 
    <field name="name">resume res_id action</field> 
    <field name="model_id" ref="module_name.model_name"/> 
    <field name="state">code</field> 
    <field name="code"> 
        action = model.sudo().alternative_action() 
    </field> 
</record>
3- When creating the menu, we call the server action rather than calling the act_window as usual

<menuitem name="My module menu" id="my_module_menu" action="id_act_server"/>

and ... that's it.
This solution may work for different use cases not only mine, we can also give it a title like :
"customize the menu link".

Hopefully this will help some. Thanks

Avatar
Discard
Best Answer

Thanks man 

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 15
4399
0
Mar 15
3363
1
Jan 24
520
2
Mar 18
3734
1
Mar 15
3920