This question has been flagged
2 Replies
12686 Views

I had 2 menuitems,

I try to get output like,first menu display all the record in the list view , and second menu display latest record form view.

In my case ,First menu work properly but in second menu case, i don't know how to get res_id of latest form view.

please suggest some ideas to me,

Here my code ,

In .py

class EventScoreUpdation(models.Model):
_name = 'event.updation'
event_name = fields.Char(string='Evnent Name')
   
    @api.multi
    def view_forum_ft(self):

return {
"type": "ir.actions.act_window",
"res_model": "event.score.updation",
"res_id": , //How to get the res_id of form view
"view_mode": "form",
"view_id": self.env.ref('forum_ft.event_score_updation_view').id,
}
In xml


<record model="ir.actions.server" id="statistics_server_action">
<field name="name">Statistics Server Action</field>
<field name="model_id" ref="forum_ft.model_event_updation">
<field name="state">code</field>
<field name="code">action = model.view_forum_ft()</field>
</record>

<menuitem id="menu_viewer1" name="Event"
parent="harmony_menu" action="statistics_server_action" groups="base.group_user"/>


Avatar
Discard

self.env.ref('module_name.your_form_view_name'

Best Answer

Hi friend,

you can do like this:

rec = self.env['event.score.updation'].search([], limit=1)

return {

    "type": "ir.actions.act_window",

    "res_model": "event.score.updation",

    "res_id": rec.id,                                            

    "view_mode": "form",

    "view_type": "form",

    "view_id": self.env.ref('forum_ft.event_score_updation_view').id,

}

From above code, first i have get latest record and then pass in res_id.

Accept and and upvote answer if helpful..

Thanks and Regards

Haresh Kansara

Avatar
Discard
Author

Thank you, its work correctly.

Once again thanks and regards ,

Ajini A V

Best Answer

Hi Haresh, I've tried your code on my button that open a current form view of user and it works fine as it getting the id of the user and opening the form view, but the problem is everytime I reload or refresh the page, the form view changes and it was a contacts form, can you also help me to solve this? Thanks

Avatar
Discard