下达生产
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import float_compare
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class sf_production_plan(models.Model):
|
||||
@@ -243,4 +244,62 @@ class sf_production_plan(models.Model):
|
||||
raise ValidationError("计划开工日期必须大于或等于今天。")
|
||||
|
||||
def release_production_order(self):
|
||||
pass
|
||||
pro_plan_list = self.env['sf.production.plan'].search(
|
||||
[('product_id', '=', self.product_id.id), ('state', '=', 'draft')])
|
||||
sf_production_line = self.env['sf.production.line'].sudo().search(
|
||||
[('name', '=', '1#CNC自动生产线')], limit=1)
|
||||
current_datetime = datetime.now() + timedelta(minutes=3)
|
||||
current_hour = current_datetime.hour + current_datetime.minute / 60
|
||||
date_planned_start = None
|
||||
production_lines = sf_production_line.mrp_workcenter_ids.filtered(lambda b: "自动生产线" in b.name)
|
||||
if production_lines:
|
||||
if not production_lines.deal_with_workcenter_calendar(current_datetime):
|
||||
attendance_list = production_lines.resource_calendar_id.attendance_ids
|
||||
# 获取所有工作日规则并按星期几分组
|
||||
attendance_by_day = {}
|
||||
for attendance in attendance_list:
|
||||
if attendance.dayofweek not in attendance_by_day:
|
||||
attendance_by_day[attendance.dayofweek] = []
|
||||
attendance_by_day[attendance.dayofweek].append(attendance)
|
||||
|
||||
for day_offset in range(0, 8):
|
||||
check_date = current_datetime + timedelta(days=day_offset)
|
||||
# 日期为星期几
|
||||
check_day = production_lines.get_current_day_of_week(check_date)
|
||||
if check_day in attendance_by_day:
|
||||
day_attendances = attendance_by_day[check_day]
|
||||
if day_offset == 0:
|
||||
for attendance in day_attendances:
|
||||
if current_hour < attendance.hour_to:
|
||||
# 找到下一个有效时间段
|
||||
if current_hour < attendance.hour_from:
|
||||
# 使用开始时间
|
||||
date_planned_start = check_date.replace(
|
||||
hour=int(attendance.hour_from),
|
||||
minute=int((attendance.hour_from % 1) * 60),
|
||||
second=0,
|
||||
microsecond=0
|
||||
)
|
||||
else:
|
||||
continue
|
||||
break
|
||||
else:
|
||||
# 不是今天,使用第一个工作时间段
|
||||
attendance = day_attendances[0]
|
||||
date_planned_start = check_date.replace(
|
||||
hour=int(attendance.hour_from),
|
||||
minute=int((attendance.hour_from % 1) * 60),
|
||||
second=0,
|
||||
microsecond=0
|
||||
)
|
||||
|
||||
if date_planned_start:
|
||||
break
|
||||
else:
|
||||
date_planned_start = current_datetime
|
||||
|
||||
if date_planned_start:
|
||||
pro_plan_list.production_line_id = sf_production_line.id
|
||||
pro_plan_list.date_planned_start = date_planned_start
|
||||
for pro_plan in pro_plan_list:
|
||||
pro_plan.do_production_schedule()
|
||||
|
||||
Reference in New Issue
Block a user