我在 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",
)
}
我还通过添加“file_custom_type”修改了 ir_attachment 模型:
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'}"/>
</group>
</page>
</notebook>
但是有了这个,我遇到了多个问题:
上下文不起作用:file_custom_type 从未按预期保存,它在数据库中保持空白(在我的服务器上使用 psql 请求验证)
当我使用表单视图上传图片时,图片保存在 ir_attachment 表中,这是预期的。
但是,关系表res_partner_custom_ir_attachment_rel
仅针对 xml 中最后一次出现的字段递增(在给定的代码中,它是“类型 c”,但如果我将类型 C 和类型 B 的字段互换,则只有类型 B 会保存在关系表。
这导致仅在最下方的字段中显示附件(并且仅显示在此字段中输入的附件)
三国纷争
相关分类