Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10044 Lượt xem

How to get and set a Many2many field in res.config.settings  

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

 Hi,

   You can check this https://www.odoo.com/forum/help-1/question/12-0-enable-features-in-the-res-config-settings-149566     link              

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can refer to the link specified in the other answer. To be a little more specific with the many2many field, you can try this code.


class XYZConfigSettings(models.TransientModel):
_name = 'xyz.config.settings'
_inherit = 'res.config.settings'

product_ids = fields.Many2many('product.product', string="Products")

@api.model
def get_default_values(self, fields):
IrValues = self.env['ir.values'].sudo()
product_ids = IrValues.get_default('xyz.config.settings', 'product_ids')
lines = False
if product_ids:
lines = [(6, 0, product_ids)]
return {
'product_ids': lines,
}

@api.multi
def set_default_values(self):
IrValues = self.env['ir.values'].sudo()
IrValues.set_default('xyz.config.settings', 'product_ids', self.product_ids.ids)

See this Video For Odoo12: How To Save Many2many Field Value In Settings Odoo

Thanks

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 4 23
7022
1
thg 6 21
7504
6
thg 3 24
22756
1
thg 8 18
5228
0
thg 6 15
4774