制造订单合并一张编程单下发时,工件配送记录的未下发nc程序为未下发及cnc程序没有对应ftp文件路径问题

This commit is contained in:
jinling.yang
2024-05-28 17:57:27 +08:00
parent 412bf4b9be
commit fe88a416a7
5 changed files with 42 additions and 19 deletions

View File

@@ -335,10 +335,10 @@ class MrpProduction(models.Model):
production_programming = self.search(
[('product_id.id', '=', production.product_id.id), ('origin', '=', production.origin)],
limit=1, order='id asc')
if not production_programming.programming_no:
if not production_programming.programming_no or (is_fetchcnc is True and scrap_production):
# 制造订单报废/返工也需重新编程
if (is_fetchcnc is True and scrap_production) or (
is_fetchcnc is False and not scrap_production):
is_fetchcnc is False and scrap_production):
production.fetchCNC(', '.join(product_id_to_production_names[production.product_id.id]),
scrap_production)
else:
@@ -408,6 +408,12 @@ class MrpProduction(models.Model):
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str('', production, route))
production.workorder_ids = workorders_values
if is_fetchcnc is False and scrap_production:
production.write({'programming_no': scrap_production.programming_no,
'programming_state': '已编程'})
production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').write({
'cnc_ids': scrap_production.workorder_ids.filtered(
lambda t1: t1.routing_type == 'CNC加工').cnc_ids})
for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected()

View File

@@ -766,6 +766,7 @@ class ResMrpWorkOrder(models.Model):
sale_order = self.env['sale.order'].sudo().search([('name', '=', productions.origin)])
if sale_order:
sale_order.mrp_production_ids |= productions
# sale_order.write({'schedule_status': 'to schedule'})
self.env['sf.production.plan'].sudo().with_company(self.production_id.company_id).create({
'name': productions.name,
@@ -995,7 +996,7 @@ class ResMrpWorkOrder(models.Model):
'date_planned_finished': tem_date_planned_finished # 保持原值
})
if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']:
record.production_id.write({'state': 'cancel'})
record.production_id.action_cancel()
record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code})
if record.is_remanufacture is True:
record.recreateManufacturingOrWorkerOrder()
@@ -1130,6 +1131,8 @@ class CNCprocessing(models.Model):
'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
'estimated_processing_time': obj['estimated_processing_time'],
'program_path': obj['program_path'],
'cnc_id': obj['cnc_id'].id,
'remark': obj['remark']
})
return cnc_processing_str
@@ -1137,19 +1140,27 @@ class CNCprocessing(models.Model):
# 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配
def get_cnc_processing_file(self, serverdir, cnc_processing, program_path):
logging.info('serverdir:%s' % serverdir)
logging.info('cnc_processing:%s' % cnc_processing)
for root, dirs, files in os.walk(serverdir):
for f in files:
logging.info('splitext(f):%s' % os.path.splitext(f)[1])
if os.path.splitext(f)[1] == ".pdf":
full_path = os.path.join(serverdir, root, f)
if full_path is not False:
if not cnc_processing.workorder_id.cnc_worksheet:
cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(
open(full_path, 'rb').read())
else:
if f in program_path:
# if cnc_processing.program_name == f.split('.')[0]:
cnc_file_path = os.path.join(serverdir, root, f)
self.write_file(cnc_file_path, cnc_processing)
logging.info('full_path:%s' % full_path)
logging.info('routing_type:%s' % cnc_processing.workorder_id.routing_type)
logging.info('cnc_worksheet:%s' % cnc_processing.workorder_id.cnc_worksheet)
# with open(full_path, 'rb') as pdf_file:
# file_content = pdf_file.read()
# cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(file_content)
if not cnc_processing.workorder_id.cnc_worksheet:
logging.info('full_path111555:%s' % full_path)
cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(
open(full_path, 'rb').read())
else:
if f in program_path:
# if cnc_processing.program_name == f.split('.')[0]:
cnc_file_path = os.path.join(serverdir, root, f)
self.write_file(cnc_file_path, cnc_processing)
# 创建附件(nc文件)
def attachment_create(self, name, data):

View File

@@ -631,8 +631,8 @@ class ReStockMove(models.Model):
'reserved_uom_qty': 1.0,
'lot_id': purchase.picking_ids.move_line_ids.lot_id.id,
'company_id': self.company_id.id,
'workorder_id': '' if not sorted_workorders else sorted_workorders.id,
'production_id': '' if not sorted_workorders else sorted_workorders.production_id.id,
# 'workorder_id': '' if not sorted_workorders else sorted_workorders.id,
# 'production_id': '' if not sorted_workorders else sorted_workorders.production_id.id,
'state': 'assigned',
}