I was trying to make two many2many fields inside configuration settings of website. I could make both fields fields but I was not able to save the multiple entered values. This is the error that occured
File "/home/RobertD'Souza/Desktop/odoo-13.0/odoo/models.py", line 1688, in _add_missing_default_values if self._fields[name].type == 'many2many' and value and isinstance(value[0], int): KeyError: 'web_products'
And this is the code I used
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
web_product = fields.Many2many('product.template', string="Website Products")
web_category = fields.Many2many('product.public.category', string="Website Categories")
def set_values(self):
res = super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].set_param('website_product_visibility.web_product', self.web_product)
self.env['ir.config_parameter'].set_param('website_product_visibility.web_category', self.web_category)
return res
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
ICPsudo = self.env['ir.config_parameter'].sudo()
web_product = ICPsudo.get_param('website_product_visibility.web_product')
web_category = ICPsudo.get_param('website_product_visibility.web_category')
res.update(
web_products=web_product,
web_categories=web_category
)
return res