当我使用 Odoo v11 单击 res.partner 中的按钮时,如何显示另一个模型的树视图?
How to show a tree view of another model when I click a button in res.partner with Odoo v11?
我在窗体视图中有一个继承 base.view_partner_form
的按钮。单击按钮时,我想显示另一个模型的树视图。我试过了,但出现错误 External ID not found
。我该如何解决?这是我的代码:
表单视图:
<record id="similar_list_view_partner_form" model="ir.ui.view">
<field name="name">similar_list_view_partner_form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"></field>
<field name="arch" type="xml">
<xpath expr="//button[@name='toggle_active'][not(ancestor::field)]" position="after">
<button class="oe_stat_button" name="similar_list_button_action" type="object" icon="fa-align-justify">
<field name="show" readonly="1"/>
</button>
</xpath>
</field>
</record>
树视图:
<record id="similar_detail_tree_view" model="ir.ui.view">
<field name="name">Similar Detail Tree View</field>
<field name="model">similar.task</field>
<field name="arch" type="xml">
<tree>
<field name="similar_name"/>
<field name="similar_email"/>
<field name="similar_phone"/>
</tree>
</field>
</record>
Python文件,按钮代码:
class similar_contact(models.Model):
_inherit = 'res.partner'
show = fields.Char(
string='Similar'
)
@api.multi
def similar_list_button_action(self):
tree_view_id = self.env.ref('similar_task.similar_detail_tree_view').id
return {
'name':'Similar Detail Tree View',
'type':'ir.actions.act_window',
'res_model':'similar.task',
'view_mode':'tree',
'views':[(view_tree_id,'tree')],
'res_id':False,
'target':'new'
}
Python 文件,新模型:
class similar_detail(models.Model):
_name="similar.task"
similar_name = fields.Char("Name")
similar_email = fields.Char("Email")
similar_phone = fields.Char("Phone")
试试这个:
@api.multi
def similar_list_button_action(self):
tree_view_id = self.env.ref('similar_task.similar_detail_tree_view').id
return {
'name': _('Similar Detail Tree View'),
'type': 'ir.actions.act_window',
'res_model': 'similar.task',
'view_type':'form',
'view_mode': 'tree',
'view_id': tree_view_id,
'res_id': False,
'context': False,
'target':'new'
}
注意:考虑到您的自定义模块应该被称为similar_task
我在窗体视图中有一个继承 base.view_partner_form
的按钮。单击按钮时,我想显示另一个模型的树视图。我试过了,但出现错误 External ID not found
。我该如何解决?这是我的代码:
表单视图:
<record id="similar_list_view_partner_form" model="ir.ui.view">
<field name="name">similar_list_view_partner_form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"></field>
<field name="arch" type="xml">
<xpath expr="//button[@name='toggle_active'][not(ancestor::field)]" position="after">
<button class="oe_stat_button" name="similar_list_button_action" type="object" icon="fa-align-justify">
<field name="show" readonly="1"/>
</button>
</xpath>
</field>
</record>
树视图:
<record id="similar_detail_tree_view" model="ir.ui.view">
<field name="name">Similar Detail Tree View</field>
<field name="model">similar.task</field>
<field name="arch" type="xml">
<tree>
<field name="similar_name"/>
<field name="similar_email"/>
<field name="similar_phone"/>
</tree>
</field>
</record>
Python文件,按钮代码:
class similar_contact(models.Model):
_inherit = 'res.partner'
show = fields.Char(
string='Similar'
)
@api.multi
def similar_list_button_action(self):
tree_view_id = self.env.ref('similar_task.similar_detail_tree_view').id
return {
'name':'Similar Detail Tree View',
'type':'ir.actions.act_window',
'res_model':'similar.task',
'view_mode':'tree',
'views':[(view_tree_id,'tree')],
'res_id':False,
'target':'new'
}
Python 文件,新模型:
class similar_detail(models.Model):
_name="similar.task"
similar_name = fields.Char("Name")
similar_email = fields.Char("Email")
similar_phone = fields.Char("Phone")
试试这个:
@api.multi
def similar_list_button_action(self):
tree_view_id = self.env.ref('similar_task.similar_detail_tree_view').id
return {
'name': _('Similar Detail Tree View'),
'type': 'ir.actions.act_window',
'res_model': 'similar.task',
'view_type':'form',
'view_mode': 'tree',
'view_id': tree_view_id,
'res_id': False,
'context': False,
'target':'new'
}
注意:考虑到您的自定义模块应该被称为similar_task