Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to use ir.needaction_mixin in my custom module for menu badges ?

By
Odoo
on 5/19/15, 8:06 AM 570 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()



Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/19/15, 8:06 AM
Seen: 570 times
Last updated: 6/11/15, 7:41 AM