修复无外协单和程序单

This commit is contained in:
jinling.yang
2024-06-30 17:52:02 +08:00
parent fd3a363bf6
commit e124560089
2 changed files with 51 additions and 51 deletions

View File

@@ -204,14 +204,14 @@ class StockRule(models.Model):
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
productions_values) productions_values)
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
''' '''
创建工单 创建工单
''' '''
# productions._create_workorder() # productions._create_workorder()
# #
self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) # self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \ productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
( (
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_dest_ids.procure_method != 'make_to_order' and not
@@ -261,30 +261,30 @@ class StockRule(models.Model):
'product_id': production.product_id.id, 'product_id': production.product_id.id,
'state': 'draft', 'state': 'draft',
}) })
# all_production = productions all_production = productions
# grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)} grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)}
# # 初始化一个字典来存储每个product_id对应的生产订单名称列表 # 初始化一个字典来存储每个product_id对应的生产订单名称列表
# product_id_to_production_names = {} product_id_to_production_names = {}
# # 对于每个product_id获取其所有生产订单的名称 # 对于每个product_id获取其所有生产订单的名称
# for product_id, all_production in grouped_product_ids.items(): for product_id, all_production in grouped_product_ids.items():
# # 为同一个product_id创建一个生产订单名称列表 # 为同一个product_id创建一个生产订单名称列表
# product_id_to_production_names[product_id] = [production.name for production in all_production] product_id_to_production_names[product_id] = [production.name for production in all_production]
# for production_item in productions: for production_item in productions:
# 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: if not production_item.programming_no:
# production_programming = self.env['mrp.production'].search( production_programming = self.env['mrp.production'].search(
# [('product_id.id', '=', production_item.product_id.id), [('product_id.id', '=', production_item.product_id.id),
# ('origin', '=', production_item.origin)], ('origin', '=', production_item.origin)],
# limit=1, order='id asc') limit=1, order='id asc')
# 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]))
# else: else:
# production_item.write({'programming_no': production_programming.programming_no, production_item.write({'programming_no': production_programming.programming_no,
# 'programming_state': '编程中'}) 'programming_state': '编程中'})
# return True return True
class ProductionLot(models.Model): class ProductionLot(models.Model):

View File

@@ -82,31 +82,31 @@ class Sf_Mrs_Connect(http.Controller):
# if pre_workorder: # if pre_workorder:
# pre_workorder.write( # pre_workorder.write(
# {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
for panel in ret['processing_panel'].split(','): for panel in ret['processing_panel'].split(','):
# 查询状态为进行中且工序类型为CNC加工的工单 # 查询状态为进行中且工序类型为CNC加工的工单
cnc_workorder = production.workorder_ids.filtered( cnc_workorder = productions.workorder_ids.filtered(
lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done',
'cancel'] and ac.processing_panel == panel) 'cancel'] and ac.processing_panel == panel)
if cnc_workorder: if cnc_workorder:
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
# panel) # panel)
program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel)
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
files_panel = os.listdir(program_path_tmp_panel) files_panel = os.listdir(program_path_tmp_panel)
if files_panel: if files_panel:
for file in files_panel: for file in files_panel:
file_extension = os.path.splitext(file)[1] file_extension = os.path.splitext(file)[1]
logging.info('file_extension:%s' % file_extension) logging.info('file_extension:%s' % file_extension)
if file_extension.lower() == '.pdf': if file_extension.lower() == '.pdf':
panel_file_path = os.path.join(program_path_tmp_panel, file) panel_file_path = os.path.join(program_path_tmp_panel, file)
logging.info('panel_file_path:%s' % panel_file_path) logging.info('panel_file_path:%s' % panel_file_path)
cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
pre_workorder = production.workorder_ids.filtered( pre_workorder = productions.workorder_ids.filtered(
lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done',
'cancel'] and ap.processing_panel == panel) 'cancel'] and ap.processing_panel == panel)
if pre_workorder: if pre_workorder:
pre_workorder.write( pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
productions.write({'programming_state': '已编程', 'work_state': '已编程'}) productions.write({'programming_state': '已编程', 'work_state': '已编程'})
cnc_program_ids = [item.id for item in productions] cnc_program_ids = [item.id for item in productions]
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(