From 09ba001b06bffefa9dbb3ca7a6123ecbc6566ded Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Mon, 24 Feb 2025 13:38:02 +0800 Subject: [PATCH] =?UTF-8?q?sf-=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83-?= =?UTF-8?q?=E5=AE=A2=E4=BE=9B=E6=96=99=E5=85=A5=E5=BA=93=E5=8D=95-?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=90=8E=E7=9A=84=E5=AE=A2=E4=BE=9B=E6=96=99?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E5=8D=95=E7=9A=84=E9=9B=B6=E4=BB=B6=E5=9B=BE?= =?UTF-8?q?=E5=8F=B7=E6=98=BE=E7=A4=BA=E5=90=8D=E7=A7=B0=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/stock.py | 42 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) 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(