This question has been flagged
1 Reply
2425 Views

in "act_window", I set  view_mode as below "view_mode="form" ";

Then I click the windows' button, I will go into its "form" for "create" mode; Now I want to to into the latest existed record when I click this windows's button/menu button; how shall I? 

The form codes are as below:

<record id="test1" model="ir.ui.view">

<field name="name">Test Form</field>

<field name="model">Test</field>

<field name="arch" type="xml">

<form>

..........

</form>

</field>

</record>

Avatar
Discard
Best Answer

HI You can achive this using _order attribute.

Syntax:

_order = "id desc"

Avatar
Discard
Author

thanks for your reply; I have add "_order = "id desc"", but I still go into the "form for creating" rather than the "form" of existed record which has been created before.

As I can understand, you have not defined the tree view for the model, if not pls create tree view and add it to action definition and if already created it then add it to action definition.

Syntax:

<record id="action id" model="ir.actions.act_window">

<field name="name">Action Name</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">object.name</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form</field>

</field>

</record>

Then you will be able to see the latest record created for that object.

Author

thank you very much for reply again and again;

but I am afraid of that I never make you clear my problem; now I will explain it clearly as below:

1. I use odoo 10;

2. I have define menu, tree and form views as below:

2.1 menu view

<menuitem id="hedgehs300"

name="hs300"

parent=""

sequence="1"

action="action_300"

/>

<act_window id="action_300"

name="hstest"

res_model="hedge300"

view_mode="tree,form" />

2.2 tree veiw:

<record id="view_tree_300" model="ir.ui.view">

<field name="name">Hedge300 Tree</field>

<field name="model">hedge300</field>

<field name="arch" type="xml">

<tree>

<field name="name"/>

<field name="create_date"/>

</tree>

</field>

</record>

2.3 form view:

<record id="view_form_300" model="ir.ui.view">

<field name="name">Hedge300 Form</field>

<field name="model">hedge300</field>

<field name="arch" type="xml">

<form>

......

</form>

</field>

</record>

3. Now all is ok, and I have created only one record of it, named "A"; and then I change " view_mode="tree,form" " in "act_window" into " view_mode="tree,form" "; I want to go into record "A" form view directly when I clicked the menu item rather than creating form view; how shall I edit my codes?

.py file as below:

class HedgeHS300(models.Model):

_name = 'hedge300'

_description = 'Hedge300'

_order = "id desc"

......