Skip to Content
Menu
This question has been flagged
4535 Views

Hi all,

Need a help how to implement menu badge in a odoo custom module .I have two user one manager and employee.How to implement this like existing project or leave management module.

Find solution ownway----- This may help to others ...enjoy.....


class hr_general(osv.osv):

    

    _name = 'hr.general'

    _inherit = ['ir.needaction_mixin']

    

    _columns = {

            'name':fields.many2one('hr.employee','Name',required=True),

            'state': fields.selection([('draft', 'To Submit'), ('reject', 'Rejected'), ('validate_hr', 'HR Approved'),('validate_mgr','Manager Approved')],'State'),

            'description':fields.char('Subject',required=True),

            'date_issue':fields.date('Date'),

            'details':fields.text('Details',required=True),

            'remarks':fields.text('Remarks'),

            'u_val':fields.integer(readonly=True)

            

                    }

    

    _defaults={

               'state':lambda *a: 'draft',

               'date_issue': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),

               'name': lambda s, cr, uid, c: uid,

               'u_val':lambda s, cr, uid, c: uid,

               }

    

    def action_button_validate(self,cr,uid,ids,context=None):

        for i in self.browse(cr,uid,ids):

            approv_obj=i.state

            print "@@@@@@@@@@@@",approv_obj

            if approv_obj=='validate_mgr':

                print "inside looop ##########@@@@@@@@@@@@",approv_obj

                self.write(cr,uid,ids,{'state':'validate_hr'})

            else:

                raise osv.except_osv(_('Error!'),_('You cannot Approve HR Approval before Approving Manager'))

    

    def action_button_draft(self,cr,uid,ids,context=None):

        self.write(cr,uid,ids,{'state':'draft'})

        return True 

    

    def action_button_reject(self,cr,uid,ids,context=None):

        self.write(cr,uid,ids,{'state':'reject'})

        return True

    

    def action_button_manager(self,cr,uid,ids,context=None):

        self.write(cr,uid,ids,{'state':'validate_mgr'})

        return True  

    

    @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 == "user1@gmail.com":

            return False  # don't show to Bob!

        return [('state', '=', 'draft')]

    

    @api.model

    def _needaction_count(self, domain=None):

        print "########################################### inside _needaction_count ",self

        if self._uid==1:

            return len(self.pool.get('hr.general').search(self._cr,self._uid,[('state','=','draft')]))

        else:

            return len(self.pool.get('hr.general').search(self._cr,self._uid,[('name','=',self._uid),('state','=','validate_hr')]))

hr_general()



Avatar
Discard