Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
9873 มุมมอง

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มี.ค. 24
9065
2
พ.ค. 23
12312
0
ก.พ. 21
3260
0
เม.ย. 23
4166
1
ต.ค. 21
3414