[IMP] hr: focus employee smart button on main flow

The current smartbutton is Employee(s) and it redirects to kanban view by default, no matter how many
employees a user / partner has. 9 out of 10 times a user / partner only has one linked employee, this
change renames the label to 'Employee' and redirects to the form view if there is only one employee
if there are more, the previous action is called

linked upgrade: odoo/upgrade#4363
this closes odoo/odoo#111439

Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
dasz
2023-03-07 18:02:37 +01:00
parent 99b09bcd42
commit 8451eabb67
4 changed files with 34 additions and 14 deletions
+11 -3
View File
@@ -32,10 +32,18 @@ class Partner(models.Model):
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': _('Related Employees'),
'name': _('Employee'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'view_mode': 'kanban,tree,form',
'domain': [('id', 'in', self.employee_ids.ids)],
'res_id': self.employee_ids.id,
'view_mode': 'form',
}
+19
View File
@@ -311,3 +311,22 @@ class User(models.Model):
company_id=self.env.company.id,
**self.env['hr.employee']._sync_user(self)
))
def action_open_employees(self):
self.ensure_one()
employees = self.employee_ids
if len(employees) > 1:
return {
'name': _('Related Employees'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'view_mode': 'kanban,tree,form',
'domain': [('id', 'in', employees.ids)],
}
return {
'name': _('Employee'),
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'res_id': employees.id,
'view_mode': 'form',
}
+1 -1
View File
@@ -9,7 +9,7 @@
<button name="action_open_employees" type="object" class="oe_stat_button" icon="fa-id-card-o" groups="hr.group_hr_user" attrs="{'invisible': [('employees_count', '=', 0)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value"><field name="employees_count"/></span>
<span class="o_stat_text">Employee(s)</span>
<span class="o_stat_text">Employee</span>
</div>
</button>
</div>
+3 -10
View File
@@ -234,13 +234,6 @@
<field name="view_id" ref="hr.res_users_view_form_profile"/>
</record>
<record id="hr_employee_action_from_user" model="ir.actions.act_window">
<field name="name">Employees</field>
<field name="res_model">hr.employee</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain">[('user_id', '=', active_id)]</field>
</record>
<record id="res_users_view_form" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
@@ -257,13 +250,13 @@
<!-- share is not correctly recomputed because it depends on fields of reified view => invisible before saving (id=False) -->
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<button name="%(hr_employee_action_from_user)d"
<button name="action_open_employees"
class="oe_stat_button"
icon="fa-users"
attrs="{'invisible': [('employee_count', '=', 0)]}"
context="{'active_test': False}"
type="action">
<field name="employee_count" widget="statinfo" string="Employee(s)"/>
type="object">
<field name="employee_count" widget="statinfo" string="Employee"/>
</button>
</xpath>
</field>