diff --git a/sf_machine_connect/views/WorkCenterBarcodes.xml b/sf_machine_connect/views/WorkCenterBarcodes.xml index 97fee70e..90058b59 100644 --- a/sf_machine_connect/views/WorkCenterBarcodes.xml +++ b/sf_machine_connect/views/WorkCenterBarcodes.xml @@ -10,6 +10,8 @@ + + diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index b5d42f0e..6e6b71cd 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -34,6 +34,65 @@ class MrpProduction(models.Model): tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True) tool_state_remark2 = fields.Text(string='功能刀具状态备注(无效刀)', readonly=True) + def _compute_default_delivery_status(self): + need_list = [ + 'pending_cam', + 'progress', + 'rework', + 'scrap', + 'to_close', + ] + try: + if self.state not in need_list: + return False + if not self.deadline_of_delivery: + return '已逾期' + hours = self.get_hours_diff() + if hours >= 48: + return '正常' + elif hours > 0 and hours < 48: + return '预警' + else: + return '已逾期' + except Exception as e: + logging.error("Error processing production ID {}: {}".format(self.id, e)) + raise e + + @api.depends('state', 'deadline_of_delivery') + def _compute_delivery_status(self): + need_list = [ + 'pending_cam', + 'progress', + 'rework', + 'scrap', + 'to_close', + ] + for production in self: + production.delivery_status = production._compute_default_delivery_status() + + delivery_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='交期状态', + store=True, + compute='_compute_delivery_status', + default=lambda self: self._compute_default_delivery_status()) + + def get_hours_diff(self): + # 获取当前日期和时间 + current_datetime = fields.Datetime.now() + + # 将 date_field 转换为 datetime 对象 + if self.deadline_of_delivery: + date_obj = fields.Date.from_string(self.deadline_of_delivery) + # 将 date 对象转换为 datetime 对象,设置时间为 00:00:00 + date_obj = datetime.datetime.combine(date_obj, datetime.time.min) + + # 计算两个日期之间的差值 + delta = date_obj - current_datetime + + # 返回差值的小时数 + return int(delta.total_seconds() / 3600) + else: + return 0.0 + @api.depends('procurement_group_id.mrp_production_ids.move_dest_ids.group_id.sale_id') def _compute_deadline_of_delivery(self): for production in self: @@ -1240,7 +1299,7 @@ class MrpProduction(models.Model): 'move_dest_ids': production.move_dest_ids.ids, 'user_id': production.user_id.id} return production_values_str - + # 增加制造订单类型 production_type = fields.Selection( [('自动化产线加工', '自动化产线加工'), ('人工线下加工', '人工线下加工')], diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 9bfc82e1..8750de2c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -147,6 +147,54 @@ class ResMrpWorkOrder(models.Model): tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True) + def _compute_default_construction_period_status(self): + need_list = [ + 'progress', + 'to be detected'] + try: + if self.state not in need_list: + return False + if not self.date_planned_finished: + return '已逾期' + hours = self.get_hours_diff() + if hours >= 12: + return '正常' + elif hours > 0 and hours < 12: + return '预警' + else: + return '已逾期' + except Exception as e: + logging.error("Error processing production ID {}: {}".format(self.id, e)) + raise e + + @api.depends('state', 'date_planned_finished') + def _compute_construction_period_status(self): + for worker in self: + worker.construction_period_status = worker._compute_default_construction_period_status() + + construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='工期状态', + store=True, + compute='_compute_construction_period_status', + default=lambda self: self._compute_default_construction_period_status()) + + def get_hours_diff(self): + # 获取当前日期和时间 + current_datetime = fields.Datetime.now() + + # 将 date_field 转换为 datetime 对象 + if self.date_planned_finished: + date_obj = fields.Datetime.from_string(self.date_planned_finished) + # 将 date 对象转换为 datetime 对象,设置时间为 00:00:00 + # date_obj = datetime.datetime.combine(date_obj, datetime.time.min) + + # 计算两个日期之间的差值 + delta = date_obj - current_datetime + + # 返回差值的小时数 + return int(delta.total_seconds() / 3600) + else: + return 0.0 + @api.depends('name', 'production_id.name') def _compute_surface_technics_picking_ids(self): for workorder in self: diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index c6a40455..c218c2d5 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -36,7 +36,8 @@ decoration-success="reservation_state == 'assigned'"/> - + @@ -56,6 +57,16 @@ + + + + + 1 + + @@ -348,7 +359,7 @@ - + diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 7aa669bf..c27f2175 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -32,8 +32,10 @@ - + @@ -257,11 +259,12 @@ -
@@ -482,11 +485,11 @@ - + - + @@ -543,11 +546,11 @@ - + - +