Accept Merge Request #2190: (feature/齐套检查与下达生产 -> develop)

Merge Request: 修复坯料的采购申请按钮没显示

Created By: @管欢
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @管欢
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2190
This commit is contained in:
管欢
2025-06-13 14:24:29 +08:00
committed by Coding
3 changed files with 19 additions and 58 deletions

View File

@@ -4,6 +4,12 @@ from odoo import models, fields, api, _
class ReSaleOrder(models.Model):
_inherit = 'sale.order'
mrp_production_ids = fields.Many2many(
'mrp.production',
compute='_compute_mrp_production_ids',
string='与此销售订单相关联的制造订单',
groups='mrp.group_mrp_user', store=True)
def sale_order_create_line(self, product, item):
ret = super(ReSaleOrder, self).sale_order_create_line(product, item)
vals = {

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:
@@ -407,10 +363,9 @@ class SfProductionDemandPlan(models.Model):
)
if total_purchase_quantity < record.product_uom_qty:
pr_ids = self.env['purchase.request'].sudo().search(
[('origin', 'like', mrp_production[0].name), ('state', '!=', 'done')])
[('line_ids.product_id', 'in', raw_materials.ids), ('state', '!=', 'done')])
outsourcing_purchase_request.extend(pr_ids.ids)
elif record.supply_method in ('purchase', 'outsourcing'):
pr_ids = None
purchase_orders = self.env['purchase.order'].sudo().search([
('state', 'in', ('purchase', 'done')),
('order_line.product_id', '=', record.product_id.id)

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)])