diff options
| author | Anh Thao Pham (pta) <pta@odoo.com> | 2020-02-11 16:00:53 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2020-04-20 10:32:45 +0000 |
| commit | 3bd345597fa932abdaf780f72bacf331690f549b (patch) | |
| tree | b94e535b7ad2a7d4667595341ff66b5eded537cc /addons/hr_work_entry | |
| parent | f50c3298bb938cd044636956719d986bb91160ae (diff) | |
[REF] hr*: convert onchange methods to stored-editable computed fields
Impacted modules:
hr, hr_contract, hr_recruitment, hr_payroll, fleet, hr_skills, hr_appraisal, ....
Several onchanges have been converted to computed fields in the following modules :
Community :
- hr
- hr_contract
- hr_recruitment
- hr_work_entry
- hr_maintenance
- hr_expense
- hr_expense_check
- hr_holidays
- sale_expense
- account_analytic_default_hr_expense
Enterprise:
- hr_contract_salary
- hr_referral
- hr_payroll
- hr_payroll_expense
- test_l10n_be_hr_payroll_account
There are still 2 onchanges with complex behavior that couldn't be converted easily:
- an onchange that updates "tz" (timezone) that is defined as a related field
to "resource_id.tz". Apparently it is useless except to initialize the default
value of "tz".
- an onchange that updates "name" that is defined as a related field to
"resource_id.name".
the applicant.
closes odoo/odoo#45414
Taskid: 2169099
Related: odoo/enterprise#8572
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/hr_work_entry')
| -rw-r--r-- | addons/hr_work_entry/models/hr_work_entry.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/addons/hr_work_entry/models/hr_work_entry.py b/addons/hr_work_entry/models/hr_work_entry.py index dafb2c0793d..368214225ce 100644 --- a/addons/hr_work_entry/models/hr_work_entry.py +++ b/addons/hr_work_entry/models/hr_work_entry.py @@ -16,8 +16,8 @@ class HrWorkEntry(models.Model): active = fields.Boolean(default=True) employee_id = fields.Many2one('hr.employee', required=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") date_start = fields.Datetime(required=True, string='From') - date_stop = fields.Datetime(string='To') - duration = fields.Float(compute='_compute_duration', inverse='_inverse_duration', store=True, string="Period") + date_stop = fields.Datetime(compute='_compute_date_stop', store=True, readonly=False, string='To') + duration = fields.Float(compute='_compute_duration', store=True, string="Period") work_entry_type_id = fields.Many2one('hr.work.entry.type') color = fields.Integer(related='work_entry_type_id.color', readonly=True) state = fields.Selection([ @@ -40,19 +40,15 @@ class HrWorkEntry(models.Model): for rec in self: rec.conflict = rec.state == 'conflict' - @api.onchange('duration') - def _onchange_duration(self): - self._inverse_duration() - @api.depends('date_stop', 'date_start') def _compute_duration(self): for work_entry in self: work_entry.duration = work_entry._get_duration(work_entry.date_start, work_entry.date_stop) - def _inverse_duration(self): - for work_entry in self: - if work_entry.date_start and work_entry.duration: - work_entry.date_stop = work_entry.date_start + relativedelta(hours=work_entry.duration) + @api.depends('date_start', 'duration') + def _compute_date_stop(self): + for work_entry in self.filtered(lambda w: w.date_start and w.duration): + work_entry.date_stop = work_entry.date_start + relativedelta(hours=work_entry.duration) def _get_duration(self, date_start, date_stop): if not date_start or not date_stop: |
