美文网首页
odoo在.pyh和.js文件中点击按钮提示确认消息

odoo在.pyh和.js文件中点击按钮提示确认消息

作者: 王哈哈zzz | 来源:发表于2024-01-24 15:16 被阅读0次

场景:

在form页面操作时,有时候会点击丢失变更按钮,但有时候会误点击,这时候最好是有一个弹窗消息提示一下你是否确认取消这样的消息

思路:

在button按钮上设置一个消息提示,后台设置提示的内容

  • 企业微信截图_17061669037168.png

在.py文件实现:

在需要弹窗的按钮后面跟上这样一个属性:

<button name="action_cancel" icon="fa-close" string="Cancel" type="object" attrs="{'invisible':['|',('state','not in',('created','approved')),('is_creator','=',False)]}" class="oe_link" confirm_method="pre_cancel"/>

属性:confirm_method

后台对应一个属性名为pre_cancel的方法:

# 预取消确定
def pre_cancel(self):
    self.ensure_one() return _("Note: The document cannot be recovered if it has been cancelled, are you sure?")

这个方法只会在运行name=action_cancel之前,进行一个显示弹窗的动作,点击取消就无事发生,点击确认才会运行action_cancel的方法,大大简化了开发的难度!

在.js文件实现:

在需要弹窗的按钮后面跟上这样一个属性:

/** js文件 **/
import { useService } from "@web/core/utils/hooks";
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";

export class FormStatusIndicator extends Component {
 setup() {
     this.dialog = useService("dialog");
  }
  async discard() {
      this.dialog.add(ConfirmationDialog, {
          body: this.env._t("您确认要丢失变更吗?"),
          confirm: () => {this.props.discard();},
          cancel: () => {},
      });
  }
}
- image.png

相关文章

网友评论

      本文标题:odoo在.pyh和.js文件中点击按钮提示确认消息

      本文链接:https://www.haomeiwen.com/subject/ujhmodtx.html