From 5393ef686a2215df8598ba69a2e3dfe9b39f67b8 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 5 Aug 2024 17:28:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 2 +- sf_manufacturing/models/stock.py | 164 +++++++++--------- .../views/mrp_production_addional_change.xml | 2 +- sf_sale/models/sale_order.py | 32 +++- 4 files changed, 118 insertions(+), 82 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 5f7c04b6..880db242 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -940,7 +940,7 @@ class ResMrpWorkOrder(models.Model): if workorder.production_id.tool_state in ['1', '2'] and workorder.state == 'ready': workorder.state = 'waiting' continue ->>>>>>> 3f27ae0f35c7054b2e6583cc60502d6faef3fc92 + # elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'cancel', 'progress', # 'rework']: diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index f6d35b54..f1289261 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -272,73 +272,79 @@ class StockRule(models.Model): product_id_to_production_names[product_id] = [production.name for production in all_production] for production_item in productions: if production_item.product_id.id in product_id_to_production_names: - # sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, key=lambda w: w.id) - # consecutive_process_parameters = [] - # m = 0 - # for i in range(len(sorted_process_parameters) - 1): - # if m == 0: - # is_pick = False - # if sorted_process_parameters[i].supplier_id.id == sorted_process_parameters[i + 1].supplier_id.id and : - # if sorted_process_parameters[i] not in consecutive_process_parameters: - # consecutive_process_parameters.append(sorted_process_parameters[i]) - # consecutive_process_parameters.append(sorted_process_parameters[i + 1]) - # m += 1 - # continue - # else: - # if m == len(consecutive_process_parameters) - 1 and m != 0: - # self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters, - # production_item) - # if sorted_process_parameters[i] in consecutive_workorders: - # is_pick = True - # consecutive_process_parameters = [] - # m = 0 - # # 当前面的连续工序生成对应的采购单再生成当前工序的外协采购单 - # if is_pick is False: - # self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], - # production_item) - # if m == len(consecutive_process_parameters) - 1 and m != 0: - # self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters, - # production_item) - # if sorted_process_parameters[i] in consecutive_process_parameters: - # is_pick = True - # consecutive_process_parameters = [] - # m = 0 - # if m == len(consecutive_process_parameters) - 1 and m != 0: - # self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters, production_item) - # if is_pick is False and m == 0: - # if len(sorted_process_parameters) == 1: - # self.env['stock.picking'].create_outcontract_picking(sorted_process_parameters, production_item) - # else: - # self.env['stock.picking'].create_outcontract_picking(sorted_process_parameters[i], production_item) - for pp in production_item.product_id.model_process_parameters_ids: - if pp.gain_way == '外协': - server_product = self.env['product.template'].search( - [('server_product_process_parameters_id', '=', pp.id), - ('detailed_type', '=', 'service')]) - purchase_order_line = self.env['purchase.order.line'].search( - [('product_id', '=', server_product.id)]) - if not purchase_order_line: - is_exist = False - else: - for item in purchase_order_line: - purchase_order = self.env['purchase.order'].search( - [('state', '=', 'draft'), ('origin', 'ilike', production_item.name), - ('id', '=', item.order_id)]) - if not purchase_order: - is_exist = False - if is_exist is False: - production_process = product_id_to_production_names.get( - production_item.product_id.id) - self.env['purchase.order'].sudo().create({ - 'partner_id': server_product.seller_ids.partner_id.id, - 'origin': ','.join(production_process), - 'state': 'draft', - 'order_line': [(0, 0, { - 'product_id': server_product.product_variant_id.id, - 'product_qty': len(production_process), - 'product_uom': server_product.uom_id.id - })] - }) + sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, + key=lambda w: w.id) + consecutive_process_parameters = [] + m = 0 + for i in range(len(sorted_process_parameters) - 1): + if m == 0: + is_purchase = False + if sorted_process_parameters[i].supplier_id.id == sorted_process_parameters[ + i + 1].supplier_id.id and sorted_process_parameters[i].gain_way == '外协': + if sorted_process_parameters[i] not in consecutive_process_parameters: + consecutive_process_parameters.append(sorted_process_parameters[i]) + consecutive_process_parameters.append(sorted_process_parameters[i + 1]) + m += 1 + continue + else: + if m == len(consecutive_process_parameters) - 1 and m != 0: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + production_item, + product_id_to_production_names) + if sorted_process_parameters[i] in consecutive_workorders: + is_purchase = True + consecutive_process_parameters = [] + m = 0 + # 当前面的连续采购单生成再生成当前工序的外协采购单 + if is_purchase is False: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters[i], + production_item, product_id_to_production_names) + if m == len(consecutive_process_parameters) - 1 and m != 0: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + production_item, product_id_to_production_names) + if sorted_process_parameters[i] in consecutive_process_parameters: + is_purchase = True + consecutive_process_parameters = [] + m = 0 + if m == len(consecutive_process_parameters) - 1 and m != 0: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, production_item, + product_id_to_production_names) + if is_purchase is False and m == 0: + if len(sorted_process_parameters) == 1: + self.env['purchase.order'].get_purchase_order(sorted_process_parameters, production_item, + product_id_to_production_names) + else: + self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], production_item, + product_id_to_production_names) + # for pp in production_item.product_id.model_process_parameters_ids: + # if pp.gain_way == '外协': + # server_product = self.env['product.template'].search( + # [('server_product_process_parameters_id', '=', pp.id), + # ('detailed_type', '=', 'service')]) + # purchase_order_line = self.env['purchase.order.line'].search( + # [('product_id', '=', server_product.id)]) + # if not purchase_order_line: + # is_exist = False + # else: + # for item in purchase_order_line: + # purchase_order = self.env['purchase.order'].search( + # [('state', '=', 'draft'), ('origin', 'ilike', production_item.name), + # ('id', '=', item.order_id)]) + # if not purchase_order: + # is_exist = False + # if is_exist is False: + # production_process = product_id_to_production_names.get( + # production_item.product_id.id) + # self.env['purchase.order'].sudo().create({ + # 'partner_id': server_product.seller_ids.partner_id.id, + # 'origin': ','.join(production_process), + # 'state': 'draft', + # 'order_line': [(0, 0, { + # 'product_id': server_product.product_variant_id.id, + # 'product_qty': len(production_process), + # 'product_uom': server_product.uom_id.id + # })] + # }) # # 同一个产品多个制造订单对应一个编程单和模型库 # # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递 @@ -575,18 +581,18 @@ class StockPicking(models.Model): _('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % move_out.picking_id.name)) res = super().button_validate() # if res is True: - # if self.id == move_out.picking_id.id: - # # if move_out.move_line_ids.workorder_id.state == 'progress': - # move_in = self.env['stock.move'].search( - # [('location_dest_id', '=', self.env['stock.location'].search( - # [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), - # ('location_id', '=', self.env['stock.location'].search( - # [('barcode', 'ilike', 'VL-SPOC')]).id), - # ('origin', '=', self.origin)]) - # production = self.env['mrp.production'].search([('name', '=', self.origin)]) - # if move_in: - # move_in.write({'state': 'assigned'}) - # self.env['stock.move.line'].create(move_in.get_move_line(production, None)) + # if self.id == move_out.picking_id.id: + # # if move_out.move_line_ids.workorder_id.state == 'progress': + # move_in = self.env['stock.move'].search( + # [('location_dest_id', '=', self.env['stock.location'].search( + # [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), + # ('location_id', '=', self.env['stock.location'].search( + # [('barcode', 'ilike', 'VL-SPOC')]).id), + # ('origin', '=', self.origin)]) + # production = self.env['mrp.production'].search([('name', '=', self.origin)]) + # if move_in: + # move_in.write({'state': 'assigned'}) + # self.env['stock.move.line'].create(move_in.get_move_line(production, None)) return res diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index a39a3d07..69aed55e 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -122,7 +122,7 @@ groups="sf_base.group_sf_mrp_user"/> -