From 3baf3e60e8879d09d21f3e05df185665ff662aa3 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Thu, 13 Mar 2025 17:21:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=96=E5=8D=8F=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E5=8D=95=E6=A0=B9=E6=8D=AE=E5=9B=BE=E5=8F=B7=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=B8=8D=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/product_template.py | 28 +++++++++++++++++++-- sf_warehouse/models/model.py | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 307fbbc2..fbea675c 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -4,6 +4,7 @@ import requests import base64 import hashlib import os +import re from odoo import models, fields, api, _ from odoo.exceptions import ValidationError, UserError from odoo.modules import get_resource_path @@ -776,10 +777,33 @@ class ResProductMo(models.Model): manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) machining_drawings = fields.Binary('2D加工图纸', readonly=True) quality_standard = fields.Binary('质检标准', readonly=True) - part_name = fields.Char(string='零件名称', readonly=True) - part_number = fields.Char(string='零件图号', readonly=True) + part_name = fields.Char(string='零件名称', compute='_compute_related_product', readonly=True, store=True) + part_number = fields.Char(string='零件图号', compute='_compute_related_product', readonly=True, store=True) machining_drawings_name = fields.Char(string='零件图号名称', readonly=True) machining_drawings_mimetype = fields.Char(string='零件图号类型', readonly=True) + + @api.depends('name') + def _compute_related_product(self): + for record in self: + if record.categ_id.name == '坯料': + product_name = '' + match = re.search(r'(S\d{5}-\d)', record.name) + # 如果匹配成功,提取结果 + if match: + product_name = match.group(0) + sale_order_name = '' + match_sale = re.search(r'S(\d+)', record.name) + if match_sale: + sale_order_name = match_sale.group(0) + sale_order = self.env['sale.order'].sudo().search( + [('name', '=', sale_order_name)]) + if sale_order: + filtered_order_line = sale_order.order_line.filtered( + lambda order_line: re.search(f'{product_name}$', order_line.product_id.name) + ) + record.part_number = filtered_order_line.product_id.part_number if filtered_order_line else None + record.part_name = filtered_order_line.product_id.part_name if filtered_order_line else None + @api.constrains('tool_length') def _check_tool_length_size(self): if self.tool_length > 1000000: diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 848b1f66..65cca601 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -1140,7 +1140,7 @@ class SfPickingType(models.Model): action = super(SfPickingType, self)._get_action(action_xmlid) if not self.env.user.has_group('base.group_system'): action['context']['create'] = False - if self.sequence_code in ['DL', 'INT', 'PC']: + if self.sequence_code in ['INT', 'PC']: action['context']['search_default_retrospect'] = 1 return action