diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index d1349671..f11a32ac 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -724,8 +724,13 @@ class MrpProduction(models.Model): proc_workorders = [] process_parameter_workorder = self.env['mrp.workorder'].search( [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id), - ('is_subcontract', '=', True)], order='sequence asc') + ('is_subcontract', '=', True), ('state', '!=', 'cancel')], order='sequence asc') if process_parameter_workorder: + # 将这些特殊表面工艺工单的采购单与调拨单置为失效 + for workorder in process_parameter_workorder: + workorder._get_surface_technics_purchase_ids().write({'state': 'cancel'}) + workorder.move_subcontract_workorder_ids.write({'state': 'cancel'}) + workorder.move_subcontract_workorder_ids.picking_id.write({'state': 'cancel'}) consecutive_workorders = [] sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.sequence) for i, workorder in enumerate(sorted_workorders): diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index b6173d78..c840ff17 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -329,7 +329,7 @@ class ResMrpWorkOrder(models.Model): def _get_surface_technics_purchase_ids(self): domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')] purchase_orders = self.env['purchase.order'].search(domain) - purchase_orders_id = None + purchase_orders_id = self.env['purchase.order'] for po in purchase_orders: for line in po.order_line: if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id: diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 8597942f..01c7bd93 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -654,54 +654,47 @@ class StockPicking(models.Model): # 创建 外协出库入单 def create_outcontract_picking(self, workorders, item, sorted_workorders): - domain = [('origin', '=', item.name), ('name', 'ilike', 'OCOUT')] - if len(workorders) > 1: - workorders = workorders[0] - else: - domain += [ - ('surface_technics_parameters_id', '=', workorders[0].surface_technics_parameters_id.id)] - stock_picking = self.env['stock.picking'].search(domain) - if not stock_picking: - for workorder in workorders: - # pick_ids = [] - if not workorder.picking_ids: - # outcontract_stock_move = self.env['stock.move'].search([('production_id', '=', item.id)]) - # if not outcontract_stock_move: - # 创建一个新的补货组 - procurement_group_id = self.env['procurement.group'].create({ - 'name': workorder.name, - 'partner_id': self.partner_id.id, - }) - move_dest_id = False - # 如果当前工单是是制造订单的最后一个工单 - if workorder == item.workorder_ids[-1]: - move_dest_id = item.move_raw_ids[0].id - else: - # 从sorted_workorders中找到上一工单的move + for workorder in workorders: + if workorder.move_subcontract_workorder_ids: + workorder.move_subcontract_workorder_ids.write({'state': 'draft'}) + workorder.move_subcontract_workorder_ids.picking_id.write({'state': 'draft'}) + else: + # 创建一个新的补货组 + procurement_group_id = self.env['procurement.group'].create({ + 'name': workorder.name, + 'partner_id': self.partner_id.id, + }) + move_dest_id = False + # 如果当前工单是是制造订单的最后一个工单 + if workorder == item.workorder_ids[-1]: + move_dest_id = item.move_raw_ids[0].id + else: + # 从sorted_workorders中找到上一工单的move + if sorted_workorders.index(workorder) > 0: move_dest_id = sorted_workorders[sorted_workorders.index(workorder) - 1].move_subcontract_workorder_ids[1].id - new_picking = True - outcontract_picking_type_in = self.env.ref( - 'sf_manufacturing.outcontract_picking_in').id, - outcontract_picking_type_out = self.env.ref( - 'sf_manufacturing.outcontract_picking_out').id, - moves_in = self.env['stock.move'].sudo().create( - self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_in, procurement_group_id.id, move_dest_id)) - picking_in = self.create( - moves_in._get_new_picking_values_Res(item, workorder, 'WH/OCIN/')) - # pick_ids.append(picking_in.id) - moves_in.write( - {'picking_id': picking_in.id, 'state': 'waiting'}) - moves_in._assign_picking_post_process(new=new_picking) - moves_out = self.env['stock.move'].sudo().create( - self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_out, procurement_group_id.id, moves_in.id)) - workorder.write({'move_subcontract_workorder_ids': [(6, 0, [moves_in.id, moves_out.id])]}) - picking_out = self.create( - moves_out._get_new_picking_values_Res(item, workorder, 'WH/OCOUT/')) - # pick_ids.append(picking_out.id) - moves_out.write( - {'picking_id': picking_out.id, 'state': 'waiting'}) - moves_out._assign_picking_post_process(new=new_picking) - + new_picking = True + outcontract_picking_type_in = self.env.ref( + 'sf_manufacturing.outcontract_picking_in').id, + outcontract_picking_type_out = self.env.ref( + 'sf_manufacturing.outcontract_picking_out').id, + moves_in = self.env['stock.move'].sudo().create( + self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_in, procurement_group_id.id, move_dest_id)) + picking_in = self.create( + moves_in._get_new_picking_values_Res(item, workorder, 'WH/OCIN/')) + # pick_ids.append(picking_in.id) + moves_in.write( + {'picking_id': picking_in.id, 'state': 'waiting'}) + moves_in._assign_picking_post_process(new=new_picking) + moves_out = self.env['stock.move'].sudo().create( + self.env['stock.move']._get_stock_move_values_Res(item, outcontract_picking_type_out, procurement_group_id.id, moves_in.id)) + workorder.write({'move_subcontract_workorder_ids': [(6, 0, [moves_in.id, moves_out.id])]}) + picking_out = self.create( + moves_out._get_new_picking_values_Res(item, workorder, 'WH/OCOUT/')) + # pick_ids.append(picking_out.id) + moves_out.write( + {'picking_id': picking_out.id, 'state': 'waiting'}) + moves_out._assign_picking_post_process(new=new_picking) + @api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id') def _compute_state(self): diff --git a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py index 80a02b2b..efc0e449 100644 --- a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py +++ b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py @@ -66,30 +66,30 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): # 工单采购单外协出入库单皆需取消 domain = [('production_id', '=', special.production_id.id)] if special.process_parameters_id: - domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id)] + domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id), ('state', '!=', 'cancel')] else: - domain += [('technology_design_id', '=', special.id)] + domain += [('technology_design_id', '=', special.id), ('state', '!=', 'cancel')] workorder = self.env['mrp.workorder'].search(domain) - previous_workorder = self.env['mrp.workorder'].search( - [('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'), - ('production_id', '=', workorder.production_id.id)]) - if previous_workorder: - if previous_workorder.supplier_id != workorder.supplier_id: - is_cancel = True - else: - is_cancel = True - if workorder.state != 'cancel' and is_cancel is True: - workorder.write({'state': 'cancel'}) - workorder.picking_ids.write({'state': 'cancel'}) - workorder.picking_ids.move_ids.write({'state': 'cancel'}) - purchase_order = self.env['purchase.order'].search( - [('origin', '=', workorder.production_id.name)]) - for line in purchase_order.order_line: - if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id: - purchase_order.write({'state': 'cancel'}) + # previous_workorder = self.env['mrp.workorder'].search( + # [('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'), + # ('production_id', '=', workorder.production_id.id)]) + # if previous_workorder: + # if previous_workorder.supplier_id != workorder.supplier_id: + # is_cancel = True + # else: + # is_cancel = True + # if workorder.state != 'cancel' and is_cancel is True: + # workorder.write({'state': 'cancel'}) + # workorder.picking_ids.write({'state': 'cancel'}) + # workorder.picking_ids.move_ids.write({'state': 'cancel'}) + # purchase_order = self.env['purchase.order'].search( + # [('origin', '=', workorder.production_id.name)]) + # for line in purchase_order.order_line: + # if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id: + # purchase_order.write({'state': 'cancel'}) else: workorder = self.env['mrp.workorder'].search( - [('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id)]) + [('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id), ('state', '!=', 'cancel')]) if not workorder: if special.route_id.routing_type == '表面工艺': product_production_process = self.env['product.template'].search( @@ -110,11 +110,12 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): workorder.blocked_by_workorder_ids = None else: if workorder.blocked_by_workorder_ids: - workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0] + workorder.blocked_by_workorder_ids = workorder.blocked_by_workorder_ids[0] productions._reset_work_order_sequence() - if self.production_id.product_id.categ_id.type == '成品': - productions._reset_subcontract_pick_purchase() - productions.get_subcontract_pick_purchase() + # 退回时不对外协出入库单和采购单做处理 + # if self.production_id.product_id.categ_id.type == '成品': + # productions._reset_subcontract_pick_purchase() + # productions.get_subcontract_pick_purchase() productions.is_adjust = True for item in productions: workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( diff --git a/sf_manufacturing/wizard/production_technology_wizard.py b/sf_manufacturing/wizard/production_technology_wizard.py index 5fbdb7d7..8700dfb5 100644 --- a/sf_manufacturing/wizard/production_technology_wizard.py +++ b/sf_manufacturing/wizard/production_technology_wizard.py @@ -63,9 +63,9 @@ class ProductionTechnologyWizard(models.TransientModel): # 工单采购单外协出入库单皆需取消 domain = [('production_id', '=', special.production_id.id)] if special.process_parameters_id: - domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id)] + domain += [('surface_technics_parameters_id', '=', special.process_parameters_id.id), ('state', '!=', 'cancel')] else: - domain += [('technology_design_id', '=', special.id)] + domain += [('technology_design_id', '=', special.id), ('state', '!=', 'cancel')] workorder = self.env['mrp.workorder'].search(domain) previous_workorder = self.env['mrp.workorder'].search( [('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'), @@ -87,7 +87,7 @@ class ProductionTechnologyWizard(models.TransientModel): else: if special.production_id.workorder_ids: workorder = self.env['mrp.workorder'].search( - [('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id)]) + [('technology_design_id', '=', special.id), ('production_id', '=', special.production_id.id), ('state', '!=', 'cancel')]) if not workorder: if special.route_id.routing_type == '表面工艺': product_production_process = self.env['product.template'].search( @@ -100,7 +100,7 @@ class ProductionTechnologyWizard(models.TransientModel): else: workorders_values.append( self.env['mrp.workorder'].json_workorder_str(special.production_id, special)) - special.production_id.write({'workorder_ids': workorders_values}) + special.production_id.write({'workorder_ids': workorders_values}) else: if len(workorder.blocked_by_workorder_ids) > 1: if workorder.sequence == 1: diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 6a1d3023..fb9d1d5b 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -248,38 +248,19 @@ class RePurchaseOrder(models.Model): def get_purchase_order(self, consecutive_process_parameters, production, product_id_to_production_names): server_product_process = [] - production_process = product_id_to_production_names.get( - production.product_id.id) - purchase_order = self.env['purchase.order'].search( - [('state', '=', 'draft'), ('origin', '=', production.name), - ('purchase_type', '=', 'consignment')], order='name asc') for pp in consecutive_process_parameters: - server_template = self.env['product.template'].search( - [('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id), - ('detailed_type', '=', 'service')]) - if not purchase_order: + purchase_order = pp._get_surface_technics_purchase_ids() + if purchase_order: + purchase_order.write({'state': 'draft'}) + else: + server_template = self.env['product.template'].search( + [('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id), + ('detailed_type', '=', 'service')]) server_product_process.append((0, 0, { 'product_id': server_template.product_variant_id.id, 'product_qty': 1, 'product_uom': server_template.uom_id.id })) - for purchase in purchase_order: - for po in purchase.order_line: - if po.product_id == server_template.product_variant_id: - continue - if server_template.server_product_process_parameters_id != po.product_id.server_product_process_parameters_id: - purchase_order_line = self.env['purchase.order.line'].search( - [('product_id', '=', server_template.product_variant_id.id), - ('product_qty', '=', 1.0), ('id', '=', purchase.id)], limit=1, - order='id desc') - if not purchase_order_line: - server_product_process.append((0, 0, { - 'product_id': server_template.product_variant_id.id, - 'product_qty': 1, - 'product_uom': server_template.uom_id.id - })) - - if server_product_process: purchase_order = self.env['purchase.order'].sudo().create({ 'partner_id': server_template.seller_ids[0].partner_id.id, 'origin': production.name,