如何在openerp Web客户端中显示日志消息? [英] How can I display log message in openerp web client?
问题描述
创建产品对象后,我尝试显示一条消息,告诉用户具有product.name的产品创建成功 这是代码:
def log_prod(self, cr, uid, ids, context=None):
product=self.pool.get('product.product').browse(cr, uid, ids)
self.log(cr, uid, ids , _("Product %s has been created") % product.name , context=context)
return True
def create(self, cr, uid, data, context=None):
new_id = super(product_product,self).create(cr, uid, data, context)
self.log_prod(cr,uid,new_id,context)
return new_id
当我创建产品时,什么都没出现
但是,在尝试创建收货后,出现了创建产品的日志消息,创建后如何在产品显示页面中显示日志消息?
我遇到了这个问题,但是这种方式对我有帮助,非常好: 从此链接 >
创建一个模块以保存消息并以以下形式显示它们:
from osv import osv
from osv import fields
from openerp.tools.translate import _
WARNING_TYPES = [('warning','Warning'),('info','Information'),('error','Error')]
class warning(osv.osv_memory):
_name = 'warning'
_description = 'warning'
_columns = {
'type': fields.selection(WARNING_TYPES, string='Type', readonly=True),
'title': fields.char(string="Title", size=100, readonly=True),
'message': fields.text(string="Message", readonly=True)}
_req_name = 'title'
def _get_view_id(self, cr, uid):
"""Get the view id
@return: view id, or False if no view found
"""
res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'osc_integ', 'warning_form')
return res and res[1] or False
def message(self, cr, uid, id, context):
message = self.browse(cr, uid, id)
message_type = [t[1]for t in WARNING_TYPES if message.type == t[0]][0]
print '%s: %s' % (_(message_type), _(message.title))
res = {
'name': '%s: %s' % (_(message_type), _(message.title)),
'view_type': 'form',
'view_mode': 'form',
'view_id': self._get_view_id(cr, uid),
'res_model': 'warning',
'domain': [],
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': message.id
}
return res
def warning(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'warning'})
res = self.message(cr, uid, id, context)
return res
def info(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'info'})
res = self.message(cr, uid, id, context)
return res
def error(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'error'})
res = self.message(cr, uid, id, context)
return res
创建视图表单XML:
<openerp>
<data>
<record id="warning_form" model="ir.ui.view">
<field name="name">warning.form</field>
<field name="model">warning</field>
<field eval="20" name="priority"/>
<field name="arch" type="xml">
<form string="Warning" version="7.0">
<field name="message" nolabel="1" />
<footer>
<button string="OK" class="oe_highlight" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_warning">
<field name="name">Warning</field>
<field name="res_model">warning</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="warning_form" />
<field name="target">new</field>
</record>
</data>
</openerp>
最后,您可以在需要的任何地方调用方法:
return self.pool.get('warning').info(cr, uid, title='Export imformation', message="%s products Created, %s products Updated "%(str(prod_new),str(prod_update)))
I try to display a message after create a product object that tell user product with product.name is created successful This is the code:
def log_prod(self, cr, uid, ids, context=None):
product=self.pool.get('product.product').browse(cr, uid, ids)
self.log(cr, uid, ids , _("Product %s has been created") % product.name , context=context)
return True
def create(self, cr, uid, data, context=None):
new_id = super(product_product,self).create(cr, uid, data, context)
self.log_prod(cr,uid,new_id,context)
return new_id
when I created the product no thing was appeared
But after that I tried to create an incoming shipment, the log message for the product creation was appeared, how I can display the log message in the product display page after create it?
I have had this problem, but this way helped me and is wonderful: from this link
Create a module to save messages and show them in form:
from osv import osv
from osv import fields
from openerp.tools.translate import _
WARNING_TYPES = [('warning','Warning'),('info','Information'),('error','Error')]
class warning(osv.osv_memory):
_name = 'warning'
_description = 'warning'
_columns = {
'type': fields.selection(WARNING_TYPES, string='Type', readonly=True),
'title': fields.char(string="Title", size=100, readonly=True),
'message': fields.text(string="Message", readonly=True)}
_req_name = 'title'
def _get_view_id(self, cr, uid):
"""Get the view id
@return: view id, or False if no view found
"""
res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'osc_integ', 'warning_form')
return res and res[1] or False
def message(self, cr, uid, id, context):
message = self.browse(cr, uid, id)
message_type = [t[1]for t in WARNING_TYPES if message.type == t[0]][0]
print '%s: %s' % (_(message_type), _(message.title))
res = {
'name': '%s: %s' % (_(message_type), _(message.title)),
'view_type': 'form',
'view_mode': 'form',
'view_id': self._get_view_id(cr, uid),
'res_model': 'warning',
'domain': [],
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': message.id
}
return res
def warning(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'warning'})
res = self.message(cr, uid, id, context)
return res
def info(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'info'})
res = self.message(cr, uid, id, context)
return res
def error(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'error'})
res = self.message(cr, uid, id, context)
return res
Create View form XML:
<openerp>
<data>
<record id="warning_form" model="ir.ui.view">
<field name="name">warning.form</field>
<field name="model">warning</field>
<field eval="20" name="priority"/>
<field name="arch" type="xml">
<form string="Warning" version="7.0">
<field name="message" nolabel="1" />
<footer>
<button string="OK" class="oe_highlight" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_warning">
<field name="name">Warning</field>
<field name="res_model">warning</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="warning_form" />
<field name="target">new</field>
</record>
</data>
</openerp>
And at last you can call method every where you need:
return self.pool.get('warning').info(cr, uid, title='Export imformation', message="%s products Created, %s products Updated "%(str(prod_new),str(prod_update)))
这篇关于如何在openerp Web客户端中显示日志消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!