From 701decb38f3872ac9b3f3660b12ee0a9b045b206 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Tue, 31 Dec 2024 17:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=8D=95=E7=A1=AE=E8=AE=A4=E8=AE=A2=E5=8D=95=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 118 +--------------------- sf_manufacturing/models/purchase_order.py | 6 -- sf_sale/models/sale_order.py | 18 ++++ 3 files changed, 19 insertions(+), 123 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index d121bae8..d6de3408 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1035,49 +1035,6 @@ class ResMrpWorkOrder(models.Model): 'production_id.tool_state', 'production_id.schedule_state', 'sequence', 'production_id.programming_state') def _compute_state(self): - # super()._compute_state() - # for workorder in self: - # if workorder.sequence != 1: - # previous_workorder = self.env['mrp.workorder'].search( - # [('production_id', '=', workorder.production_id.id), - # ('sequence', '=', workorder.sequence - 1)]) - # if workorder.state == 'pending': - # if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]): - # if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排': - # if ((workorder.sequence == 1 and not workorder.blocked_by_workorder_ids) - # or (workorder.blocked_by_workorder_ids.state in ('done', 'cancel') - # and workorder.blocked_by_workorder_ids.test_results not in ['报废', '返工']) - # or (previous_workorder.state in ('done', 'cancel') - # and not workorder.blocked_by_workorder_ids - # and previous_workorder.test_results not in ['报废', '返工']) - # ): - # workorder.state = 'ready' - # continue - # if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'): - # if workorder.sequence != 1: - # workorder.state = 'pending' - # continue - # if workorder.state not in ('waiting', 'ready'): - # continue - # if workorder.state in ( - # 'waiting') and workorder.sequence == 1 and workorder.production_id.schedule_state == '已排': - # workorder.state = 'ready' - # continue - # if not all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]): - # workorder.state = 'pending' - # if workorder.state in ['waiting']: - # if previous_workorder.state == 'waiting': - # workorder.state = 'pending' - # if workorder.sequence == 1 and workorder.state == 'pending': - # workorder.state = 'waiting' - # continue - # if workorder.production_id.reservation_state not in ('waiting', 'confirmed', 'assigned'): - # continue - # if workorder.production_id.reservation_state == 'assigned' and workorder.state == 'waiting' and workorder.production_id.schedule_state == '已排': - # workorder.state = 'ready' - # elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready': - # workorder.state = 'waiting' - for workorder in self: # 如果工单的工序没有进行排序则跳出循环 if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0): @@ -1119,7 +1076,7 @@ class ResMrpWorkOrder(models.Model): if workorder.state != 'waiting': workorder.state = 'waiting' continue - if workorder.production_id.programming_state == '已编程': + if workorder.production_id.programming_state == '已编程' and workorder.technology_design_id.routing_tag != 'special': workorder.state = 'ready' elif workorder.state != 'waiting': workorder.state = 'waiting' @@ -1134,85 +1091,12 @@ class ResMrpWorkOrder(models.Model): if workorder.is_subcontract is False: workorder.state = 'ready' else: - # production_programming = self.env['mrp.production'].search( - # [('origin', '=', self.production_id.origin)], order='name asc') - # production_no_remanufacture = production_programming.filtered( - # lambda a: a.is_remanufacture is False) - # production_list = [production.name for production in production_programming] - # purchase_orders = self.env['purchase.order'].search( - # [('origin', 'ilike', ','.join(production_list))]) - # for line in purchase_orders.order_line: - # if ( - # line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id - # and line.product_qty == len(production_no_remanufacture)): - # if all(pur_order.state == 'purchase' for pur_order in purchase_orders): - # workorder.state = 'ready' - # else: - # workorder.state = 'waiting' purchase_orders_id = self._get_surface_technics_purchase_ids() if purchase_orders_id: workorder.state = 'ready' if purchase_orders_id.state == 'purchase' else 'waiting' else: workorder.state = 'waiting' - # re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id), - # ('processing_panel', '=', workorder.processing_panel), - # ('is_rework', '=', True), ('state', 'in', ['done', 'rework'])]) - # cnc_workorder = self.env['mrp.workorder'].search( - # [('production_id', '=', workorder.production_id.id), - # ('processing_panel', '=', workorder.processing_panel), - # ('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']), - # ('test_results', '=', '返工')]) - # cnc_workorder_pending = self.env['mrp.workorder'].search( - # [('production_id', '=', workorder.production_id.id), - # ('processing_panel', '=', workorder.processing_panel), - # ('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])]) - # unclamp_workorder = self.env['mrp.workorder'].search( - # [('production_id', '=', workorder.production_id.id), - # ('sequence', '=', workorder.sequence - 1), - # ('state', 'in', ['done'])]) - # if workorder.state not in ['cancel', 'progress', 'rework']: - # if workorder.production_id.state == 'rework': - # if workorder.routing_type == '装夹预调': - # # # 有返工工单 - # # if re_work: - # # 新工单 - # if workorder.is_rework is False: - # if (workorder.production_id.programming_state == '已编程' - # and workorder.production_id.is_rework is False): - # if re_work or cnc_workorder: - # workorder.state = 'ready' - # else: - # if workorder.production_id.is_rework is True: - # if re_work or cnc_workorder: - # workorder.state = 'waiting' - # - # elif workorder.routing_type == 'CNC加工': - # pre_workorder = self.env['mrp.workorder'].search( - # [('production_id', '=', workorder.production_id.id), - # ('processing_panel', '=', workorder.processing_panel), - # ('routing_type', '=', '装夹预调'), ('state', '=', 'done')]) - # if pre_workorder: - # if re_work: - # workorder.state = 'waiting' - # elif workorder.routing_type == '解除装夹': - # if cnc_workorder: - # if not cnc_workorder_pending or unclamp_workorder.test_results == '报废': - # workorder.state = 'waiting' - # # else: - # # if workorder.production_id.is_rework is True: - # # workorder.state = 'waiting' - # elif workorder.production_id.state == 'progress': - # if (workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' - # and workorder.is_rework is False and workorder.state not in ['done', 'rework', 'cancel']): - # if workorder.production_id.is_rework is False: - # if re_work or cnc_workorder or unclamp_workorder: - # workorder.state = 'ready' - # # if (re_work or cnc_workorder) and workorder.production_id.is_rework is False: - # # workorder.state = 'ready' - # elif workorder.production_id.state == 'scrap': - # if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废': - # workorder.state = 'waiting' # 重写工单开始按钮方法 def button_start(self): diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index 3e20a0a2..2813883e 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -50,12 +50,6 @@ class PurchaseOrder(models.Model): for workorder in workorders: if workorder.routing_type == '表面工艺' and workorder.is_subcontract is True: move_out = workorder.move_subcontract_workorder_ids[1] - # move_out = self.env['stock.move'].search( - # [('location_id', '=', self.env['stock.location'].search( - # [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), - # ('location_dest_id', '=', self.env['stock.location'].search( - # [('barcode', 'ilike', 'VL-SPOC')]).id), - # ('origin', '=', self.production_id.name), ('state', 'not in', ['cancel', 'done'])]) for mo in move_out: if mo.state != 'done': mo.write({'state': 'assigned', 'production_id': False}) diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 44899d05..24f689d4 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -391,6 +391,23 @@ class RePurchaseOrder(models.Model): production = self.env['mrp.production'].search([('name', '=', production_name)]) for workorder in production.workorder_ids.filtered( lambda wd: wd.routing_type == '表面工艺' and wd.state == 'waiting' and line.product_id.server_product_process_parameters_id == wd.surface_technics_parameters_id): + work_ids = workorder.production_id.workorder_ids.filtered( + lambda wk: wk.state not in ['done', 'rework', 'cancel']) + min_sequence_wk = min(work_ids, key=lambda wk: wk.sequence) + artificial_offline = ( + workorder.production_id.production_type == '人工线下加工' and workorder.production_id.schedule_state != '已排') + auto_production = ( + workorder.production_id.production_type == '自动化产线加工' and workorder.production_id.schedule_state != '已编程') + if workorder.sequence == min_sequence_wk.sequence: + if artificial_offline or auto_production: + raise UserError('等待组件') + else: + sorted_work_ids = work_ids.sorted(key=lambda w: w.sequence) + previous_workorder = self.env['mrp.workorder'].search([('sequence', '<', workorder.sequence), + ('production_id', '=', workorder.production_id.id), + ('state', '=', 'done')], order='sequence desc', limit=1) + if not previous_workorder: + raise UserError('等待组件') workorder.state = 'ready' return result @@ -423,6 +440,7 @@ class PurchaseOrderLine(models.Model): part_name = fields.Char('零件名称', related='product_id.part_name', readonly=True) # part_number = fields.Char('零件图号',related='product_id.part_number', readonly=True) + class ResPartnerToSale(models.Model): _inherit = 'res.partner'