1.1修复排程工件配送没有目的生产线2.注释获取cnc程序最新代码(第二期)3.优化部分页面

This commit is contained in:
jinling.yang
2024-05-11 00:17:43 +08:00
parent b5c9387d8c
commit 2bffc5964a
7 changed files with 77 additions and 60 deletions

View File

@@ -111,11 +111,12 @@ class Sf_Bf_Connect(http.Controller):
res['message'] = '该订单模型的材料型号在您分配的工厂里暂未设置获取方式和供应商,请先配置再进行分配' res['message'] = '该订单模型的材料型号在您分配的工厂里暂未设置获取方式和供应商,请先配置再进行分配'
request.cr.rollback() request.cr.rollback()
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
# 产品配置bom else:
product_bom_purchase = request.env['mrp.bom'].with_user( # 产品配置bom
request.env.ref("base.user_admin")).bom_create(product, 'normal', False) product_bom_purchase = request.env['mrp.bom'].with_user(
product_bom_purchase.with_user(request.env.ref("base.user_admin")).bom_create_line_has( request.env.ref("base.user_admin")).bom_create(product, 'normal', False)
purchase_embryo) product_bom_purchase.with_user(request.env.ref("base.user_admin")).bom_create_line_has(
purchase_embryo)
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
i += 1 i += 1
res['factory_order_no'] = order_id.name res['factory_order_no'] = order_id.name

View File

