Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show a menu badge in OpenERP/Odoo?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 515
    Comment on it

    If you want to show a menu badge in OpenERP/Odoo then you should follow the below code:

     

    class Shiva(models.Model):
        _name = 'Shiva'
        _inherit = ['ir.needaction_mixin']
    
        STATES = [
            ('healthy', "Healthy Shiva"),
            ('sick', "Sick Shiva"),
        ]
    
        name = fields.Char(required=True)
        state = fields.Selection(STATES, default='healthy')
    
        @api.model
        def _needaction_domain_get(self):
            """
            Show a count of sick horses on the menu badge.
            An exception: don't show the count to Bob,
            because he worries too much!
            """
            if self.env.user.name == "Bob":
                return False  # don't show to Bob!
            return [('state', '=', 'sick')]
    After that making use of the domain argument in this file.
    
    def _needaction_count(self, domain=None):
        """
        Count all objects in a view, deducting a dozen
        before displaying on the badge
        (we don't want to alarm people with big numbers)
        """
        return self.search_count(domain or []) - 12

     

    Note- Rather than defining domain_get method you can alternatively define a count method, it will return a number of your choice directly in odoo. As shown in screenshot below:

    How to show a menu badge in OpenERP/Odoo?

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: