From 9a9bfd198b775f5d326c64c87a694753cca91b87 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Wed, 13 Nov 2024 14:46:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BA=A4=E6=9C=9F=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/__manifest__.py | 4 +- sf_manufacturing/data/cron_data.xml | 29 ++++++++++++++ sf_manufacturing/models/mrp_production.py | 46 ++++++++++++++++++---- sf_manufacturing/models/mrp_workorder.py | 47 +++++++++++++++++++---- 4 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 sf_manufacturing/data/cron_data.xml diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index 98c71f21..eea7da85 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -10,8 +10,10 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse','jikimo_attachment_viewer', 'jikimo_sale_multiple_supply_methods'], + 'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse', 'jikimo_attachment_viewer', + 'jikimo_sale_multiple_supply_methods'], 'data': [ + 'data/cron_data.xml', 'data/stock_data.xml', 'data/empty_racks_data.xml', 'data/panel_data.xml', diff --git a/sf_manufacturing/data/cron_data.xml b/sf_manufacturing/data/cron_data.xml new file mode 100644 index 00000000..36e5bcf9 --- /dev/null +++ b/sf_manufacturing/data/cron_data.xml @@ -0,0 +1,29 @@ + + + + 工期状态变更 + + code + model._corn_update_construction_period_status() + 12 + hours + -1 + + + + + + + 交期状态变更 + + code + model._corn_update_delivery_status() + 12 + hours + -1 + + + + + + \ No newline at end of file diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 6e6b71cd..5f479969 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -60,6 +60,42 @@ class MrpProduction(models.Model): @api.depends('state', 'deadline_of_delivery') def _compute_delivery_status(self): + for production in self: + delivery_status = production._compute_default_delivery_status() + if delivery_status and production.delivery_status != delivery_status: + production.delivery_status = delivery_status + + delivery_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], string='交期状态', + store=True, + compute='_compute_delivery_status', + default=lambda self: self._compute_default_delivery_status()) + + def get_page_all_records(self, model_name, func, domain, page_size=100): + # 获取模型对象 + model = self.env[model_name].sudo() + + # 初始化分页参数 + page_number = 1 + while True: + # 计算偏移量 + offset = (page_number - 1) * page_size + + # 获取当前页的数据 + records = model.search(domain, limit=page_size, offset=offset) + + # 如果没有更多记录,退出循环 + if not records: + break + + # 将当前页的数据添加到结果列表 + func(records) + # 增加页码 + page_number += 1 + + def run_compute_delivery_status(self, records): + records._compute_delivery_status() + + def _corn_update_delivery_status(self): need_list = [ 'pending_cam', 'progress', @@ -67,13 +103,9 @@ class MrpProduction(models.Model): '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()) + # previous_workorder = self.env['mrp.production'].search([('state', 'in', need_list)]) + self.get_page_all_records('mrp.production', self.run_compute_delivery_status, + [('state', 'in', need_list)], 100) def get_hours_diff(self): # 获取当前日期和时间 diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 8750de2c..19c28352 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -149,8 +149,8 @@ class ResMrpWorkOrder(models.Model): def _compute_default_construction_period_status(self): need_list = [ - 'progress', - 'to be detected'] + 'progress', + 'to be detected'] try: if self.state not in need_list: return False @@ -170,12 +170,45 @@ class ResMrpWorkOrder(models.Model): @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 = worker._compute_default_construction_period_status() + if construction_period_status and worker.construction_period_status!=construction_period_status: + worker.construction_period_status = 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()) + construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], + string='工期状态', + store=True, + compute='_compute_construction_period_status', + default=lambda + self: self._compute_default_construction_period_status()) + + def get_page_all_records(self, model_name, func, domain, page_size=100): + # 获取模型对象 + model = self.env[model_name].sudo() + + # 初始化分页参数 + page_number = 1 + while True: + # 计算偏移量 + offset = (page_number - 1) * page_size + + # 获取当前页的数据 + records = model.search(domain, limit=page_size, offset=offset) + + # 如果没有更多记录,退出循环 + if not records: + break + + # 将当前页的数据添加到结果列表 + func(records) + # 增加页码 + page_number += 1 + def run_compute_construction_period_status(self,records): + records._compute_construction_period_status() + def _corn_update_construction_period_status(self): + need_list = [ + 'progress', + 'to be detected'] + self.get_page_all_records('mrp.workorder',self.run_compute_construction_period_status,[('state', 'in', need_list)],100) def get_hours_diff(self): # 获取当前日期和时间 From 811a79c7c19ae9befbbbee7807ff8b27d47b7729 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Fri, 15 Nov 2024 10:33:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BA=A4=E6=9C=9F=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 18 ++++++++---------- sf_manufacturing/models/mrp_workorder.py | 17 +++++++++-------- .../views/mrp_production_addional_change.xml | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 5f479969..031515a5 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -35,23 +35,18 @@ class MrpProduction(models.Model): 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: + if self.state == 'cancel': return False if not self.deadline_of_delivery: - return '已逾期' + return False hours = self.get_hours_diff() if hours >= 48: return '正常' - elif hours > 0 and hours < 48: + elif hours > 0 and hours < 48 and self.state != 'done': return '预警' + elif hours > 0 and hours < 48 and self.state == 'done': + return '正常' else: return '已逾期' except Exception as e: @@ -97,6 +92,9 @@ class MrpProduction(models.Model): def _corn_update_delivery_status(self): need_list = [ + 'draft', + 'technology_to_confirmed', + 'confirmed', 'pending_cam', 'progress', 'rework', diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 19c28352..a61b0986 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -148,19 +148,19 @@ class ResMrpWorkOrder(models.Model): tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True) def _compute_default_construction_period_status(self): - need_list = [ - 'progress', - 'to be detected'] + need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected','done'] try: if self.state not in need_list: return False if not self.date_planned_finished: - return '已逾期' + return False hours = self.get_hours_diff() if hours >= 12: return '正常' - elif hours > 0 and hours < 12: + elif hours > 0 and hours < 12 and self.state!='done': return '预警' + elif hours > 0 and hours < 12 and self.state=='done': + return '正常' else: return '已逾期' except Exception as e: @@ -205,9 +205,10 @@ class ResMrpWorkOrder(models.Model): def run_compute_construction_period_status(self,records): records._compute_construction_period_status() def _corn_update_construction_period_status(self): - need_list = [ - 'progress', - 'to be detected'] + need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected'] + # need_list = [ + # 'progress', + # 'to be detected'] self.get_page_all_records('mrp.workorder',self.run_compute_construction_period_status,[('state', 'in', need_list)],100) def get_hours_diff(self): diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index c218c2d5..c56f4c3e 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -557,7 +557,7 @@ -