您的位置:首页 > 其它

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

2018-01-02 15:26 543 查看
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' : _('[b]Warning Message.')[/b]
  }
 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 按钮点击时显示确认信息:【直接加上"confirm"属性,就可以实现,点击按钮的时候,弹出窗口,提示“是否确认操作”的提示框】

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

相关参考:

http://www.cnblogs.com/cnshen/p/3205405.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: