下达生产修改

This commit is contained in:
guanhuan
2025-06-13 10:05:33 +08:00
parent 448a2cd277
commit 2c97287218
2 changed files with 12 additions and 56 deletions

View File

@@ -99,8 +99,8 @@ class SfProductionDemandPlan(models.Model):
], string='投料齐套检查', compute='_compute_material_check', store=True)
processing_time = fields.Char('程序工时', readonly=True)
planned_start_date = fields.Date('计划开工日期')
actual_start_date = fields.Date('实际开工日期', compute='_compute_actual_start_date', store=True)
actual_end_date = fields.Date('实际完工日期', compute='_compute_actual_end_date', store=True)
actual_start_date = fields.Datetime('实际开工日期', compute='_compute_actual_start_date', store=True)
actual_end_date = fields.Datetime('实际完工日期', compute='_compute_actual_end_date', store=True)
print_count = fields.Char('打印次数', default='T0C0', readonly=True)
sequence = fields.Integer('序号')
@@ -242,7 +242,7 @@ class SfProductionDemandPlan(models.Model):
lambda mo: mo.product_id == record.product_id)
if manufacturing_orders:
start_dates = [
workorder.date_start.date() for mo in manufacturing_orders
workorder.date_start for mo in manufacturing_orders
for workorder in mo.workorder_ids if workorder.date_start
]
record.actual_start_date = min(start_dates) if start_dates else None
@@ -261,7 +261,7 @@ class SfProductionDemandPlan(models.Model):
finished_orders = manufacturing_orders.filtered(lambda mo: mo.state == 'done')
if len(finished_orders) >= record.product_uom_qty:
end_dates = [
workorder.date_finished.date() for mo in finished_orders
workorder.date_finished for mo in finished_orders
for workorder in mo.workorder_ids if workorder.date_finished
]
record.actual_end_date = max(end_dates) if end_dates else None
@@ -298,61 +298,17 @@ class SfProductionDemandPlan(models.Model):
raise ValidationError("计划开工日期必须大于或等于今天。")
def release_production_order(self):
if not self.planned_start_date:
raise ValidationError("请先填写计划开工日期")
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:
if sf_production_line:
now = datetime.now()
time_part = (now + timedelta(minutes=3)).time()
date_part = fields.Date.from_string(self.planned_start_date)
date_planned_start = datetime.combine(date_part, time_part)
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:

View File

@@ -62,7 +62,7 @@ class MrpWorkorder(models.Model):
[('workorder_id', '=', record.id)])
if demand_plan_print:
self.env['sf.demand.plan.print.wizard'].sudo().write(
{'cnc_worksheet': res.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
else:
demand_plan = self.env['sf.production.demand.plan'].sudo().search(
[('product_id', '=', record.product_id.id)])