How can I display log message in openerp web client?

前端 未结 5 1437
执念已碎
执念已碎 2021-01-23 21:42

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,          


        
5条回答
  •  不思量自难忘°
    2021-01-23 22:11

    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:

    
       
            
                warning.form
                warning
                
                
                    
    Warning warning form form new

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

提交回复
热议问题