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

三国纷争
TA贡献1804条经验 获得超7个赞
我认为最简单的解决方案是在类中创建三个字段并确保定义域
attachment_type_a = fields.(...., domain=[...])
这里要做的关键是对所有字段使用相同的关系名称和列名称,以确保它们将数据保存在同一个表中,而无需创建三个关系表。
当您不关心域时,您可以保留 attachment_ids 以访问所有附件。
添加回答
举报
0/150
提交
取消