Files
odoo_source/addons/hr/models/res_partner.py
T
Yannick Tivisse 24713b76b5 [REV] fleet: Revert multiple fleet mechanism
I don't get why you don't get it...

Partial revert of the taskID: 2415309
Com PR: https://github.com/odoo/odoo/pull/70313
Ent PR: https://github.com/odoo/enterprise/pull/18114
Upg PR: https://github.com/odoo/upgrade/pull/2447

closes odoo/odoo#75475

Related: odoo/enterprise#20406
Related: odoo/upgrade#2765
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2021-08-25 12:20:39 +00:00

42 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo.exceptions import AccessError
class Partner(models.Model):
_inherit = ['res.partner']
employee_ids = fields.One2many(
'hr.employee', 'address_home_id', string='Employees', groups="hr.group_hr_user",
help="Related employees based on their private address")
employees_count = fields.Integer(compute='_compute_employees_count', groups="hr.group_hr_user")
def name_get(self):
""" Override to allow an employee to see its private address in his profile.
This avoids to relax access rules on `res.parter` and to add an `ir.rule`.
(advantage in both security and performance).
Use a try/except instead of systematically checking to minimize the impact on performance.
"""
try:
return super(Partner, self).name_get()
except AccessError as e:
if len(self) == 1 and self in self.env.user.employee_ids.mapped('address_home_id'):
return super(Partner, self.sudo()).name_get()
raise e
def _compute_employees_count(self):
for partner in self:
partner.employees_count = len(partner.employee_ids)
def action_open_employees(self):
self.ensure_one()
return {
'name': _('Related Employees'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'view_mode': 'kanban,tree,form',
'domain': [('id', 'in', self.employee_ids.ids)],
}