1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息:

raise osv.except_osv(_('Error!'), _('Error Message.'))

示例代码:

#删除当前销售单,需要验证销售单的状态def unlink(self, cr, uid, ids, context=None):for rec in self.browse(cr, uid, ids, context=context):if rec.state not in ['draft']:raise osv.except_osv(_(u'警告!'),_(u'您不能删除以下状态的销售单 %s .')%(rec.state))if rec.create_uid.id != uid:raise osv.except_osv(_(u'警告!'),_(u'您不能删除他人创建的单据.'))return super(sale, self).unlink(cr, uid, ids, context)

2.字段的 onchange 事件中返回值,同时返回提示信息:

warning = {'title': _('Warning!'),'message' : _('Warning Message.')}return {'warning': warning, 'value': value}

示例代码:

@api.onchange('partner_id')def onchange_partner_id_warning(self):if not self.partner_id:returnwarning = {}title = Falsemessage = Falsepartner = self.partner_id# If partner has no warning, check its companyif partner.sale_warn == 'no-message' and partner.parent_id:partner = partner.parent_idif partner.sale_warn != 'no-message':# Block if partner only has warning but parent company is blockedif partner.sale_warn != 'block' and partner.parent_id and partner.parent_id.sale_warn == 'block':partner = partner.parent_idtitle = ("Warning for %s") % partner.namemessage = partner.sale_warn_msgwarning = {'title': title,'message': message,}if partner.sale_warn == 'block':self.update({'partner_id': False, 'partner_invoice_id': False, 'partner_shipping_id': False, 'pricelist_id': False})return {'warning': warning}if warning:return {'warning': warning}

3.视图中 button 按钮点击时显示确认信息:【直接加上"confirm"属性,就可以实现,点击按钮的时候,弹出窗口,提示“是否确认操作”的提示框】

<button name="cancel_voucher" string="Cancel Voucher" type="object" states="posted" confirm="Are you sure you want to unreconcile this record?"/>

实例代码:

<!-- This general view is used in Invoicing - Journal Entries - Journal Vouchers --><record model="ir.ui.view" id="view_voucher_form"><field name="name">account.voucher.form</field><field name="model">account.voucher</field><field name="arch" type="xml"><form string="Accounting Voucher" version="7.0"><header><button name="proforma_voucher" string="Post" states="draft" class="oe_highlight"/><button name="cancel_voucher" string="Cancel Voucher" type="object" states="posted" confirm="Are you sure you want to unreconcile this record?"/><button name="cancel_voucher" string="Cancel Voucher" states="draft,proforma" /><button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft"/><field name="state" widget="statusbar" statusbar_visible="draft,posted" statusbar_colors='{"proforma":"blue"}'/></header><sheet string="Accounting Voucher"><group col="4" colspan="4"><field name="partner_id" required="1" on_change="onchange_journal_voucher(line_ids, tax_id, amount, partner_id, journal_id, type)"/><field name="date" on_change="onchange_date(date, currency_id, payment_rate_currency_id, amount, company_id)"/><field name="journal_id" widget="selection" on_change="onchange_journal_voucher(line_ids, tax_id, amount, partner_id, journal_id, type)"/><field name="type" required="1"/><field name="name" colspan="2"/><field name="company_id" widget="selection" groups="base.group_multi_company"/><field name="reference"/><field name="number"/><field name="currency_id" groups="base.group_multi_currency"/><field name="account_id" widget="selection" invisible="True"/><field name="payment_rate_currency_id" invisible="1"/></group><notebook colspan="4"><page string="Voucher Entry"><field name="line_ids" on_change="onchange_price(line_ids, tax_id, partner_id)" context="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}"><tree string="Voucher Items" editable="bottom"><field name="account_id"/><field name="name"/><field name="amount" sum="Total Amount"/><field name="type"/><field name="account_analytic_id" groups="analytic.group_analytic_accounting"/></tree></field><group><field name="narration" nolabel="1" placeholder="Internal Notes"/><group class="oe_subtotal_footer oe_right" attrs="{'invisible':[('type','in',['payment', 'receipt', False])]}"><field name="tax_id" on_change="onchange_price(line_ids, tax_id, partner_id)" widget="selection" nolabel="1"/><field name="tax_amount" nolabel="1"/><div class="oe_subtotal_footer_separator"><label for="amount"/><button type="object" icon="terp-stock_format-scientific"   name="compute_tax" class="oe_link oe_edit_only" string="(Update)" attrs="{'invisible': [('state','!=','draft')]}"/></div><field name="amount" class="oe_subtotal_footer_separator" nolabel="1"/></group></group></page><page string="Journal Items" attrs="{'invisible': [('state','!=','posted')]}"><group col="4"><field name="period_id"/><field name="audit"/></group><field name="move_ids" readonly="1"><tree string="Journal Items"><field name="move_id"/><field name="ref"/><field name="date"/><field name="statement_id"/><field name="partner_id"/><field name="account_id"/><field name="name"/><field name="debit"/><field name="credit"/><field name="state"/><field name="reconcile_id"/></tree></field></page></notebook></sheet><div class="oe_chatter"><field name="message_follower_ids" widget="mail_followers"/><field name="message_ids" widget="mail_thread"/></div></form></field></record>
  • 有兴趣的小伙伴可以研究下,odoo的几种抛出异常的方式的区别:
