修复表面工艺外协及工艺设计

This commit is contained in:
jinling.yang
2024-11-28 15:59:17 +08:00
parent da22cb301e
commit c42c053d66
8 changed files with 147 additions and 159 deletions

View File

@@ -1204,21 +1204,21 @@ class ResMrpWorkOrder(models.Model):
if self.sequence == 1: if self.sequence == 1:
# 判断工单状态是否为等待组件 # 判断工单状态是否为等待组件
if self.state == 'waiting': # if self.state == 'waiting':
raise UserError('制造订单【%s】缺少组件信息!' % self.production_id.name) # raise UserError('制造订单【%s】缺少组件信息' % self.production_id.name)
# 判断是否有坯料的序列号信息 # # 判断是否有坯料的序列号信息
boolean = False # boolean = False
if self.production_id.move_raw_ids: # if self.production_id.move_raw_ids:
if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料': # if self.production_id.move_raw_ids[0].product_id.categ_type == '坯料':
if self.production_id.move_raw_ids[0].move_line_ids: # if self.production_id.move_raw_ids[0].move_line_ids:
if self.production_id.move_raw_ids[0].move_line_ids: # if self.production_id.move_raw_ids[0].move_line_ids:
if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name: # if self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
boolean = True # boolean = True
else: # else:
boolean = True # boolean = True
if not boolean: # if not boolean:
raise UserError('制造订单【%s】缺少组件的序列号信息!' % self.production_id.name) # raise UserError('制造订单【%s】缺少组件的序列号信息' % self.production_id.name)
self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name # self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name
# cnc校验 # cnc校验
if self.production_id.production_type == '自动化产线加工': if self.production_id.production_type == '自动化产线加工':
cnc_workorder = self.search( cnc_workorder = self.search(
@@ -1247,10 +1247,14 @@ class ResMrpWorkOrder(models.Model):
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
('location_dest_id', '=', self.env['stock.location'].search( ('location_dest_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'VL-SPOC')]).id), [('barcode', 'ilike', 'VL-SPOC')]).id),
('origin', '=', self.production_id.name)]) ('origin', '=', self.production_id.name), ('state', 'not in', ['cancel', 'done'])])
if move_out.state != 'done': for mo in move_out:
move_out.write({'state': 'assigned', 'production_id': False}) pick = self.env['stock.picking'].search([('id', '=', mo.picking_id.id), ('name', 'ilike', 'OCOUT'),
self.env['stock.move.line'].create(move_out.get_move_line(self.production_id, self)) ('partner_id', '=', self.supplier_id.id)])
if pick:
if mo.state != 'done':
mo.write({'state': 'assigned', 'production_id': False})
self.env['stock.move.line'].create(mo.get_move_line(self.production_id, self))
# move_out._action_assign() # move_out._action_assign()
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress': if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
@@ -1315,11 +1319,11 @@ class ResMrpWorkOrder(models.Model):
def button_finish(self): def button_finish(self):
for record in self: for record in self:
if record.routing_type == '装夹预调': if record.routing_type == '装夹预调':
if not record.rfid_code and record.is_rework is False: # if not record.rfid_code and record.is_rework is False:
raise UserError("请扫RFID码进行绑定") # raise UserError("请扫RFID码进行绑定")
if record.is_rework is False: # if record.is_rework is False:
if not record.material_center_point: # if not record.material_center_point:
raise UserError("坯料中心点为空,请检查") # raise UserError("坯料中心点为空,请检查")
# if record.X_deviation_angle <= 0: # if record.X_deviation_angle <= 0:
# raise UserError("X偏差角度小于等于0请检查本次计算的X偏差角度为%s" % record.X_deviation_angle) # raise UserError("X偏差角度小于等于0请检查本次计算的X偏差角度为%s" % record.X_deviation_angle)
record.process_state = '待加工' record.process_state = '待加工'

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

@@ -290,7 +290,7 @@ class StockRule(models.Model):
else: else:
mrp_production = production mrp_production = production
# if sale_order: # if sale_order:
# sale_order.write({'schedule_status': 'to schedule'}) # sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(company_id).create({ self.env['sf.production.plan'].sudo().with_company(company_id).create({
'name': production.name, 'name': production.name,
'order_deadline': sale_order.deadline_of_delivery, 'order_deadline': sale_order.deadline_of_delivery,
@@ -301,7 +301,6 @@ class StockRule(models.Model):
'product_id': production.product_id.id, 'product_id': production.product_id.id,
'state': 'draft', 'state': 'draft',
}) })
technology_design_values = []
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对应的生产订单名称列表
@@ -311,6 +310,7 @@ class StockRule(models.Model):
# 为同一个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:
technology_design_values = []
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)],
@@ -325,70 +325,69 @@ class StockRule(models.Model):
else: else:
production_item.write({'programming_no': production_programming.programming_no, production_item.write({'programming_no': production_programming.programming_no,
'programming_state': '编程中'}) 'programming_state': '编程中'})
if not technology_design_values: i = 0
i = 0 if production_item.product_id.categ_id.type == '成品':
if production_item.product_id.categ_id.type == '成品': # 根据加工面板的面数及成品工序模板生成工序设计
# 根据加工面板的面数及成品工序模板生成工序设计 if production_item.production_type == '自动化产线加工':
if production_item.production_type == '自动化产线加工': model = 'sf.product.model.type.routing.sort'
model = 'sf.product.model.type.routing.sort' domain = [
domain = [ ('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)]
('product_model_type_id', '=', production_item.product_id.product_model_type_id.id)] else:
else: model = 'sf.manual.product.model.type.routing.sort'
model = 'sf.manual.product.model.type.routing.sort' domain = [('manual_product_model_type_id', '=',
domain = [('manual_product_model_type_id', '=', production_item.product_id.product_model_type_id.id)]
production_item.product_id.product_model_type_id.id)] product_routing_workcenter = self.env[model].search(domain, order='sequence asc')
product_routing_workcenter = self.env[model].search(domain, order='sequence asc') if production_item.production_type == '自动化产线加工':
if production_item.production_type == '自动化产线加工': for k in (production_item.product_id.model_processing_panel.split(',')):
for k in (production_item.product_id.model_processing_panel.split(',')):
for route in product_routing_workcenter:
i += 1
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
else:
for route in product_routing_workcenter: for route in product_routing_workcenter:
i += 1 i += 1
technology_design_values.append( technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route, i, False)) self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
elif production_item.product_id.categ_id.type == '坯料': else:
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search( for route in product_routing_workcenter:
[('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
order='sequence asc'
)
for route_embryo in embryo_routing_workcenter:
i += 1 i += 1
technology_design_values.append( technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i, self.env['sf.technology.design'].json_technology_design_str(False, route, i, False))
False)) elif production_item.product_id.categ_id.type == '坯料':
surface_technics_arr = [] embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
route_workcenter_arr = [] [('embryo_model_type_id', '=', production_item.product_id.embryo_model_type_id.id)],
for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: order='sequence asc'
if item.route_workcenter_id.surface_technics_id.id: )
for process_param in production_item.product_id.model_process_parameters_ids: for route_embryo in embryo_routing_workcenter:
if item.route_workcenter_id.surface_technics_id == process_param.process_id: i += 1
surface_technics_arr.append( technology_design_values.append(
item.route_workcenter_id.surface_technics_id.id) self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
route_workcenter_arr.append(item.route_workcenter_id.id) False))
if surface_technics_arr: surface_technics_arr = []
production_process = self.env['sf.production.process'].search( route_workcenter_arr = []
[('id', 'in', surface_technics_arr)], for item in production_item.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
order='sequence asc' if item.route_workcenter_id.surface_technics_id.id:
) for process_param in production_item.product_id.model_process_parameters_ids:
for p in production_process: if item.route_workcenter_id.surface_technics_id == process_param.process_id:
logging.info('production_process:%s' % p.name) surface_technics_arr.append(
process_parameter = production_item.product_id.model_process_parameters_ids.filtered( item.route_workcenter_id.surface_technics_id.id)
lambda pm: pm.process_id.id == p.id) route_workcenter_arr.append(item.route_workcenter_id.id)
if process_parameter: if surface_technics_arr:
i += 1 production_process = self.env['sf.production.process'].search(
route_production_process = self.env[ [('id', 'in', surface_technics_arr)],
'mrp.routing.workcenter'].search( order='sequence asc'
[('surface_technics_id', '=', p.id), )
('id', 'in', route_workcenter_arr)]) for p in production_process:
technology_design_values.append( logging.info('production_process:%s' % p.name)
self.env['sf.technology.design'].json_technology_design_str(False, process_parameter = production_item.product_id.model_process_parameters_ids.filtered(
route_production_process, lambda pm: pm.process_id.id == p.id)
i, if process_parameter:
process_parameter)) i += 1
productions.technology_design_ids = technology_design_values route_production_process = self.env[
'mrp.routing.workcenter'].search(
[('surface_technics_id', '=', p.id),
('id', 'in', route_workcenter_arr)])
technology_design_values.append(
self.env['sf.technology.design'].json_technology_design_str(False,
route_production_process,
i,
process_parameter))
production_item.technology_design_ids = technology_design_values
productions.write({'state': 'technology_to_confirmed'}) productions.write({'state': 'technology_to_confirmed'})
return True return True
@@ -634,39 +633,24 @@ class StockPicking(models.Model):
return '%s%s' % (rescode, num) return '%s%s' % (rescode, num)
def button_validate(self): def button_validate(self):
if self.picking_type_id.barcode == 'OCOUT': res = super().button_validate()
move_out = self.env['stock.move'].search( if res is True and self.picking_type_id.sequence_code == 'OCOUT':
[('location_id', '=', self.env['stock.location'].search( # if self.id == move_out.picking_id.id:
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), # if move_out.move_line_ids.workorder_id.state == 'progress':
('location_dest_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'VL-SPOC')]).id),
('origin', '=', self.origin)])
move_in = self.env['stock.move'].search( move_in = self.env['stock.move'].search(
[('location_dest_id', '=', self.env['stock.location'].search( [('location_dest_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id), [('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
('location_id', '=', self.env['stock.location'].search( ('location_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'VL-SPOC')]).id), [('barcode', 'ilike', 'VL-SPOC')]).id),
('origin', '=', self.origin), ('picking_id', '=', self.id)]) ('origin', '=', self.origin), ('state', 'not in', ['cancel', 'done'])])
if self.location_id == move_in.location_id and self.location_dest_id == move_in.location_dest_id: production = self.env['mrp.production'].search([('name', '=', self.origin)])
if move_out.origin == move_in.origin: for mi in move_in:
move_in.write({'production_id': False}) pick = self.env['stock.picking'].search([('id', '=', mi.picking_id.id), ('name', 'ilike', 'OCIN'),
if move_out.picking_id.state != 'done': ('partner_id', '=', self.partner_id.id)])
raise UserError( if pick:
_('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % move_out.picking_id.name)) if mi.state != 'done':
res = super().button_validate() mi.write({'state': 'assigned'})
if res is True and self.picking_type_id.barcode == 'OCIN': self.env['stock.move.line'].create(mi.get_move_line(production, None))
if self.id == move_out.picking_id.id:
# if move_out.move_line_ids.workorder_id.state == 'progress':
move_in = self.env['stock.move'].search(
[('location_dest_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'WH-PREPRODUCTION')]).id),
('location_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'VL-SPOC')]).id),
('origin', '=', self.origin)])
production = self.env['mrp.production'].search([('name', '=', self.origin)])
if move_in.state != 'done':
move_in.write({'state': 'assigned'})
self.env['stock.move.line'].create(move_in.get_move_line(production, None))
return res return res

View File

@@ -83,7 +83,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
workorder.picking_ids.write({'state': 'cancel'}) workorder.picking_ids.write({'state': 'cancel'})
workorder.picking_ids.move_ids.write({'state': 'cancel'}) workorder.picking_ids.move_ids.write({'state': 'cancel'})
purchase_order = self.env['purchase.order'].search( purchase_order = self.env['purchase.order'].search(
[('origin', '=', workorder.production_id.origin)]) [('origin', '=', workorder.production_id.name)])
for line in purchase_order.order_line: for line in purchase_order.order_line:
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id: if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id:
purchase_order.write({'state': 'cancel'}) purchase_order.write({'state': 'cancel'})

View File

@@ -80,7 +80,7 @@ class ProductionTechnologyWizard(models.TransientModel):
workorder.picking_ids.write({'state': 'cancel'}) workorder.picking_ids.write({'state': 'cancel'})
workorder.picking_ids.move_ids.write({'state': 'cancel'}) workorder.picking_ids.move_ids.write({'state': 'cancel'})
purchase_order = self.env['purchase.order'].search( purchase_order = self.env['purchase.order'].search(
[('origin', '=', workorder.production_id.origin)]) [('origin', '=', workorder.production_id.name)])
for line in purchase_order.order_line: for line in purchase_order.order_line:
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id: if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id:
purchase_order.write({'state': 'cancel'}) purchase_order.write({'state': 'cancel'})

View File

@@ -40,21 +40,21 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
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:
production.write({'programming_state': '已编程', 'work_state': '已编程'}) production.write({'programming_state': '已编程', 'work_state': '已编程'})
for panel in ret['processing_panel'].split(','): for panel in ret['processing_panel'].split(','):
@@ -72,29 +72,29 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
cnc_workorder_has.write( cnc_workorder_has.write(
{'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret), {'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret),
'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)}) 'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)})
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', 'rework' # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework'
'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)
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]
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', 'rework' # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework'
'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': '已编程'})
logging.info('已更新制造订单编程状态:%s' % productions.ids) logging.info('已更新制造订单编程状态:%s' % productions.ids)
res.update({ res.update({

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

@@ -5,8 +5,8 @@ import requests
import os import os
from datetime import datetime from datetime import datetime
# 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