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
Try Server Action: https://learnopenerp.blogspot.com/2020/01/odoo-server-action.html