Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
securityhrv7
14 Respuestas
25941 Vistas
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
Mejor respuesta

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
Mejor respuesta

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
Mejor respuesta

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

1
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Creating user groups that allow users to access several companies
security v7
Avatar
Avatar
1
feb 25
8583
How can I import photos of my employees into HR module? Resuelto
hr v7
Avatar
Avatar
Avatar
Avatar
3
oct 23
14298
Why does OpenERP store passwords in plain text by default
security v7
Avatar
Avatar
Avatar
Avatar
Avatar
4
mar 15
10229
There is no reference available for base.element
hr v7
Avatar
0
mar 15
5078
How do I send out emails to all followers when an update happens in the HR (hiring) module)
hr v7
Avatar
Avatar
1
mar 15
8267
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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