优化表面工艺排序

This commit is contained in:
jinling.yang
2024-08-25 14:58:40 +08:00
parent 9218633a5e
commit 3e438a10ee
6 changed files with 93 additions and 93 deletions

View File

@@ -446,41 +446,45 @@ class MrpProduction(models.Model):
# self.env['mrp.workorder'].json_workorder_str(k, production, route)) # self.env['mrp.workorder'].json_workorder_str(k, production, route))
# 表面工艺工序 # 表面工艺工序
# 获取表面工艺id # 获取表面工艺id
if production.product_id.model_process_parameters_ids: # 工序id
logging.info('model_process_parameters_ids:%s' % production.product_id.model_process_parameters_ids) surface_technics_arr = []
surface_technics_arr = [] route_workcenter_arr = []
# 工序id for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
route_workcenter_arr = [] if item.route_workcenter_id.surface_technics_id.id:
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: for process_param in production.product_id.model_process_parameters_ids:
surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id) logging.info('process_param:%s%s' % (process_param.id, process_param.name))
route_workcenter_arr.append(item.route_workcenter_id.id) if item.route_workcenter_id.surface_technics_id == process_param.process_id:
if surface_technics_arr: logging.info(
production_process = self.env['sf.production.process'].search( 'surface_technics_id:%s%s' % (item.route_workcenter_id.surface_technics_id.id,
[('parameter_ids.id', 'in', surface_technics_arr)], item.route_workcenter_id.surface_technics_id.name))
order='sequence asc' surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id)
) route_workcenter_arr.append(item.route_workcenter_id.id)
if production_process: if surface_technics_arr:
for p in production_process: production_process = self.env['sf.production.process'].search(
logging.info('production_process:%s' % p.name) [('id', 'in', surface_technics_arr)],
if production_process: order='sequence asc'
process_parameter = production.product_id.model_process_parameters_ids.filtered( )
lambda pm: pm.process_id.id == p.id) for p in production_process:
if process_parameter: logging.info('production_process:%s' % p.name)
# 产品为表面工艺服务的供应商 # if production_process:
product_production_process = self.env['product.template'].search( process_parameter = production.product_id.model_process_parameters_ids.filtered(
[('server_product_process_parameters_id', '=', process_parameter.id)]) lambda pm: pm.process_id.id == p.id)
if product_production_process: if process_parameter:
route_production_process = self.env[ # 产品为表面工艺服务的供应商
'mrp.routing.workcenter'].search( product_production_process = self.env['product.template'].search(
[('surface_technics_id', '=', p.id), [('server_product_process_parameters_id', '=', process_parameter.id)])
('id', 'in', route_workcenter_arr)]) if product_production_process:
if route_production_process: route_production_process = self.env[
workorders_values.append( 'mrp.routing.workcenter'].search(
self.env[ [('surface_technics_id', '=', p.id),
'mrp.workorder']._json_workorder_surface_process_str( ('id', 'in', route_workcenter_arr)])
production, route_production_process, if route_production_process:
process_parameter, workorders_values.append(
product_production_process.seller_ids[0].partner_id.id)) self.env[
'mrp.workorder']._json_workorder_surface_process_str(
production, route_production_process,
process_parameter,
product_production_process.seller_ids[0].partner_id.id))
elif production.product_id.categ_id.type == '坯料': elif production.product_id.categ_id.type == '坯料':
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search( embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)], [('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],

View File

@@ -9,8 +9,8 @@ from odoo.exceptions import ValidationError, UserError
from odoo.modules import get_resource_path from odoo.modules import get_resource_path
# from OCC.Extend.DataExchange import read_step_file from OCC.Extend.DataExchange import read_step_file
# from OCC.Extend.DataExchange import write_stl_file from OCC.Extend.DataExchange import write_stl_file
class ResProductMo(models.Model): class ResProductMo(models.Model):

View File

@@ -177,10 +177,10 @@ class StockRule(models.Model):
for company_id, moves_values in moves_values_by_company.items(): for company_id, moves_values in moves_values_by_company.items():
# create the move as SUPERUSER because the current user may not have the rights to do it (mto product # create the move as SUPERUSER because the current user may not have the rights to do it (mto product
# launched by a sale for example) # launched by a sale for example)
logging.info(moves_values) # logging.info(moves_values)
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
moves_values) moves_values)
logging.info(moves) # logging.info(moves)
# Since action_confirm launch following procurement_group we should activate it. # Since action_confirm launch following procurement_group we should activate it.
moves._action_confirm() moves._action_confirm()

