我在 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
提交
取消