Files
odoo_source/addons/hr/models/res_partner.py
T
Yannick Tivisse e8c48f824e [IMP] hr: Remove address_home_id field
Improve usability of employee form. It is confusing for end users
to create another record to encode the employee address.

Move all the private information on the hr.employee record itself.

Remove the M2O address_home_id.

TaskID: 3101400
2023-07-05 14:21:28 +02:00

36 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
class Partner(models.Model):
_inherit = ['res.partner']
employee_ids = fields.One2many(
'hr.employee', 'work_contact_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 _compute_employees_count(self):
for partner in self:
partner.employees_count = len(partner.employee_ids)
def action_open_employees(self):
self.ensure_one()
if len(self.employee_ids) > 1:
return {
'name': _('Related Employees'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'view_mode': 'form',
'domain': [('id', 'in', self.employee_ids.ids)],
}
return {
'name': _('Employee'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'res_id': self.employee_ids.id,
'view_mode': 'form',
}