我为res.partner模块创建了两个表单视图。 第一个是继承的,第二个只显示几个字段:
<record model="ir.ui.view" id="program_viewform">
<field name="name">My Program</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<form>
<separator string="My Program " />
<field name="projects_ids" nolabel="True"/>
<separator string="submitted Tasks" />
<field name="submission_task_ids" nolabel="True"/>
</form>
</field>
</record>
并使用了这个动作:
<record model="ir.actions.server" id="myprogram_action">
<field name="name">My Program</field>
<field name='model_id' ref='base.model_res_partner'/>
<field name="state">code</field>
<field name="code">
action = {
'type': 'ir.actions.act_window',
'name': 'My Program',
'view_mode': 'form',
'view_type': 'form',
'view_id': 'ref="training_program_management.program_viewform"',
'context': '{ "form_view_ref":"program_viewform"}',
'res_model': 'res.partner',
'res_id': int(env['res.users'].browse(env.user.partner_id.id)),
'views': [(True, 'form')],
}
</field>
</record>
它正常工作,没有错误,问题是它显示了第一个ForView,我需要用id:program_viewform显示视图。 我在ir.actions.server中仍然有点混乱,我不理解这一行的使用:
'views': [(True, 'form')],
为什么这条线路没有向我显示所需的视图?
'view_id': 'ref="training_program_management.program_viewform"',
任何解释都会有所帮助。
答案 0 :(得分:2)
不要直接在服务器操作中返回创建方法 返回相同的字典。
<field name="code">action = model.open_form_view()</field>
并在您的模型中定义此方法:
@api.model
def open_form_view(self):
# FIRST GET THE ID OF THE VIEW
form_id = self.env.ref('training_program_management.program_viewform').id
# if you want to open the res partener related to the user
recor_id = self.env.user.partner_id.id
return {
'type': 'ir.actions.act_window',
'name': 'My Program',
'view_mode': 'form',
'view_type': 'form',
# form_id accept integer value.
# if you are using only one view
# no need to use views
'view_id': form_id,
'context': {},
'res_model': 'res.partner',
'res_id': record_id ,
# but if you are using more then one view
# you must use views to pass mutliple ids
#'views': [(form_id, 'form'), (tree_id, 'tree')],
# and to specify the search view use
# 'search_view_id': search_view_id,
}