odoo verification friendly prompt

There is a situation in odoo that limits the upload file to xlsx, xls, but sometimes even if an error is reported, its record still exists.
This function not only reminds but also can control the air.

    @api.onchange('attachment')
    def _onchange_attachment(self):
        if self.attachment:
            if not self.store_fname.endswith(('xls', 'xlsx')):
                self.attachment = False
                warning = {
    
    
                    'title': "文件验证警告",
                    'message': "上传文件格式有误, 仅支持xlsx, xls文件",
                }
                return {
    
    'warning': warning}

There is also the case that when the date is verified, the past can be verified even if it is reminded, and it is a verification problem when it is saved, so the data that fails the verification is directly blanked.

        @api.onchange('plan_start')
    def _onchange_plan_start(self):
        if self.plan_start:
            if self.plan_start < fields.Date.today():
                self.plan_start = False
                warning = {
    
    
                    'title': "数据验证警告",
                    'message': "计划开始不能小于当前日期",
                }
                return {
    
    'warning': warning}

It is not easy to make, please like and encourage

Guess you like

Origin blog.csdn.net/weixin_42464956/article/details/108401221