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}

示例代码:

    def onchange_pricelist_id(self, cr, uid, ids, pricelist_id, order_lines, context=None):
context = context or {}
if not pricelist_id:
return {}
value = {
'currency_id': self.pool.get('product.pricelist').browse(cr, uid, pricelist_id, context=context).currency_id.id
}
if not order_lines:
return {'value': value}
warning = {
'title': _('Pricelist Warning!'),
'message' : _('If you change the pricelist of this order (and eventually the currency), prices of existing order lines will not be updated.')
}
return {'warning': warning, 'value': value}

3.视图中 button 按钮点击时显示确认信息:

 <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>

openerp学习笔记 错误、警告、提示、确认信息显示的更多相关文章

  1. Entity Framework学习笔记——错误汇总

    之前的小项目做完了,到了总结经验和更新学习笔记的时间了.开始正题之前先啰嗦一下,对之前的学习目标进行一个调整:“根据代码生成表”与“生成数据库脚本和变更脚本”合并为“Code First模式日常使用篇 ...

  2. C#学习笔记3:提示“截断字符串或二进制数据”错误解决方法

    1.调试程序如出现“截断字符串或二进制数据”的关于数据库的错误,可以先试一试修改数据库中字符定义的长度. 2.使用ManualResetEvent前需导入 命名空间System.Threading; ...

  3. openerp学习笔记 tree视图增加复选处理按钮

    wizard:用于确认或选择 wizard/sale_multi_action.py # -*- encoding: utf-8 -*-from openerp.osv import fields, ...

  4. JavaScript高级程序设计学习笔记--错误处理与调试

    try-catch语句 只要代码中包含finally子句,则无论try或catch语句块中包含什么代码--甚至return语句,都不会阻止finally子句的执行,来看下面这个函数: function ...

  5. openerp学习笔记 调用工作流

    获取工作流服务:wf_service = netsvc.LocalService("workflow")删除对象对应记录的工作流:wf_service.trg_delete(uid ...

  6. openerp学习笔记 跟踪状态,记录日志,发送消息

    跟踪状态基础数据: kl_qingjd/kl_qingjd_data.xml <?xml version="1.0"?><openerp>    <d ...

  7. javascript学习笔记——chrome等提示找不到“getElementsByTagName”的一种解决方法

    最近学习是写了一个小网页,前台有个下拉框是通过后天的xml配置的,在写好代码后使用发现在IE9以及之前的IE浏览器都可以正常获取,但是IE10,chrome和firefox都会在获取一个标签时报get ...

  8. Tomcat学习笔记 - 错误日志 - Tomcat访问Manager apps出现401 Unauthorized错误

    原因是配置文件中未指定管理员身份. 打开tomcat>conf>tomcat-user.xml文件,添加如下代码: <role rolename="admin-gui&qu ...

  9. Tomcat学习笔记 - 错误日志 - Tomcat安装版安装后第二次启动后闪退(转)-- javac不是内部或外部命令 -- 配置java环境教程

    如果安装成功并且安装完成第一次启动是成功的,第二次就闪退的话,原因之一是没有配置java的环境.在网上找的配制方法有很多错误,测试javac命令时候会提示不是内部或外部命令,找到一个正确的教程.如下, ...

随机推荐

  1. JD轮播图代码

    <!DOCTYPE html>   <html>   <head>   <title>jd网站的轮播图效果</title>   <me ...

  2. [经典算法] 排列组合-N元素集合的M元素子集

    题目说明: 假设有个集合拥有n个元素,任意的从集合中取出m个元素,则这m个元素所形成的可能子集有那些? 题目解析: 假设有5个元素的集合,取出3个元素的可能子集如下: {1 2 3}.{1 2 4 } ...

  3. linux 命令行发送邮件及附件

    环境 本机安装sendmail了, 但是没有启动. 其他机器上有mail server, 并且已经把本机加到open relay列表中了, 可以通过该mail server发送邮件.做法如下:1. 安 ...

  4. DNS resolving 占用大量日志

    公司内部DNS配置好后,测试解析正常,只是几乎每秒都有无法解析的日志产生.但分析日志时发现,每天的日志都有2G左右.日志中几乎全是类似network unreachable resolving 'ww ...

  5. mysql_DML_update

    update  表名  set  字段=XX where....;(记得加条件不安全改了) 多个字段: update  表名  set  字段1=XX,字段2= where....;(记得加条件不安全 ...

  6. Java时间戳与日期格式字符串的互转

    上代码: import java.text.SimpleDateFormat; import java.util.Date; public class DateUtil { /** * 时间戳转换成日 ...

  7. hdu-5690 All X(快速幂+乘法逆元)

    题目链接: All X Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Pro ...

  8. Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed

    最近在用Python开发自己的博客,需要用到Python生成验证码,当然肯定要用到Python的图形处理库PIL,因为我用的是windows. 所以在安装好pil之后就开始写,就按照题目所说出现了Th ...

  9. python 打包exe注意的问题

    教程百度.谷歌都有,本文讲讲安装时出错的问题. 教程:http://keliang.blog.51cto.com/3359430/661884 1.cxfreeze 找不到路径时: 需要修改Scrip ...

  10. Linux 字符设备控制技术

    字符设备控制技术 一.字符设备控制理论 1.作用 大部分设备除了具有<读写设备>的能力,还应该有<控制设备>的能力.比如改变 波特率 2. 应用程序接口 在用户空间中使用 Io ...