如何根据odoo中的记录过滤附件视图
How to filter attachments view depending on the records in odoo
目前正在odoo
开发客服管理模块。
在此用户可以创建案例。个案包含附件。我在案例表单视图上有一个按钮,单击它会打开附件视图 (ir.attachment)。
我想要的是根据记录过滤附件;即,当单击一条记录时,其关联的附件应该只能查看。
我的代码如下..
<button class="oe_stat_button" name="%(csm.attachement_action)d" string="Documents" type="action" />
<record id="attachement_action" model="ir.actions.act_window">
<field name="name">Attachments</field>
<field name="res_model">ir.attachment</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain" eval="[('res_id','=',active_id)]" />
<field name="view_id" ref="attachment_kanban"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">To add attachments click on create</p>
</field>
</record>
从按钮调用包含此域的操作
('res_id','=',active_id)
res_id
跟踪 "related resource".
或者您可以定义一个 return 动作的方法并从按钮调用它,例如:
@api.multi
def open_related_attachments(self):
self.ensure_one()
domain = [
('res_id', '=', self.id),
]
return {
'name': 'Related attachments',
'type': 'ir.actions.act_window',
'res_model': 'ir.attachment',
'target': 'current',
'view_type': 'form',
'view_mode': 'tree,form',
'domain': domain,
}
在按钮上附加上下文:
<button class="oe_stat_button" name="%(csm.attachement_action)d" string="Documents" type="action" context="{'res_name': name}"/>
并在域字段上过滤它:
<field name="domain">[('res_model','=','your.model'),('res_id','=', active_id),('res_name', '=', res_name + '...')]</field>
目前正在odoo
开发客服管理模块。
在此用户可以创建案例。个案包含附件。我在案例表单视图上有一个按钮,单击它会打开附件视图 (ir.attachment)。
我想要的是根据记录过滤附件;即,当单击一条记录时,其关联的附件应该只能查看。
我的代码如下..
<button class="oe_stat_button" name="%(csm.attachement_action)d" string="Documents" type="action" />
<record id="attachement_action" model="ir.actions.act_window">
<field name="name">Attachments</field>
<field name="res_model">ir.attachment</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain" eval="[('res_id','=',active_id)]" />
<field name="view_id" ref="attachment_kanban"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">To add attachments click on create</p>
</field>
</record>
从按钮调用包含此域的操作
('res_id','=',active_id)
res_id
跟踪 "related resource".
或者您可以定义一个 return 动作的方法并从按钮调用它,例如:
@api.multi
def open_related_attachments(self):
self.ensure_one()
domain = [
('res_id', '=', self.id),
]
return {
'name': 'Related attachments',
'type': 'ir.actions.act_window',
'res_model': 'ir.attachment',
'target': 'current',
'view_type': 'form',
'view_mode': 'tree,form',
'domain': domain,
}
在按钮上附加上下文:
<button class="oe_stat_button" name="%(csm.attachement_action)d" string="Documents" type="action" context="{'res_name': name}"/>
并在域字段上过滤它:
<field name="domain">[('res_model','=','your.model'),('res_id','=', active_id),('res_name', '=', res_name + '...')]</field>