修改匹配加工中心

This commit is contained in:
jinling.yang
2022-11-04 16:08:43 +08:00
parent 14d0d32ab6
commit 65a7d74430
3 changed files with 40 additions and 19 deletions

View File

@@ -27,17 +27,17 @@ class ResMrpRoutingWorkcenter(models.Model):
# 如果只配置了一个工作中心,则默认采用该工作中心;
# 如果有多个工作中心,
# 则根据该工作中心的工单个数进行分配(优先分配给工单个数最少的);
# def get_workcenter(self, workcenter_ids):
# print(workcenter_ids[0].id)
# if workcenter_ids:
# if len(workcenter_ids) == 1:
# return workcenter_ids[0].id
# elif len(workcenter_ids) >= 2:
# workcenter_id = self.env['mrp.workorder'].search(
# [('workcenter_ids.id', 'in', True)],
# limit=1,
# group_by =
# )
def get_workcenter(self, workcenter_ids):
if workcenter_ids:
if len(workcenter_ids) == 1:
return workcenter_ids[0]
elif len(workcenter_ids) >= 2:
# workcenter_ids_str = ','.join([str(s) for s in workcenter_ids])
self.env.cr.execute("""
SELECT workcenter_id FROM mrp_workorder where workcenter_id
in %s group by workcenter_id
order by count(*),workcenter_id asc limit 1 """, [tuple(workcenter_ids)])
return self.env.cr.dictfetchall()[0].get('workcenter_id')
class ModelTypeRoutingSort(models.Model):