Merge branch 'develop' into feature/commercially_launched

This commit is contained in:
胡尧
2025-03-24 14:56:16 +08:00

View File

@@ -2,6 +2,7 @@
import base64 import base64
import random import random
import re import re
import traceback
import qrcode import qrcode
from itertools import groupby from itertools import groupby
@@ -292,7 +293,8 @@ class StockRule(models.Model):
if production_item.product_id.id in product_id_to_production_names: if production_item.product_id.id in product_id_to_production_names:
# 同一个产品多个制造订单对应一个编程单和模型库 # 同一个产品多个制造订单对应一个编程单和模型库
# 只调用一次fetchCNC并将所有生产订单的名称作为字符串传递 # 只调用一次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: if not production_programming.programming_no:
production_item.fetchCNC( production_item.fetchCNC(
', '.join(product_id_to_production_names[production_item.product_id.id])) ', '.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 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) last_picking = self.sudo().search([('name', 'ilike', rescode)], order='name desc', limit=1)
sequence_id = sequence.next_by_id() sequence_id = sequence.next_by_id()
name_without_prefix = last_picking.name.removeprefix(rescode) name_without_prefix = last_picking.name.removeprefix(rescode)
@@ -624,7 +626,8 @@ class StockPicking(models.Model):
if move_in: if move_in:
workorder = move_in.subcontract_workorder_id workorder = move_in.subcontract_workorder_id
workorders = workorder.production_id.workorder_ids 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]: # if workorder == subcontract_workorders[-1]:
# self.env['stock.quant']._update_reserved_quantity( # self.env['stock.quant']._update_reserved_quantity(
# move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty, # 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') @api.depends('product_id')
def _compute_part_info(self): def _compute_part_info(self):
for move in self: try:
if move.product_id.categ_id.type == '成品': for move in self:
move.part_number = move.product_id.part_number if move.product_id.categ_id.type == '成品':
move.part_name = move.product_id.part_name move.part_number = move.product_id.part_number
elif move.product_id.categ_id.type == '坯料': move.part_name = move.product_id.part_name
product_name = '' elif move.product_id.categ_id.type == '坯料':
match = re.search(r'(S\d{5}-\d)', move.product_id.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: if match:
sale_order_name = match.group(0) product_name = match.group(0)
sale_order = self.env['sale.order'].sudo().search( if move.picking_id.sale_order_id:
[('name', '=', sale_order_name)]) sale_order = move.picking_id.sale_order_id
filtered_order_line = sale_order.order_line.filtered( else:
lambda production: re.search(f'{product_name}$', production.product_id.name) 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: if filtered_order_line:
move.part_number = filtered_order_line.part_number move.part_number = filtered_order_line.part_number
move.part_name = filtered_order_line.part_name move.part_name = filtered_order_line.part_name
elif move.product_id.categ_id.type == '原材料': elif move.product_id.categ_id.type == '原材料':
production_id = move.production_id or move.raw_material_production_id 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 not production_id: if not production_id:
continue if not move.origin:
product_name = '' continue
logging.info('制造订单的产品',production_id.product_id.name) logging.info('制造订单的调拨单', move.origin)
match = re.search(r'(S\d{5}-\d)', production_id.product_id.name) production_id = self.env['mrp.production'].sudo().search(
# 如果匹配成功,提取结果 [('name', '=', move.origin)], limit=1)
if match: if not production_id:
product_name = match.group(0) continue
if move.picking_id.sale_order_id: product_name = ''
sale_order = move.picking_id.sale_order_id logging.info('制造订单的产品', production_id.product_id.name)
else: match = re.search(r'(S\d{5}-\d)', production_id.product_id.name)
sale_order_name = '' # 如果匹配成功,提取结果
match = re.search(r'(S\d+)', production_id.product_id.name)
if match: if match:
sale_order_name = match.group(0) product_name = match.group(0)
sale_order = self.env['sale.order'].sudo().search( if move.picking_id.sale_order_id:
[('name', '=', sale_order_name)]) sale_order = move.picking_id.sale_order_id
filtered_order_line = sale_order.order_line.filtered( else:
lambda production: re.search(f'{product_name}$', production.product_id.name) 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): 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 route_id = self.env.ref('sf_manufacturing.route_surface_technology_outsourcing').id
stock_rule = self.env['stock.rule'].sudo().search( 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 picking_type_id = self.env.ref('sf_manufacturing.outcontract_picking_in').id
sequence = self.env.ref('sf_manufacturing.sequence_stock_picking_in') sequence = self.env.ref('sf_manufacturing.sequence_stock_picking_in')
return { return {
'name': self.env['stock.picking']._get_name_Res(rescode,sequence), 'name': self.env['stock.picking']._get_name_Res(rescode, sequence),
'origin': item.name, 'origin': item.name,
'surface_technics_parameters_id': sorted_workorders.surface_technics_parameters_id.id, 'surface_technics_parameters_id': sorted_workorders.surface_technics_parameters_id.id,
'company_id': self.mapped('company_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)]) [('origin', '=', production.origin), ('product_id', '=', production.product_id.id)])
res['origin'] = ','.join(productions.mapped('name')) res['origin'] = ','.join(productions.mapped('name'))
if self.picking_type_id.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 return res
def _get_new_picking_values(self): def _get_new_picking_values(self):