diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 901b521b..dc8cc437 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- import base64 +import random +import re + import qrcode from itertools import groupby from collections import defaultdict, namedtuple @@ -738,25 +741,26 @@ class ReStockMove(models.Model): move.part_number = move.product_id.part_number move.part_name = move.product_id.part_name elif move.product_id.categ_id.type == '坯料': - if move.origin: - origin = move.origin.split(',')[0] if ',' in move.origin else move.origin - mrp_productio_info = self.env['mrp.production'].sudo().search( - [('name', '=', origin)]) - if mrp_productio_info: - move.part_number = mrp_productio_info.part_number - move.part_name = mrp_productio_info.part_name - else: - purchase_order_info = self.env['purchase.order'].sudo().search( - [('name', '=', origin)]) - if purchase_order_info: - mrp_production_ids = purchase_order_info._get_mrp_productions().ids - if mrp_production_ids: - mrp_productio_info = self.env['mrp.production'].sudo().search( - [('id', '=', mrp_production_ids[0])]) - if mrp_productio_info: - move.part_number = mrp_productio_info.part_number - move.part_name = mrp_productio_info.part_name - + product_name = '' + match = re.search(r'(S\d{5}-\d)', move.product_id.name) + # 如果匹配成功,提取结果 + if match: + product_name = match.group(0) + if move.picking_id.sale_order_id: + sale_order = move.picking_id.sale_order_id + else: + sale_order_name = '' + match = re.search(r'(S\d+)', move.product_id.name) + if match: + sale_order_name = match.group(0) + sale_order = self.env['sale.order'].sudo().search( + [('name', '=', sale_order_name)]) + filtered_order_line = sale_order.order_line.filtered( + lambda production: product_name in production.product_id.name + ) + if filtered_order_line: + move.part_number = filtered_order_line.part_number + move.part_name = filtered_order_line.part_name def _get_stock_move_values_Res(self, item, picking_type_id, group_id, move_dest_ids=False): route_id = self.env.ref('sf_manufacturing.route_surface_technology_outsourcing').id stock_rule = self.env['stock.rule'].sudo().search(