Accept Merge Request #1959: (feature/tool_standard_library_process -> develop)

Merge Request: 调拨单零件图号零件名称计算逻辑 错误处理

Created By: @廖丹龙
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @廖丹龙
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1959
This commit is contained in:
廖丹龙
2025-03-24 14:55:24 +08:00
committed by Coding

View File

@@ -2,6 +2,7 @@
import base64
import random
import re
import traceback
import qrcode
from itertools import groupby
@@ -292,7 +293,8 @@ class StockRule(models.Model):
if production_item.product_id.id in product_id_to_production_names:
# 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递
if not production_item.programming_no and production_item.production_type in ['自动化产线加工', '人工线下加工']:
if not production_item.programming_no and production_item.production_type in ['自动化产线加工',
'人工线下加工']:
if not production_programming.programming_no:
production_item.fetchCNC(
', '.join(product_id_to_production_names[production_item.product_id.id]))
@@ -587,7 +589,7 @@ class StockPicking(models.Model):
item.address_of_delivery = sale_info.address_of_delivery
# 设置外协出入单的名称
def _get_name_Res(self, rescode,sequence):
def _get_name_Res(self, rescode, sequence):
last_picking = self.sudo().search([('name', 'ilike', rescode)], order='name desc', limit=1)
sequence_id = sequence.next_by_id()
name_without_prefix = last_picking.name.removeprefix(rescode)
@@ -624,7 +626,8 @@ class StockPicking(models.Model):
if move_in:
workorder = move_in.subcontract_workorder_id
workorders = workorder.production_id.workorder_ids
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True and wo.state!='cancel').sorted('sequence')
subcontract_workorders = workorders.filtered(
lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
# if workorder == subcontract_workorders[-1]:
# self.env['stock.quant']._update_reserved_quantity(
# move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty,
@@ -750,63 +753,69 @@ class ReStockMove(models.Model):
@api.depends('product_id')
def _compute_part_info(self):
for move in self:
if move.product_id.categ_id.type == '成品':
move.part_number = move.product_id.part_number
move.part_name = move.product_id.part_name
elif move.product_id.categ_id.type == '坯料':
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)
try:
for move in self:
if move.product_id.categ_id.type == '成品':
move.part_number = move.product_id.part_number
move.part_name = move.product_id.part_name
elif move.product_id.categ_id.type == '坯料':
product_name = ''
match = re.search(r'(S\d{5}-\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: re.search(f'{product_name}$', production.product_id.name)
)
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: re.search(f'{product_name}$', production.product_id.name)
)
if filtered_order_line:
move.part_number = filtered_order_line.part_number
move.part_name = filtered_order_line.part_name
elif move.product_id.categ_id.type == '原材料':
production_id = move.production_id or move.raw_material_production_id
if not production_id:
if not move.origin:
continue
production_id = self.env['mrp.production'].sudo().search(
[('name', '=', move.origin)],limit=1)
if filtered_order_line:
move.part_number = filtered_order_line.part_number
move.part_name = filtered_order_line.part_name
elif move.product_id.categ_id.type == '原材料':
production_id = move.production_id or move.raw_material_production_id
if not production_id:
continue
product_name = ''
logging.info('制造订单的产品',production_id.product_id.name)
match = re.search(r'(S\d{5}-\d)', production_id.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+)', production_id.product_id.name)
if not move.origin:
continue
logging.info('制造订单的调拨单', move.origin)
production_id = self.env['mrp.production'].sudo().search(
[('name', '=', move.origin)], limit=1)
if not production_id:
continue
product_name = ''
logging.info('制造订单的产品', production_id.product_id.name)
match = re.search(r'(S\d{5}-\d)', production_id.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: re.search(f'{product_name}$', production.product_id.name)
)
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+)', production_id.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: re.search(f'{product_name}$', production.product_id.name)
)
if filtered_order_line:
move.part_number = filtered_order_line.part_number
move.part_name = filtered_order_line.part_name
except Exception as e:
traceback_error = traceback.format_exc()
logging.error("零件图号 零件名称获取失败:%s" % traceback_error)
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(
@@ -839,7 +848,7 @@ class ReStockMove(models.Model):
picking_type_id = self.env.ref('sf_manufacturing.outcontract_picking_in').id
sequence = self.env.ref('sf_manufacturing.sequence_stock_picking_in')
return {
'name': self.env['stock.picking']._get_name_Res(rescode,sequence),
'name': self.env['stock.picking']._get_name_Res(rescode, sequence),
'origin': item.name,
'surface_technics_parameters_id': sorted_workorders.surface_technics_parameters_id.id,
'company_id': self.mapped('company_id').id,
@@ -1064,7 +1073,8 @@ class ReStockMove(models.Model):
[('origin', '=', production.origin), ('product_id', '=', production.product_id.id)])
res['origin'] = ','.join(productions.mapped('name'))
if self.picking_type_id.name == '客供料入库':
self.picking_id.sudo().write({'origin': res['origin'] if res.get('origin') else self[0].picking_id.origin})
self.picking_id.sudo().write(
{'origin': res['origin'] if res.get('origin') else self[0].picking_id.origin})
return res
def _get_new_picking_values(self):