diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index 72ed971e..e15c25e6 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - +import re from collections import defaultdict from odoo import api, fields, models, _ @@ -109,15 +109,37 @@ class PurchaseOrder(models.Model): class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' - part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True) + part_number = fields.Char('零件图号', store=True, compute='_compute_origin_sale_id') + part_name = fields.Char('零件图号', store=True, + compute='_compute_origin_sale_id') related_product = fields.Many2one('product.product', string='关联产品', help='经此产品工艺加工成的成品') - - # @api.depends('order_id.origin') - # def _compute_related_product(self): - # for record in self: - # if record.product_id.detailed_type: - # production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)]) - # record.related_product = production_id.product_id if production_id else False - # else: - # record.related_product = False + @api.depends('product_id') + def _compute_related_product(self): + for record in self: + if record.product_id.categ_id.name == '坯料': + product_name = '' + match = re.search(r'(S\d{5}-\d)', record.product_id.name) + # 如果匹配成功,提取结果 + if match: + product_name = match.group(0) + sale_order_name = '' + match_sale = re.search(r'(S\d+)', record.product_id.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: product_name in 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 + else: + record.part_number = record.product_id.part_number + record.part_name = record.product_id.part_name + # if record.product_id.detailed_type: + # production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)]) + # record.related_product = production_id.product_id if production_id else False + # else: + # record.related_product = False diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index 16b0da2f..d7444afb 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -2305,6 +2305,8 @@ class Cutting_tool_standard_library(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['cutting_tool_standard_library_all_list']: + if item['code'] == 'JKM-T-DJWL-ZTDJ-20250225001': + print('qwfhuiuiohfqwuio') cutting_tool_standard_library = self.search( [("code", '=', item['code']), ("active", 'in', [True, False])]) @@ -2385,8 +2387,8 @@ class Cutting_tool_standard_library(models.Model): "handle_id": False if not item['handle_code'] else self.search( [('code', '=', item['handle_code'])]).id, "suitable_machining_method_ids": [(6, 0, [])] if not item.get( - 'suitable_machining_methods') else self.env['maintenance.equipment.image']._get_ids( - item['suitable_machining_methods']), + 'suitable_machining_method') else self.env['maintenance.equipment.image']._get_ids( + item['suitable_machining_method']), "blade_tip_characteristics_id": self.env['maintenance.equipment.image'].search( [('name', '=', item['blade_tip_characteristics'])]).id, "handle_type_id": self.env['maintenance.equipment.image'].search(