Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
825 Lượt xem

Hi all, need some help... I have a Selection Field called "Available" with Badge widget "Yes" "No" and Checkbox Field. I try to change Badge to "Yes" if Checkbox is not set nad change Badge to "No" if Checkbox is set. Any help is gtreatly appreciated.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Gives me an error

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
available = fields.Selection([('yes', 'Yes'), ('no', 'No')], string='Available', default='no', compute='_compute_available_badge')
    checkbox_field = fields.Boolean(string='Checkbox Field')

    @api.depends('checkbox_field')
    def _compute_available_badge(self):
        for record in self:
            if record.checkbox_field:
                record.available = 'no'
            else:
                record.available = 'yes'
   


Add this compute, it will always change the selection field value based on the boolean field

Edited : Apologise, I forgot to add the compute to the field definition.. please try it now, I have edited the code

Ảnh đại diện
Huỷ bỏ
Tác giả

Still can't make it to work ((