跳至內容
選單
此問題已被標幟
2 回覆
9777 瀏覽次數

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

頭像
捨棄
作者 最佳答案

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
頭像
捨棄

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.

最佳答案

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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
3月 24
8957
2
5月 23
12254
0
2月 21
3184
0
4月 23
4087
1
10月 21
3378