Odoo Help

3

4
14 Answers
3
Avatar

saad Morocco

--saad--

1028
| 5 4 10
Casablanca, Morocco
--saad--
saad Morocco
3/28/13, 3:11 PM

For Timesheets access, add a record rule with ['|',('employee_id.user_id','=',user.id),('employee_id.parent_id.user_id','=',user.id)] in domain filter field.

Adding the employee_id field is not sufficient, you should fill it by overriding the on_change_user_id method, I suppose that your employees are linked to users and you have added employee_id field in hr.analytic.timesheet form view and tree view.

In .py file:

def on_change_user_id(self, cr, uid, ids, user_id):
    if not user_id:
        return {}
    context = {'user_id': user_id}
    emp = self.pool.get("hr.employee").search(cr,uid,[('user_id','=',user_id)])
    return {'value': {
        'product_id': self. _getEmployeeProduct(cr, uid, context),
        'product_uom_id': self._getEmployeeUnit(cr, uid, context),
        'general_account_id': self._getGeneralAccount(cr, uid, context),
        'journal_id': self._getAnalyticJournal(cr, uid, context),
        'employee_id': emp and emp[0],
    }}

You should also fill the employee_id field when you are creating Timesheet Activities form timesheet form by overrinding the create method:

def create(self, cr, uid, vals, context=None):
    if context is None:
        context = {}
    emp_obj = self.pool.get('hr.employee')
    emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
    vals['employee_id'] = emp_id and emp_id[0]
    ename = ''
    if emp_id:
        ename = emp_obj.browse(cr, uid, emp_id[0], context=context).name
    if not vals.get('journal_id',False):
       raise osv.except_osv(_('Warning!'), _('No \'Analytic Journal\' is defined for employee %s \nDefine an employee for the selected user and assign an \'Analytic Journal\'!')%(ename,))
    if not vals.get('account_id',False):
       raise osv.except_osv(_('Warning!'), _('No analytic account is defined on the project.\nPlease set one or we cannot automatically fill the timesheet.'))
    return super(hr_analytic_timesheet, self).create(cr, uid, vals, context=context)

At this moment, the same rule can be applied on Timesheet Activities and Timesheets

9 Comments
Elmasry Egypt
3/29/13, 2:39 PM

thank you very match saad

please could u explain me ho to create expression like that , i can do it but dt understand how and can't know the attributes that i can work on it, how can i know them.

i will be so thankfull if u help me more to learn it

saad Morocco
4/4/13, 7:49 AM

Look on my updated answer.

Elmasry Egypt
4/7/13, 7:43 AM

thanks very much Saad i'm so happy to see your update but after i do that i faced problem that the timesheets and which created from My Timesheet form is not filtered right under timesheet activities. have u any idea why?! can i connect u through linked in , Gmail or facebook?!

saad Morocco
4/8/13, 8:44 AM

yes, the 'onchange_user_id' method is not triggered when you create timesheet activities from timesheet form, so the 'employee_id' field remains empty. You should manually add a value for employee_id in the create method. I will update my answer to be more complete. You can find me in the french community or moroccan community.

Elmasry Egypt
4/8/13, 9:34 AM

thanks my Saad i tested your code before update but "change_user_id" is already exist but i understand your code and what you aim to so i do it by my way and it is run correctly. you update is very good but still have logical error cuz the user_id in creat method 'll be always the user id of the user who log in system .. so if manger create timesheets for his employee so the employee id 'll be id of manger not employee.

Elmasry Egypt
4/8/13, 9:41 AM

so we have 3 steps to avoid it

1- add global variable --> _employee=0 ..... 2- assign employee id to it in onchange_user_id method --> self._employee = self.pool.get("hr.employee").search(cr,uid,[('user_id','=',user_id)]) .... 3- add it to vals in create method --> vals['employee_id']=self._employee ... and if you have Gmail or linked in or FB it 'll be great thanks brother

Mihalache Ciprian Romania
9/18/13, 4:49 AM

did anyone managed to do this ? Please add a video support on youtube. Thanks.

Mihalache Ciprian Romania
12/19/13, 4:16 AM

I modified the file hr_timesheet.py and restarted openerp server. I added this rule on timesheet activities ['|', '|', ('employee_id.user_id','=',user.id),('message_follower_ids','in',[user.partner_id.id]),('employee_id.parent_id.user_id','=',user.id)] but I get this error invalid field 'employee_id.user_id' in leaf

Mihalache Ciprian Romania
12/19/13, 5:01 AM

"and you have added employee_id field in hr.analytic.timesheet form view and tree view"

How to add this because on this model you cannot add employee_id ?

http://i.imgur.com/Ho5TKhT.jpg

6
Bista Support India
4/1/13, 3:02 PM

To show his own department you can set the domain on the department field

and access rule may be like as follows..

<record id="emp_rule_personal_record" model="ir.rule">
    <field name="name">Personal Leads</field>
    <field ref="model_yourobject" name="model_id"/>
    <field name="domain_force">['|',('employee_id.user_id','=',user.id),('employee_id.parent_id.user_id','=',user.id),('user_id','=',False)]</field>
    <field name="groups" eval="[(4, ref('yourGroupRef'))]"/>
</record>

Hope this will help you..

1 Comment
Elmasry Egypt
4/1/13, 9:03 PM

my friend this domain dt work with "Timesheet Activities" menu cuz no employee_id field in the model and when i created it manualy i find it empty field and could u explain me how i can create the domain

0

Is it possible to do this with roles? If so, how? 

Ask a Question
Writer
Tags
Keep Informed
2 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now