[IMP] hr_contract: improve the contract general usability

Purpose fo the task is to improve the usability of hr contract and
automatic alert before contract expired
  -improve sign demo data
  -improve kanban state field in contract kanban
  -improve contract Form view ui
  -set first contract date on employee form
  -added the date of last completed contract on the new contract
  -improve signature request form
  -create automatic activity before the week of contract expired date

closes odoo/odoo#40789

Task: 2049413
Closes: #40789
Related: odoo/enterprise#7454
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Prakash Prajapati
2020-02-03 10:27:54 +00:00
committed by Yannick Tivisse
parent 5c0b13086e
commit 5ffbcd57ae
3 changed files with 66 additions and 32 deletions
+12 -5
View File
@@ -58,6 +58,7 @@ class Contract(models.Model):
hr_responsible_id = fields.Many2one('res.users', 'HR Responsible', tracking=True,
help='Person responsible for validating the employee\'s contracts.')
calendar_mismatch = fields.Boolean(compute='_compute_calendar_mismatch')
first_contract_date = fields.Date(related='employee_id.first_contract_date')
@api.depends('employee_id.resource_calendar_id', 'resource_calendar_id')
def _compute_calendar_mismatch(self):
@@ -108,8 +109,8 @@ class Contract(models.Model):
@api.model
def update_state(self):
self.search([
('state', '=', 'open'),
contracts = self.search([
('state', '=', 'open'), ('kanban_state', '!=', 'blocked'),
'|',
'&',
('date_end', '<=', fields.Date.to_string(date.today() + relativedelta(days=7))),
@@ -117,9 +118,15 @@ class Contract(models.Model):
'&',
('visa_expire', '<=', fields.Date.to_string(date.today() + relativedelta(days=60))),
('visa_expire', '>=', fields.Date.to_string(date.today() + relativedelta(days=1))),
]).write({
'kanban_state': 'blocked'
})
])
for contract in contracts:
contract.activity_schedule(
'mail.mail_activity_data_todo', contract.date_end,
_("The contract of %s is about to expire.") % contract.employee_id.name,
user_id=contract.hr_responsible_id.id or self.env.uid)
contracts.write({'kanban_state': 'blocked'})
self.search([
('state', '=', 'open'),
+10
View File
@@ -16,6 +16,16 @@ class Employee(models.Model):
calendar_mismatch = fields.Boolean(related='contract_id.calendar_mismatch')
contracts_count = fields.Integer(compute='_compute_contracts_count', string='Contract Count')
contract_warning = fields.Boolean(string='Contract Warning', store=True, compute='_compute_contract_warning', groups="hr.group_hr_user")
first_contract_date = fields.Date(compute='_compute_first_contract_date', groups="hr.group_hr_user")
@api.depends('contract_ids.state')
def _compute_first_contract_date(self):
for employee in self:
contracts = employee.contract_ids.filtered(lambda c: c.state != 'cancel')
if contracts:
employee.first_contract_date = min(contracts.mapped('date_start'))
else:
employee.first_contract_date = False
@api.depends('contract_id', 'contract_id.state', 'contract_id.kanban_state')
def _compute_contract_warning(self):
+44 -27
View File
@@ -19,14 +19,37 @@
<field name="arch" type="xml">
<data>
<div name="button_box" position="inside">
<field name="contract_warning" invisible="1"/>
<button name="%(act_hr_employee_2_hr_contract)d"
class="oe_stat_button"
icon="fa-book"
type="action"
groups="hr_contract.group_hr_contract_manager">
<field name="contracts_count" widget="statinfo" string="Contracts"/>
<div attrs="{'invisible' : [('first_contract_date', '=', False)]}" class="o_stat_info">
<span class="o_stat_text text-success" attrs="{'invisible' : [('contract_warning', '=', True)]}" title="In Contract Since"> In Contract Since</span>
<span class="o_stat_value text-success" attrs="{'invisible' : [('contract_warning', '=', True)]}">
<field name="first_contract_date" readonly="1"/>
</span>
<span class="o_stat_text text-danger" attrs="{'invisible' : [('contract_warning', '=', False)]}" title="In Contract Since">
In Contract Since
</span>
<span class="o_stat_value text-danger" attrs="{'invisible' : [('contract_warning', '=', False)]}">
<field name="first_contract_date" readonly="1"/>
</span>
</div>
<div attrs="{'invisible' : [('first_contract_date', '!=', False)]}" class="o_stat_info">
<span class="o_stat_value text-danger">
<field name="contracts_count"/>
</span>
<span class="o_stat_text text-danger">
Contracts
</span>
</div>
</button>
</div>
<xpath expr="//field[@name='user_id']" position="before">
<field name="first_contract_date" attrs="{'invisible' : [('first_contract_date', '=', False)]}" readonly="1"/>
</xpath>
<xpath expr="//field[@name='bank_account_id']" position="replace">
<field name="bank_account_id" context="{'display_partner':True}" attrs="{'invisible' : [('address_home_id', '=', False)]}"/>
</xpath>
@@ -140,37 +163,29 @@
<field name="active" invisible="1"/>
<field name="employee_id"/>
<field name="department_id"/>
<field name="job_id"/>
<field name="company_id" groups="base.group_multi_company"/>
</group>
<group>
<field name="company_id" groups="base.group_multi_company"/>
<field name="job_id"/>
<field name="date_start"/>
<field name="first_contract_date" attrs="{'invisible': ['|', ('first_contract_date', '=', False), ('first_contract_date', '=', 'date_start')]}"/>
<field name="date_end"/>
<field name="calendar_mismatch" invisible="1"/>
<label for="resource_calendar_id"/>
<div>
<field name="resource_calendar_id" required="1" nolabel="1"/>
<span attrs="{'invisible': ['|', ('calendar_mismatch', '=', False), ('state', '!=', 'open')]}"
class="fa fa-exclamation-triangle text-danger o_calendar_warning pl-3">
</span>
<span class="o_calendar_warning_tooltip text-danger">
Calendar Mismatch : The employee's calendar does not match this contract's calendar. This could lead to unexpected behaviors.
</span>
</div>
<field name="hr_responsible_id"/>
</group>
</group>
<notebook>
<page string="Contract Details" name="other">
<group>
<group name="duration_group" string="Contract Terms">
<field name="date_start"/>
<label for="date_end"/>
<div class="o_row">
<field name="date_end" nolabel="1"/>
<span class="text-muted">(If fixed-term contract)</span>
</div>
<field name="trial_date_end"/>
<field name="calendar_mismatch" invisible="1"/>
<label for="resource_calendar_id"/>
<div>
<field name="resource_calendar_id" required="1" nolabel="1"/>
<span attrs="{'invisible': ['|', ('calendar_mismatch', '=', False), ('state', '!=', 'open')]}"
class="fa fa-exclamation-triangle text-danger o_calendar_warning pl-3">
</span>
<span class="o_calendar_warning_tooltip text-danger">
Calendar Mismatch : The employee's calendar does not match this contract's calendar. This could lead to unexpected behaviors.
</span>
</div>
<field name="hr_responsible_id"/>
</group>
</group>
<group string="Notes">
<field name="notes" nolabel="1"/>
</group>
@@ -246,7 +261,6 @@
</div>
<div class="oe_kanban_content">
<div class="o_hr_contract_state">
<field name="kanban_state" widget="state_selection" />
<strong class="o_kanban_record_title">
<field name="name"/>
</strong>
@@ -256,6 +270,9 @@
</div>
<div class="oe_kanban_bottom_right">
<img t-att-src="kanban_image('hr.employee', 'image_128', record.employee_id.raw_value)" t-att-title="record.employee_id.value" t-att-alt="record.employee_id.value" width="24" height="24" class="oe_kanban_avatar float-right"/>
<span class="float-right mr4">
<field name="kanban_state" widget="state_selection"/>
</span>
</div>
</div>
<div class="oe_clear"></div>