创建一个模块以保存消息并以以下形式显示它们:from osv import osvfrom osv import fieldsfrom 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 successfulThis 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 Truedef 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_idwhen 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 linkCreate a module to save messages and show them in form:from osv import osvfrom osv import fieldsfrom 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 resCreate 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客户端中显示日志消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 20:35