Skip to content
Permalink
Browse files

read_group

  • Loading branch information...
Whenrow committed May 14, 2019
1 parent ab25968 commit 8ebd37c7df2144c9c399608486556c4ef6415cb3
Showing with 11 additions and 10 deletions.
  1. +11 −10 addons/mrp/models/mrp_production.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from collections import defaultdict
from datetime import datetime

from odoo import api, fields, models, _
from odoo.addons import decimal_precision as dp
from odoo.exceptions import AccessError, UserError
from odoo.tools import date_utils, float_round, DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools import date_utils, float_round


class MrpProduction(models.Model):
@@ -626,13 +625,15 @@ def _plan_workorders(self):
workcenters = workorder.workcenter_id | workorder.workcenter_id.alternative_workcenter_ids

# extract already planned workorders
wos = self.env['mrp.workorder'].search([
wos = self.env['mrp.workorder'].read_group([
('workcenter_id', 'in', workcenters.ids),
('state', 'in', ('ready', 'pending', 'progress')),
('date_planned_finished', '>=', start_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT))],
order="date_planned_finished"
('date_planned_finished', '>=', start_date)],
['workcenter_id', 'date_planned_start:array_agg', 'date_planned_finished:array_agg'],
['workcenter_id'],
orderby='date_planned_finished'
)
best_start_date = start_date
wos = {wo['workcenter_id'][0]: zip(wo['date_planned_start'], wo['date_planned_finished']) for wo in wos}
best_finished_date = datetime.max
best_values = {}
for workcenter in workcenters:
@@ -651,12 +652,12 @@ def _plan_workorders(self):
else:
to_date = date_utils.add(from_date, minutes=duration_expected)
# Check intervals
for wo in wos.filtered(lambda wo: wo.workcenter_id == workcenter):
if best_finished_date < wo.date_planned_finished:
for date_start, date_finished in wos.get(workcenter.id, []):
if best_finished_date < date_finished:
# workorders are ordered by date. There is no need to check the other ones
break
if to_date > wo.date_planned_start:
from_date = wo.date_planned_finished
if to_date > date_start:
from_date = date_finished
if has_schedule:
to_date = workcenter.resource_calendar_id.plan_hours(duration_expected / 60.0, from_date, compute_leaves=True, resource=workcenter.resource_id)
else:

0 comments on commit 8ebd37c

Please sign in to comment.
You can’t perform that action at this time.