Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
7 ตอบกลับ
11543 มุมมอง

Hello I've got two forms in my view xml file, here's the code for it

<record model="ir.ui.view" id="myMod_form_view">
<field name="name">myMod.form</field>
<field name="model">test.myMod</field>
<field name="arch" type="xml">
<form string="My Form 1">
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="myMod_conn_1_view">
<field name="name">myMod.form</field>
<field name="model">test.myMod</field>
<field name="arch" type="xml">
<form string="My Form 2">
<sheet>
<group string="Hello World">
</group>
</sheet>
</form>
</field>
</record>

this is the code for the button I use,

<button name='butClick' type='object' string="Click"/>

I want to return the second form to a view on a button click, I've written this code in the models.py

@api.multi
def butClick(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'test.myMod',
'name': 'Testing',
'views': [[False, 'form']],
'res_id': myMod_conn_1_view,
'target' : 'new',
}

but this gives an error,

NameError: global name 'myMod_conn_1_view' is not defined


What can I do to display this second form on the button click??? Please help!!!

อวตาร
ละทิ้ง
ผู้เขียน

hey, why did you remove the answer? :|

There were some issues with Arya's answer, only the last form was called from the above code, I fixed it with some help from Arya's answer... view_id = self.env['ir.model.data'].get_object_reference('module_name', 'myMod_conn_1_view') return { 'type': 'ir.actions.act_window', 'res_model': 'test.myMod', 'name': 'Testing', 'views': [[view_id[1], 'form']], 'target' : 'new', } thank you Arya... :)

คำตอบที่ดีที่สุด

Hi Rizan,

Your code is correct. You can pass IDs of your specific tree, form in views.

In res_id, you have to pass the ID of the test.myMod object if you want to show the record of that particular ID or if you want to show all the records, remove res_id.

@api.multi
def butClick(self):
view_ref = self.env['ir.model.data'].get_object_reference('module_name', 'xmlID_of_your_form_view')
return {
'type': 'ir.actions.act_window',
'res_model': 'test.myMod',
'name': 'Testing',
'views': view_ref and view_ref[1] or False,
# 'res_id': myMod_conn_1_view,
'target' : 'new',
}

Else you can directly use view_id instead of views in your return dictionary.

return {
'type': 'ir.actions.act_window',
'res_model': 'test.myMod',
'name': 'Testing',
'view_id': view_ref and view_ref[1] or False,
# 'res_id': myMod_conn_1_view,
'target' : 'new',
}

อวตาร
ละทิ้ง
ผู้เขียน

Hi Arya... thanks for the comment... can you please help me how to make the button click pick the second form? by default it's picking the first form...

ผู้เขียน

hey Arya, I get an error ValueError: External ID not found in the system: myMod.myMod_conn_1_view

Make sure you have given correct module name and XML ID.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 20
5065
3
ธ.ค. 23
20007
3
ม.ค. 24
8395
0
เม.ย. 23
1355
2
มี.ค. 23
9272