from odoo.exceptions import except_orm, Warning, RedirectWarning,AccessDenied
AccessDenied
RedirectWarning
MissingError
except_orm
AccessError
DeferredException
ValidationError
Warning

Odoo----异常、错误、警告、提示、确认信息显示相关推荐

  1. PHP屏蔽错误警告提示

    @屏蔽法 @在php中一个抑制错误的符号,即便是你开启了报错功能,只要在错误语句之前加上@符号,便可屏蔽了错误信息.使用@抑制错误之前,会出现一个警告错误. 示例代码:@$tcdi = $tcdian ...

  2. odoo开发笔记 -- 异常、错误、警告、提示、确认信息显示

    odoo开发笔记 -- 异常.错误.警告.提示.确认信息显示 参考文章: (1)odoo开发笔记 -- 异常.错误.警告.提示.确认信息显示 (2)https://www.cnblogs.com/he ...

  3. U3d引擎崩溃、异常、警告、BUG与提示总结及解决方法

    此贴会持续更新,都是项目中常会遇到的问题,总结成贴,提醒自己和方便日后检查,也能帮到有需要的同学. 若各位有啥好BUG好异常好警告好崩溃可以分享的话,请多多指教.xuzhiping7#qq.com. ...

  4. 完全卸载office(手动卸载)、微软工具自动卸载、安装Office时提示错误1310、写入文件“GROOVEEX“时错误,请确认您有权限访问该目录

    方法1.下面是微软提供的手动完全卸载office软件(自己一步一步按照操作卸载) https://support.office.com/zh-cn/article/%e6%89%8b%e5%8a%a8 ...

  5. 根据用户输入的账号和密码,确认是否成功登录?若正确,提示“恭喜您,登录成功!”;若错误,提示“账号或密码输入错误,请重新输入!”;若错误输入超过3次,则提示“今天输入已经超过3次

    根据用户输入的账号和密码,确认是否成功登录?若正确,提示"恭喜您,登录成功!":若错误,提示"账号或密码输入错误,请重新输入!":若错误输入超过3次,则提示&q ...

  6. PHP中间件ICE,ICE的安装配置,ICE常见编译和运行(异常)错误(自测Php版本安装部分,因为php版本跟ice版本不一样失败)

    ICE(Internet Communications Engine)是Zeroc提供的一款高性能的中间件.使用ICE能使得php(或c++,java,python)与java,c++,.net,py ...

  7. AngularJS 表单数据验证及错误信息提示

    一.表单验证基本原理 表单验证包括两个主题: 定义验证规则,验证数据有效性. 显示验证结果,把验证结果以友好的方式显示给用户. H5内置一些验证功能,并会显示内置的错误提示信息,先要禁用它,在< ...

  8. 织梦Dedecms错误警告:连接数据库失败,可能数据库密码不对

    很多站长在使用dedecms的过程中会遇到这样的错误提示"DedeCMS Error Track:DedeCMS错误警告:连接数据库失败,可能数据库密码不对或数据库服务器出错!", ...

  9. 总结:整理 oracle异常错误处理

    5.1 异常处理概念 5.1.1 预定义的异常处理 5.1.2 非预定义的异常处理 5.1.3 用户自定义的异常处理 5.1.4  用户定义的异常处理 5.2 异常错误传播 5.2.1 在执行部分引发 ...

  10. java 非法操作异常_电脑提示非法操作怎么办 电脑系统故障解决方法【详解】

    电脑提示非法操作怎么办? 在电脑操作中,出现"非法操作"提示的几率比蓝屏现象要多出一筹.造成"非法操作"的原因主要出自软件.当一个程序访问其内存地址空间之外的内 ...

最新文章

  1. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXX
  2. Deep Reinforcement Learning 深度增强学习资源
  3. 真是一分钱一分货 NVme SSD都有哪些优势?
  4. loop 伪设备 挂在文件系统
  5. oracle rac fail,Oracle RAC Load Balance , Fail Over测试
  6. [导入]写了个img2ppt的demo,为写PDF2PPT做准备
  7. (01)C++之设计模式演变
  8. 《神经网络》学习笔记
  9. 在create-react-app的脚手架里面使用scss
  10. python3.5.4安装_linux-centos系统下安装python3.5.4步骤
  11. Modelsim SE 的下载安装与注册
  12. 如何在Windows系统电脑安装原版Chrome OS
  13. 关系图谱在贝壳的构建和应用
  14. 本期推送应该是全网最全的奥特曼表情包合集
  15. mysql 增加分区_MySql数据分区操作之新增分区操作
  16. 苦熬31年终于登陆科创板!WPS如何一步步熬到了今天?
  17. P4565 [CTSC2018]暴力写挂 题解
  18. blob格式照片在前端页面的显示
  19. 手把手微信机器人部署教学
  20. java判断单元格是否是日期_Excel单元格,日期/时间返回Int而不是日期/时间字符串...

热门文章

  1. unity四种Text总结
  2. 1、二进制安装k8s
  3. 查看linux发行版
  4. 宣化科技职业学院计算机哪个校区,宣化科技职业学院宿舍怎么样
  5. 逸仙时空上翻的一个旧帖子
  6. 坑爹公司大盘点 --- 转自拉钩
  7. JS的DOM操作1--获取元素与修改元素(附带动图案例)
  8. 云与瘦客户机 未来IT数据安全延续
  9. Windows10家庭版 提升管理员权限
  10. 网上发现的一个 《Flashflex大全》