我在 res_partner 和 ir_attachement 之間有一個(gè) 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") }這將允許我按我的自定義類型重新組合附件,對(duì)我的附件進(jìn)行排序,并且比僅在我的表單視圖頂部使用 XXX 數(shù)百個(gè)附件的下拉列表具有更清晰的視圖。所以我在 res_partner_form_view 中創(chuàng)建了一個(gè)筆記本:<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>但是有了這個(gè),我遇到了多個(gè)問題:?jiǎn)栴} 1:永遠(yuǎn)不會(huì)保存 file_custom_type上下文不起作用:file_custom_type 從未按預(yù)期保存,它在數(shù)據(jù)庫(kù)中保持空白(在我的服務(wù)器上使用 psql 請(qǐng)求驗(yàn)證)問題 2:只有最后一次出現(xiàn)的字段保存在關(guān)系表中當(dāng)我使用表單視圖上傳圖片時(shí),圖片保存在 ir_attachment 表中,這是預(yù)期的。但是,關(guān)系表res_partner_custom_ir_attachment_rel僅針對(duì) xml 中最后一次出現(xiàn)的字段遞增(在給定的代碼中,它是“類型 c”,但如果我將類型 C 和類型 B 的字段互換,則只有類型 B 會(huì)保存在關(guān)系表。這導(dǎo)致僅在最下方的字段中顯示附件(并且僅顯示在此字段中輸入的附件)
Odoo 如何通過小部件 many2many_binary 為特定字段設(shè)置默認(rèn)值
BIG陽(yáng)
2023-06-06 17:39:59