View File

@@ -24,26 +24,28 @@ class Sf_Mrs_Connect(http.Controller):
ret = json.loads(datas) ret = json.loads(datas)
ret = json.loads(ret['result']) ret = json.loads(ret['result'])
logging.info('下发编程单:%s' % ret) logging.info('下发编程单:%s' % ret)
domain = [('programming_no', '=', ret['programming_no'])]
if ret['manufacturing_type'] == 'scrap':
domain += [('state', 'not in', ['done', 'scrap'])]
productions = request.env['mrp.production'].with_user( productions = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search( request.env.ref("base.user_admin")).search(domain)
[('programming_no', '=', ret['programming_no'])])
if productions: if productions:
# # 拉取所有加工面的程序文件 # 拉取所有加工面的程序文件
# for r in ret['processing_panel'].split(','): for r in ret['processing_panel'].split(','):
# program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
# if os.path.exists(program_path_tmp_r): if os.path.exists(program_path_tmp_r):
# files_r = os.listdir(program_path_tmp_r) files_r = os.listdir(program_path_tmp_r)
# if files_r: if files_r:
# for file_name in files_r: for file_name in files_r:
# file_path = os.path.join(program_path_tmp_r, file_name) file_path = os.path.join(program_path_tmp_r, file_name)
# os.remove(file_path) os.remove(file_path)
# download_state = request.env['sf.cnc.processing'].with_user( download_state = request.env['sf.cnc.processing'].with_user(
# request.env.ref("base.user_admin")).download_file_tmp( request.env.ref("base.user_admin")).download_file_tmp(
# ret['folder_name'], r) ret['folder_name'], r)
# if download_state is False: if download_state is False:
# res['status'] = -2 res['status'] = -2
# res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
# return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
for production in productions: for production in productions:
if not production.workorder_ids: if not production.workorder_ids:
production.product_id.model_processing_panel = ret['processing_panel'] production.product_id.model_processing_panel = ret['processing_panel']
@@ -82,38 +84,32 @@ 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 = productions.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 = productions.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]
# workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
# [('production_id', 'in', cnc_program_ids)])
# if workpiece_delivery:
# workpiece_delivery.write(
# {'is_cnc_program_down': True, 'production_line_id': productions.production_line_id.id})
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
else: else:
res = {'status': 0, 'message': '该制造订单暂未开始'} res = {'status': 0, 'message': '该制造订单暂未开始'}

View File

@@ -8,8 +8,8 @@ from datetime import datetime
import requests import requests
from odoo import http from odoo import http
from odoo.http import request from odoo.http import request
# from OCC.Extend.DataExchange import read_step_file from OCC.Extend.DataExchange import read_step_file
# from OCC.Extend.DataExchange import write_stl_file from OCC.Extend.DataExchange import write_stl_file
from odoo import models, fields, api from odoo import models, fields, api
from odoo.modules import get_resource_path from odoo.modules import get_resource_path
from odoo.exceptions import ValidationError, UserError from odoo.exceptions import ValidationError, UserError

View File

@@ -6,8 +6,8 @@ import os
from datetime import datetime from datetime import datetime
from stl import mesh from stl import mesh
# from OCC.Core.GProp import GProp_GProps # from OCC.Core.GProp import GProp_GProps
# from OCC.Extend.DataExchange import read_step_file from OCC.Extend.DataExchange import read_step_file
# from OCC.Extend.DataExchange import write_stl_file from OCC.Extend.DataExchange import write_stl_file
from odoo.addons.sf_base.commons.common import Common from odoo.addons.sf_base.commons.common import Common
from odoo import models, fields, api from odoo import models, fields, api
from odoo.modules import get_resource_path from odoo.modules import get_resource_path