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

Hi, im using Odoo 14, i want to pop up a warning window when compute field calculating incorrect results.

i try to raise UserError, but this will hinder the display of the page.and returning the following code in compute callback function will not have any effect.

notification = {
    'type': 'ir.actions.client',
    'tag': 'display_notification',
    'params': {
        'title': ('Warning'),
        'message': ('Sensor value exceeds threshold'),
        'sticky': True,
        'type': 'danger'
    },
}

how can i do in this function

is_check = fields.Integer(compute="_is_check")
def _is_check(self, *args):
    for record in self:
        record.is_check = 0
    notification = {
        'type': 'ir.actions.client',
        'tag': 'display_notification',
        'params': {
            'title': ('Warning'),
            'message': ('Sensor value exceeds threshold'),
            'sticky': True,
            'type': 'danger'
        },
    }
    return notification



頭像
捨棄
最佳答案

Hi,
Refer to the forum it shows how to add Compute Field Popup Error Message
https://www.odoo.com/forum/help-1/to-compute-field-popup-error-message-152075

Hope it helps

頭像
捨棄
最佳答案
is_warn = fields.Boolean("Is Warn", compute="_compute_is_warn")

def _compute_is_warn(self):
for rec in self:
if rec:
rec.is_warn = True
raise UserError(_("###### Error ######"))
else:
rec.is_warn = False

You can try withUserError with correct condition.
Hope it Helps.


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 25
6773
2
3月 24
1968
0
11月 23
1373
1
9月 23
2333
1
7月 22
1125