From 9a9e47b4ff6bd3fad1d06a19ec25ee322bf7c444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Fri, 29 Nov 2024 08:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=B2=BE=E5=9D=AF=E6=96=99?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=B2=BE=E5=BA=A6=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=8E=92=E7=A8=8B=E5=8A=A0=E4=B8=8A=E9=A2=84=E7=95=99=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/product_template.py | 24 ++++++++++++++++----- sf_plan/models/custom_plan.py | 16 +++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 6e211f09..fb6f92ce 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -859,12 +859,12 @@ class ResProductMo(models.Model): raise UserError('请先配置模型类型内的坯料冗余') vals = { 'name': '%s-%s-%s' % ('P', order_id.name, i), - 'model_long': item['model_long'] + embryo_redundancy_id.long, - 'model_width': item['model_width'] + embryo_redundancy_id.width, - 'model_height': item['model_height'] + embryo_redundancy_id.height, - 'model_volume': (item['model_long'] + embryo_redundancy_id.long) * ( + 'model_long': self.format_float(item['model_long'] + embryo_redundancy_id.long), + 'model_width': self.format_float(item['model_width'] + embryo_redundancy_id.width), + 'model_height': self.format_float(item['model_height'] + embryo_redundancy_id.height), + 'model_volume': self.format_float((item['model_long'] + embryo_redundancy_id.long) * ( item['model_width'] + embryo_redundancy_id.width) * ( - item['model_height'] + embryo_redundancy_id.height), + item['model_height'] + embryo_redundancy_id.height)), 'product_model_type_id': model_type.id, 'model_processing_panel': item['processing_panel_detail'], 'model_machining_precision': item['model_machining_precision'], @@ -907,6 +907,20 @@ class ResProductMo(models.Model): self.attachment_update(item['quality_standard_name'], copy_product_id.product_tmpl_id.id, 'quality_standard', item['quality_standard_mimetype']) return copy_product_id + + def format_float(self, value): + # 将浮点数转换为字符串 + value_str = str(value) + # 检查小数点的位置 + if '.' in value_str: + # 获取小数部分 + decimal_part = value_str.split('.')[1] + # 判断小数位数是否超过2位 + if len(decimal_part) > 2: + # 超过2位则保留2位小数 + return "{:.2f}".format(value) + # 否则保持原来的位数 + return float(value_str) def _get_ids(self, param): type_ids = [] diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index 147caa96..6ee1d3ee 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -242,10 +242,10 @@ class sf_production_plan(models.Model): # 设置一个小的开始时间 first_cnc_workorder.date_planned_start = datetime.now() - timedelta(days=100) first_cnc_workorder.date_planned_finished = date_start + timedelta( - minutes=routing_workcenter.time_cycle) + minutes=routing_workcenter.time_cycle + routing_workcenter.reserved_duration) first_cnc_workorder.date_planned_start = date_start record.sudo().production_id.plan_start_processing_time = first_cnc_workorder.date_planned_start - first_cnc_workorder.duration_expected = routing_workcenter.time_cycle + first_cnc_workorder.duration_expected = routing_workcenter.time_cycle + routing_workcenter.reserved_duration record.calculate_plan_time(first_cnc_workorder, record.production_id.workorder_ids) # 找到最后一张CNC加工工单 last_cnc_workorder = record.production_id.workorder_ids.filtered(lambda x: x.name == 'CNC加工')[-1] @@ -257,10 +257,10 @@ class sf_production_plan(models.Model): routing_workcenter = item.technology_design_id.route_id item.date_planned_start = datetime.now() - timedelta(days=100) item.date_planned_finished = wo_start + timedelta( - minutes=routing_workcenter.time_cycle) + minutes=routing_workcenter.time_cycle + routing_workcenter.reserved_duration) item.date_planned_start = wo_start record.sudo().production_id.plan_start_processing_time = item.date_planned_start - item.duration_expected = routing_workcenter.time_cycle + item.duration_expected = routing_workcenter.time_cycle + routing_workcenter.reserved_duration record.calculate_plan_time(item, record.production_id.workorder_ids) last_cnc_workorder = record.production_id.workorder_ids[-1] record.date_planned_finished = last_cnc_workorder.date_planned_finished @@ -338,8 +338,8 @@ class sf_production_plan(models.Model): next_workorder.date_planned_start = datetime.now() - timedelta(days=100) next_workorder.date_planned_finished = current_workorder.date_planned_start next_workorder.date_planned_start = next_workorder.date_planned_finished - timedelta( - minutes=routing_workcenter.time_cycle) - next_workorder.duration_expected = routing_workcenter.time_cycle + minutes=routing_workcenter.time_cycle + routing_workcenter.reserved_duration) + next_workorder.duration_expected = routing_workcenter.time_cycle + routing_workcenter.reserved_duration for i in range(item_position, len(workorder_list) - 1): if i > len(workorder_list) - 1: @@ -350,9 +350,9 @@ class sf_production_plan(models.Model): # 设置一个小的开始时间 next_workorder.date_planned_start = datetime.now() - timedelta(days=100) next_workorder.date_planned_finished = current_workorder.date_planned_finished + timedelta( - minutes=routing_workcenter.time_cycle) + minutes=routing_workcenter.time_cycle + routing_workcenter.reserved_duration) next_workorder.date_planned_start = current_workorder.date_planned_finished - next_workorder.duration_expected = routing_workcenter.time_cycle + next_workorder.duration_expected = routing_workcenter.time_cycle + routing_workcenter.reserved_duration def calculate_plan_time_after(self, item, workorder_id_list): """