[FIX] mrp(workorder_hr): fix workorder duration
Previously, _intervals_duration (called by _compute_duration) sometimes loose the last mrp.workcenter.productivity. A fix has been made. First, mrp.workcenter.productivity.loss _convert_to_duration calculates according to the loss type, we have to take that in account. Second, mrp.workcenter.productivity _close badly generates performance timers. For example, test_mrp_employee_analytic_account generated - productive for 1st employee from 10:00 to 11:00 - performance for 2nd employee from 10:00 to 11:00 - performance for 2nd employee from 11:00 to 11:00 (! duration = 0) Now, the timers are - productive for 1st employee from 10:00 to 11:00 - productive for 2nd employee from 10:00 to 11:00 which is correct. closes odoo/odoo#106908 Task: 2985735 X-original-commit: 8638ec145ab83e4afafa39a5c9e987e8d772bfd1 Related: odoo/enterprise#34533 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Jean-François Aubert <ajf@odoo.com>
This commit is contained in:
@@ -434,20 +434,14 @@ class MrpWorkcenterProductivity(models.Model):
|
||||
underperformance_timers = self.env['mrp.workcenter.productivity']
|
||||
for timer in self:
|
||||
wo = timer.workorder_id
|
||||
if wo.duration_expected <= wo.duration:
|
||||
if timer.loss_type == 'productive':
|
||||
timer.write({'date_end': datetime.now()})
|
||||
if wo.duration > wo.duration_expected:
|
||||
productive_date_end = timer.date_end - relativedelta.relativedelta(minutes=wo.duration - wo.duration_expected)
|
||||
if productive_date_end <= timer.date_start:
|
||||
underperformance_timers |= timer
|
||||
timer.write({'date_end': fields.Datetime.now()})
|
||||
continue
|
||||
|
||||
maxdate = timer.date_start + relativedelta.relativedelta(minutes=wo.duration_expected - wo.duration)
|
||||
enddate = fields.datetime.now()
|
||||
if maxdate > enddate:
|
||||
timer.write({'date_end': enddate})
|
||||
else:
|
||||
timer.write({'date_end': maxdate})
|
||||
underperformance_timers |= timer.copy({'date_start': maxdate, 'date_end': enddate})
|
||||
|
||||
else:
|
||||
underperformance_timers |= timer.copy({'date_start': productive_date_end})
|
||||
timer.write({'date_end': productive_date_end})
|
||||
if underperformance_timers:
|
||||
underperformance_type = self.env['mrp.workcenter.productivity.loss'].search([('loss_type', '=', 'performance')], limit=1)
|
||||
if not underperformance_type:
|
||||
|
||||
Reference in New Issue
Block a user