コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
9785 ビュー

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
8963
2
5月 23
12256
0
2月 21
3185
0
4月 23
4087
1
10月 21
3380