【发布时间】:2020-08-19 17:19:16
【问题描述】:
我在 res_partner 和 ir_attachement 之间定义了一个 many2many 字段:
class res_partner(osv.osv):
_inherit = 'res.partner'
_columns = {
'attachments_ids': fields.many2many('ir.attachment',
'res_partner_custom_ir_attachment_rel',
string=u"Custom attachments",
)
}
我还修改了 ir_attachment 模型,以这种方式添加了“file_custom_type”:
class Attachment(osv.osv):
_inherit = 'ir.attachment'
_columns = {
'file_custom_type': fields.selection([("a", u"Type A"),
("b", u"Type B"),
("c", u"Type C"),
],
u"Custom file type")
}
与表单视图顶部的 XXX 数百个附件的下拉列表相比,这将允许我按我的自定义类型重新组合附件,对附件进行排序并获得更清晰的视图。
所以我在 res_partner_form_view 中创建了一个笔记本:
<notebook position="inside">
<page string="Company attachments" attrs="{'invisible': [('is_company', '=', False)]}">
<group>
<field name='attachments_ids'
string="Attachment type A"
widget='many2many_binary'
domain="[('file_custom_type', '=', 'a')]"
context="{'default_file_custom_type': 'a'}"/>
<field name='attachments_ids'
string="attachment type B"
widget='many2many_binary'
domain="[('file_custom_type', '=', 'b')]"
context="{'default_file_custom_type': 'b'}"/>
<field name='attachments_ids'
string="attachment type C"
widget='many2many_binary'
domain="[('file_custom_type', '=', 'c')]"
context="{'default_file_custom_type': 'c'}"/>
</group>
</page>
</notebook>
但是有了这个,我遇到了很多问题:
问题 1:file_custom_type 永远不会保存
上下文不起作用:file_custom_type 从未按预期保存,它在数据库中保持空白(通过我服务器上的 psql 请求验证)
问题 2:只有最后一次出现的字段保存在关系表中
当我使用表单视图上传图片时,图片保存在ir_attachment表中,这就是本意。
但是,关系表 res_partner_custom_ir_attachment_rel 仅在 xml 中字段的最后一次出现时递增(在给定的代码中,它是“类型 c”,但如果我将类型 C 和类型 B 的字段相互转换,则只有类型 B 将保存在关系表中。
这导致附件仅显示在最下方的字段(并且仅显示在此字段中输入的附件)
Bug 可视化:
问题 3:域不工作
正如你在上面的问题中看到的,file_custom_type 没有保存,但是我在这个字段上有一个域,然而,第三个仍然显示附件,当域状态时它应该只显示 file_custom_type=" c"。
【问题讨论】:
-
v8 不支持在表单视图中多次使用一个字段