Skip to Content
Menu
This question has been flagged
2 Replies
6939 Views

Hi, I'm using odoo 14.

I want to get the value coming from ir.config_parameter. I've made sure the parameter exists by checking in the system parameters directly. However I can't get my parameter value.


class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"
    setting = fields.Boolean(string='Setting')

    @api.model
    def get_values(self):
        res = super(SaleOrderLine, self).get_values()
        IrConfigParam = self.env['ir.config_parameter'].sudo()
        res.update({
            'setting': IrConfigParam.get_param('sale_order_multiple_pricelist', False),
    })
        return res       

I'm confused why the setting field always gets false

Avatar
Discard
Author Best Answer

I have solved this problem using compute. Just a guess, maybe using @api.model can't do because the function that uses that decorator will only be called when entering the form. In my case I want to affect the whole record without having to enter the form, so it can only be done if i'm using compute

setting = fields.Boolean(compute='_compute_setting', string='Setting')
def_compute_setting(self):    
    for rec in self:
        config = self.env['ir.config_parameter'].sudo()
        get_setting = config.get_param('sale_order_multiple_pricelist', False)
        rec.setting = get_setting
Avatar
Discard

Good, It can be done by onchange also as per reference of my previous answer.
Your get_values method is not called form any where. It will solved your issue if you call the get_value method.

Best Answer

Hi Muhammad Imron,

Can you please tell me when you "get_values" method called ?

Also use the IrConfigParam as it is created in the database.

Please use this reference.

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 24
6929
2
May 23
10409
0
Feb 21
2427
0
Apr 23
2691
1
Oct 21
2575