Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to allow manager to access his employees or his department only?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
securityhrv7
14 Respostes
25849 Vistes
Avatar
Elmasry

I'm new in openERP and i use openERP V7

i have hr manager M1 and under him 3 employees emp1 , emp2 and emp3

and another hr manager M2 under him >> emp4 , emp5 , emp6

i want M1 just see Timesheets of himself and emp1 , emp2 and emp3 only

and M2 just see Timesheets of himself and emp4 , emp5 , emp6

i tried to use record rules but i couldn't create the expression right

also if i want to let him access his department only what can i do?

any one can help me please

thanks to all in advance

anyone can help me?

the answer work with "Timesheets to Validate" menu only

and now I want to do same record rule on "Timesheet Activities" menu but no result I try to add this line to hr.analytic.timesheet model 'employee_id': fields.many2one('hr.employee', 'Employee', required=True), add the result was that no records in tree.


please help me to understand how to do it and explain me in more detaisls how can i create domains like that easily.

3
Avatar
Descartar
Mihalache Ciprian

Hello. Did u managed to resolve this problem ?

"I try to add this line to hr.analytic.timesheet model 'employee_id': fields.many2one('hr.employee', 'Employee', required=True)"

Where did you modify this. What file path... or menu ?

Avatar
saad
Best Answer

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

3
Avatar
Descartar
Elmasry
Autor

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

Look on my updated answer.

Elmasry
Autor

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

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
Autor

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
Autor

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

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

Mihalache Ciprian

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

"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

Avatar
Nimesh Contractor
Best Answer

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

6
Avatar
Descartar
Elmasry
Autor

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

Avatar
Horwath & Associados, SROC, Lda
Best Answer

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

1
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Creating user groups that allow users to access several companies
security v7
Avatar
Avatar
1
de febr. 25
8474
How can I import photos of my employees into HR module? Solved
hr v7
Avatar
Avatar
Avatar
Avatar
3
d’oct. 23
14177
Why does OpenERP store passwords in plain text by default
security v7
Avatar
Avatar
Avatar
Avatar
Avatar
4
de març 15
10116
There is no reference available for base.element
hr v7
Avatar
0
de març 15
4940
How do I send out emails to all followers when an update happens in the HR (hiring) module)
hr v7
Avatar
Avatar
1
de març 15
8194
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now