From 2c9728721826ee5d50ccbbe378e654828e790593 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Fri, 13 Jun 2025 10:05:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8B=E8=BE=BE=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/sf_production_demand_plan.py | 66 ++++--------------- .../wizard/sf_demand_plan_print_wizard.py | 2 +- 2 files changed, 12 insertions(+), 56 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index df1e2990..de902573 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -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: diff --git a/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py b/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py index 871d7e5c..ddd154e6 100644 --- a/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py +++ b/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py @@ -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)]) From 2c7fbd3aef99cb6f90413118f82fbd06b3420051 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Fri, 13 Jun 2025 10:41:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9D=AF=E6=96=99?= =?UTF-8?q?=E7=9A=84=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=B2=A1=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sf_production_demand_plan.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index de902573..d484fb8e 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -363,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) From ffad4b79951c4786252ec57066662413aaad1a4e Mon Sep 17 00:00:00 2001 From: guanhuan Date: Fri, 13 Jun 2025 14:17:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9D=AF=E6=96=99?= =?UTF-8?q?=E7=9A=84=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=B2=A1=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sale_order.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sf_demand_plan/models/sale_order.py b/sf_demand_plan/models/sale_order.py index e1168115..27e5c603 100644 --- a/sf_demand_plan/models/sale_order.py +++ b/sf_demand_plan/models/sale_order.py @@ -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 = {