@@ -511,7 +511,6 @@ class Manufacturing_Connect(http.Controller):
rfid_code = ret[f'RfidCode{i}'] rfid_code = ret[f'RfidCode{i}']
logging.info('RfidCode:%s' % rfid_code) logging.info('RfidCode:%s' % rfid_code)
domain = [ domain = [
('feeder_station_start_id.name', '=', ret['DeviceId']),
('workorder_id.rfid_code', '=', rfid_code), ('workorder_id.rfid_code', '=', rfid_code),
('status', '=', '待下发'), ('status', '=', '待下发'),
('type', '=', '下产线') ('type', '=', '下产线')

View File

@@ -154,7 +154,7 @@ class MrpProduction(models.Model):
production.maintenance_count = len(production.request_ids) production.maintenance_count = len(production.request_ids)
# cnc程序获取 # cnc程序获取
def fetchCNC(self, production_names): def fetchCNC(self):
cnc = self.env['mrp.production'].search([('id', '=', self.id)]) cnc = self.env['mrp.production'].search([('id', '=', self.id)])
quick_order = self.env['quick.easy.order'].search( quick_order = self.env['quick.easy.order'].search(
[('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])]) [('name', '=', cnc.product_id.default_code.rsplit('-', 1)[0])])
@@ -166,25 +166,26 @@ class MrpProduction(models.Model):
if quick_order: if quick_order:
programme_way = 'manual operation' programme_way = 'manual operation'
try: try:
res = {'model_code': cnc.product_id.name, res = {
'production_no': production_names, 'production_no': cnc.name,
'machine_tool_code': "", 'machine_tool_code': '',
'material_code': self.env['sf.production.materials'].search( 'model_code': cnc.product_id.model_code,
[('id', '=', cnc.product_id.materials_id.id)]).materials_no, 'material_code': self.env['sf.production.materials'].search(
'material_type_code': self.env['sf.materials.model'].search( [('id', '=', cnc.product_id.materials_id.id)]).materials_no,
[('id', '=', cnc.product_id.materials_type_id.id)]).materials_no, 'material_type_code': self.env['sf.materials.model'].search(
'machining_processing_panel': cnc.product_id.model_processing_panel, [('id', '=', cnc.product_id.materials_type_id.id)]).materials_no,
'machining_precision': cnc.product_id.model_machining_precision, 'machining_processing_panel': cnc.product_id.model_processing_panel,
'embryo_long': cnc.product_id.bom_ids.bom_line_ids.product_id.length, 'machining_precision': cnc.product_id.model_machining_precision,
'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height, 'embryo_long': cnc.product_id.bom_ids.bom_line_ids.product_id.length,
'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width, 'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height,
'order_no': cnc.origin, 'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width,
'model_order_no': cnc.product_id.default_code, 'order_no': cnc.origin,
'user': cnc.env.user.name, 'model_order_no': cnc.product_id.default_code,
'programme_way': programme_way, 'user': cnc.env.user.name,
'model_file': '' if not cnc.product_id.model_file else base64.b64encode( 'programme_way': programme_way,
cnc.product_id.model_file).decode('utf-8') 'model_file': '' if not cnc.product_id.model_file else base64.b64encode(
} cnc.product_id.model_file).decode('utf-8')
}
# 打印出除了 model_file 之外的所有键值对 # 打印出除了 model_file 之外的所有键值对
for key, value in res.items(): for key, value in res.items():
if key != 'model_file': if key != 'model_file':
@@ -266,15 +267,15 @@ class MrpProduction(models.Model):
# 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心; # 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心;
def _create_workorder3(self): def _create_workorder3(self):
production_names = [production.name for production in self if production.product_id.categ_id.type == '成品'] # production_names = [production.name for production in self if production.product_id.categ_id.type == '成品']
programming_no = None # programming_no = None
product_first = None # product_first = None
for production in self: for production in self:
if not production.bom_id or not production.product_id: if not production.bom_id or not production.product_id:
continue continue
workorders_values = [] workorders_values = []
if product_first is None: # if product_first is None:
product_first = production.product_id # product_first = production.product_id
product_qty = production.product_uom_id._compute_quantity(production.product_qty, product_qty = production.product_uom_id._compute_quantity(production.product_qty,
production.bom_id.product_uom_id) production.bom_id.product_uom_id)
@@ -299,13 +300,15 @@ class MrpProduction(models.Model):
'state': 'pending', 'state': 'pending',
}] }]
if production.product_id.categ_id.type == '成品': if production.product_id.categ_id.type == '成品':
if programming_no is None: production.fetchCNC()
production.fetchCNC(production_names) # 第二期同一个产品多个制造订单对应一个编程单和模型库
programming_no = production.programming_no # if programming_no is None:
else: # production.fetchCNC(production_names)
if production.product_id == product_first: # programming_no = production.programming_no
if not production.programming_no: # else:
production.write({'programming_no': programming_no, 'programming_state': '编程中'}) # if production.product_id == product_first:
# if not production.programming_no:
# production.write({'programming_no': programming_no, 'programming_state': '编程中'})
# 根据加工面板的面数及对应的工序模板生成工单 # 根据加工面板的面数及对应的工序模板生成工单
i = 0 i = 0
processing_panel_len = len(production.product_id.model_processing_panel.split(',')) processing_panel_len = len(production.product_id.model_processing_panel.split(','))

View File

@@ -827,8 +827,6 @@ class ResMrpWorkOrder(models.Model):
raise UserError("请对前置三元检测定位参数进行计算定位") raise UserError("请对前置三元检测定位参数进行计算定位")
if not record.rfid_code: if not record.rfid_code:
raise UserError("请扫RFID码进行绑定") raise UserError("请扫RFID码进行绑定")
record.workpiece_delivery_ids[0].write({'status': '待下发'})
if record.routing_type == '解除装夹': if record.routing_type == '解除装夹':
''' '''
记录结束时间 记录结束时间
@@ -895,13 +893,17 @@ class ResMrpWorkOrder(models.Model):
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取 # 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
def get_detection_file(self, workorder, reportPath): def get_detection_file(self, workorder, reportPath):
if reportPath.startswith('/'): # if reportPath.startswith('/'):
reportPath = reportPath[4:] # reportPath = reportPath[4:]
serverdir = os.path.join('/tmp', reportPath) # serverdir = os.path.join('/tmp', reportPath)
serverdir = '/tmp' + reportPath
logging.info('get_detection_file-serverdir:%s' % serverdir) logging.info('get_detection_file-serverdir:%s' % serverdir)
serverdir_prefix = os.path.dirname(serverdir) serverdir_prefix = os.path.dirname(serverdir)
logging.info('serverdir_prefix-serverdir:%s' % serverdir_prefix)
for root, dirs, files in os.walk(serverdir_prefix): for root, dirs, files in os.walk(serverdir_prefix):
for filename in files: for filename in files:
logging.info('filename:%s' % filename)
logging.info('reportPath:%s' % os.path.basename(reportPath))
if filename == os.path.basename(reportPath): if filename == os.path.basename(reportPath):
report_file_path = os.path.join(root, filename) report_file_path = os.path.join(root, filename)
logging.info('get_detection_file-report_file_path:%s' % report_file_path) logging.info('get_detection_file-report_file_path:%s' % report_file_path)
@@ -1290,7 +1292,7 @@ class WorkPieceDelivery(models.Model):
'default_type': production_type, 'default_type': production_type,
}} }}
else: else:
if self.type == '运送空料架': if production_type == '运送空料架':
raise UserError("您所选择的【任务路线】的【终点接驳站】已占用,请在该接驳站空闲时进行配送") raise UserError("您所选择的【任务路线】的【终点接驳站】已占用,请在该接驳站空闲时进行配送")
else: else:
raise UserError( raise UserError(
@@ -1330,11 +1332,13 @@ class WorkPieceDelivery(models.Model):
if route_id is None: if route_id is None:
route_id = item.route_id.id route_id = item.route_id.id
if feeder_station_start is None: if feeder_station_start is None:
feeder_station_start = item.feeder_station_start_id.name feeder_station_start = item.feeder_station_start_id
if feeder_station_destination is None: if feeder_station_destination is None:
feeder_station_destination = item.feeder_station_destination_id.name feeder_station_destination = item.feeder_station_destination_id
if item.type in ['上产线', '下产线']: if item.type in ['上产线', '下产线']:
item.route_id = route_id item.route_id = route_id
item.feeder_station_start_id = feeder_station_start.id
item.feeder_station_destination_id = feeder_station_destination.id
delivery_Arr.append(item.name) delivery_Arr.append(item.name)
else: else:
self = self.create( self = self.create(
@@ -1346,12 +1350,12 @@ class WorkPieceDelivery(models.Model):
delivery_str = ','.join(map(str, delivery_Arr)) delivery_str = ','.join(map(str, delivery_Arr))
if feeder_station_start is not None: if feeder_station_start is not None:
positionCode_Arr.append({ positionCode_Arr.append({
'positionCode': feeder_station_start, 'positionCode': feeder_station_start.name,
'code': '00' 'code': '00'
}) })
if feeder_station_destination is not None: if feeder_station_destination is not None:
positionCode_Arr.append({ positionCode_Arr.append({
'positionCode': feeder_station_destination, 'positionCode': feeder_station_destination.name,
'code': '00' 'code': '00'
}) })
res = {'reqCode': delivery_str, 'reqTime': '', 'clientCode': '', 'tokenCode': '', res = {'reqCode': delivery_str, 'reqTime': '', 'clientCode': '', 'tokenCode': '',

View File

@@ -608,7 +608,7 @@
<field name="production_id"/> <field name="production_id"/>
<field name="type" readonly="1"/> <field name="type" readonly="1"/>
<field name="production_line_id" options="{'no_create': True}"/> <field name="production_line_id" options="{'no_create': True}"/>
<field name="route_id" options="{'no_create': True}"/> <field name="route_id" options="{'no_create': True}" domain="[('type','in',['上产线','下产线'])]"/>
<field name="feeder_station_start_id" readonly="1" force_save="1"/> <field name="feeder_station_start_id" readonly="1" force_save="1"/>
<field name="feeder_station_destination_id" readonly="1" force_save="1"/> <field name="feeder_station_destination_id" readonly="1" force_save="1"/>
<field name="is_cnc_program_down" readonly="1"/> <field name="is_cnc_program_down" readonly="1"/>

View File

@@ -24,6 +24,7 @@ class FtpController():
def file_exists(self, path): def file_exists(self, path):
# 检查文件是否存在于FTP服务器上 # 检查文件是否存在于FTP服务器上
try: try:
logging.info("dirname:%s" % os.path.dirname(path))
self.ftp.cwd(os.path.dirname(path)) self.ftp.cwd(os.path.dirname(path))
files = self.ftp.nlst() files = self.ftp.nlst()
return os.path.basename(path) in files return os.path.basename(path) in files
@@ -31,6 +32,11 @@ class FtpController():
logging.error(f"Error checking file: {e}") logging.error(f"Error checking file: {e}")
return False return False
# # 检测字符串的编码
# def detect_encoding(self, s):
# result = chardet.detect(s)
# return result['encoding']
# 下载目录下的文件 # 下载目录下的文件
def download_file_tree(self, target_dir, serverdir): def download_file_tree(self, target_dir, serverdir):
if not os.path.exists(serverdir): if not os.path.exists(serverdir):
@@ -40,17 +46,13 @@ class FtpController():
logging.info('目录:%s' % target_dir) logging.info('目录:%s' % target_dir)
target_dir1 = target_dir.split('/') target_dir1 = target_dir.split('/')
logging.info('目录1:%s' % target_dir1[1]) logging.info('目录1:%s' % target_dir1[1])
self.ftp.cwd('NC') self.ftp.cwd(target_dir1[1]) # 切换工作路径
self.ftp.cwd('XT_WH_MO_00164') logging.info('目录2:%s' % target_dir1[2])
self.ftp.cwd('return') self.ftp.cwd(target_dir1[2]) # 切换工作路径
self.ftp.cwd('R') logging.info('目录3:%s' % target_dir1[3])
# self.ftp.cwd(target_dir1[1]) # 切换工作路径 self.ftp.cwd(target_dir1[3]) # 切换工作路径
# logging.info('目录2:%s' % target_dir1[2]) logging.info('目录4:%s' % target_dir1[4])
# self.ftp.cwd(target_dir1[2]) # 切换工作路径 self.ftp.cwd(target_dir1[4]) # 切换工作路径
# logging.info('目录3:%s' % target_dir1[3])
# self.ftp.cwd(target_dir1[3]) # 切换工作路径
# logging.info('目录4:%s' % target_dir1[4])
# self.ftp.cwd(target_dir1[4]) # 切换工作路径
remotenames = self.ftp.nlst() remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames) logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames: for file in remotenames:
@@ -88,6 +90,9 @@ class FtpController():
return 1 return 1
except Exception: except Exception:
return 0 return 0
finally:
self.ftp.quit()
logging.info("ftp已关闭")
# 下载指定目录下的指定文件 # 下载指定目录下的指定文件
def download_file(self, serverfile, remotefile): def download_file(self, serverfile, remotefile):

View File

@@ -229,6 +229,11 @@ class sf_production_plan(models.Model):
record.env['mrp.production'].sudo().browse(i).schedule_state = '已排' record.env['mrp.production'].sudo().browse(i).schedule_state = '已排'
# record.production_id.date_planned_start = record.date_planned_start # record.production_id.date_planned_start = record.date_planned_start
# record.production_id.date_planned_finished = record.date_planned_finished # record.production_id.date_planned_finished = record.date_planned_finished
record.production_id.production_line_id = record.production_line_id.id
record.production_id.workorder_ids.filtered(
lambda b: b.routing_type == "装夹预调").workpiece_delivery_ids.write(
{'production_line_id': record.production_line_id.id,
'plan_start_processing_time': record.date_planned_start})
else: else:
raise ValidationError("未找到工单") raise ValidationError("未找到工单")
# record.date_planned_finished = record.date_planned_start + timedelta(days=3) # record.date_planned_finished = record.date_planned_start + timedelta(days=3)