坯料的采购订单零件图号,零件名称显示

This commit is contained in:
liaodanlong
2025-02-26 09:37:56 +08:00
parent c400553294
commit c4c6386871
3 changed files with 69 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details. # Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
from collections import defaultdict from collections import defaultdict
from odoo import api, fields, models, _ from odoo import api, fields, models, _
@@ -109,15 +109,37 @@ class PurchaseOrder(models.Model):
class PurchaseOrderLine(models.Model): class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line' _inherit = 'purchase.order.line'
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True) part_number = fields.Char('零件图号', store=True, compute='_compute_origin_sale_id')
part_name = fields.Char('零件图号', store=True,
compute='_compute_origin_sale_id')
related_product = fields.Many2one('product.product', string='关联产品', related_product = fields.Many2one('product.product', string='关联产品',
help='经此产品工艺加工成的成品') help='经此产品工艺加工成的成品')
@api.depends('product_id')
# @api.depends('order_id.origin') def _compute_related_product(self):
# def _compute_related_product(self): for record in self:
# for record in self: if record.product_id.categ_id.name == '坯料':
# if record.product_id.detailed_type: product_name = ''
# production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)]) match = re.search(r'(S\d{5}-\d)', record.product_id.name)
# record.related_product = production_id.product_id if production_id else False # 如果匹配成功,提取结果
# else: if match:
# record.related_product = False product_name = match.group(0)
sale_order_name = ''
match_sale = re.search(r'(S\d+)', record.product_id.name)
if match_sale:
sale_order_name = match_sale.group(0)
sale_order = self.env['sale.order'].sudo().search(
[('name', '=', sale_order_name)])
if sale_order:
filtered_order_line = sale_order.order_line.filtered(
lambda order_line: product_name in order_line.product_id.name
)
record.part_number = filtered_order_line.product_id.part_number if filtered_order_line else None
record.part_name = filtered_order_line.product_id.part_name if filtered_order_line else None
else:
record.part_number = record.product_id.part_number
record.part_name = record.product_id.part_name
# if record.product_id.detailed_type:
# production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)])
# record.related_product = production_id.product_id if production_id else False
# else:
# record.related_product = False

View File

@@ -3,6 +3,8 @@ import logging
import os import os
import json import json
import base64 import base64
import traceback
from odoo import http, fields, models from odoo import http, fields, models
from odoo.http import request from odoo.http import request
from odoo.addons.sf_base.controllers.controllers import MultiInheritController from odoo.addons.sf_base.controllers.controllers import MultiInheritController
@@ -42,26 +44,26 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
# 拉取所有加工面的程序文件 # 拉取所有加工面的程序文件
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'] or '', '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': '已编程', 'is_rework': False}) production.write({'programming_state': '已编程', 'work_state': '已编程', 'is_rework': False})
for panel in ret['processing_panel'].split(','): for panel in ret['processing_panel'].split(','):
# 查询状态为进行中且工序类型为CNC加工的工单 # 查询状态为进行中且工序类型为CNC加工的工单
cnc_workorder_has = production.workorder_ids.filtered( cnc_workorder_has = production.workorder_ids.filtered(
lambda ach: ach.routing_type in ['CNC加工', '人工线下加工'] and ach.state not in ['progress', 'done', lambda ach: ach.routing_type == 'CNC加工' and ach.state not in ['progress', 'done',
'rework', 'rework',
'cancel'] and ach.processing_panel == panel) 'cancel'] and ach.processing_panel == panel)
if cnc_workorder_has: if cnc_workorder_has:
@@ -76,36 +78,34 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
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 in ['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 in ['装夹预调', '人工线下加工'] 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': '已编程'})
productions.filtered(lambda p: p.production_type == '人工线下加工').write({'manual_quotation': True})
logging.info('已更新制造订单编程状态:%s' % productions.ids) logging.info('已更新制造订单编程状态:%s' % productions.ids)
# 对制造订单所有面的cnc工单的程序用刀进行校验 # 对制造订单所有面的cnc工单的程序用刀进行校验
try: try:
logging.info(f'已更新制造订单:{productions}') logging.info(f'已更新制造订单:{productions}')
re_tool_chekout = False re_tool_chekout = False
productions_temp = productions.filtered(lambda p: p.production_type == '自动化产线加工') re_tool_chekout = productions.production_cnc_tool_checkout()
re_tool_chekout = productions_temp.production_cnc_tool_checkout()
if re_tool_chekout: if re_tool_chekout:
return json.JSONEncoder().encode({'status': -3, 'message': '对cnc工单的程序用刀进行校验失败'}) return json.JSONEncoder().encode({'status': -3, 'message': '对cnc工单的程序用刀进行校验失败'})
except Exception as e: except Exception as e:
@@ -202,17 +202,6 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
'send_time': ret['send_time'], 'send_time': ret['send_time'],
}) })
logging.info('已创建无效功能刀具的编程记录:%s' % production.name) logging.info('已创建无效功能刀具的编程记录:%s' % production.name)
elif ret['reprogramming_reason']:
production.programming_record_ids.create({
'number': len(production.programming_record_ids) + 1,
'production_id': production.id,
'reason': ret['reprogramming_reason'],
'programming_method': ret['programme_way'],
'current_programming_count': ret['reprogramming_num'],
'target_production_id': productions_reprogram,
'apply_time': ret['trigger_time'],
'send_time': ret['send_time'],
})
else: else:
logging.info('无对应状态,不需更新编程记录') logging.info('无对应状态,不需更新编程记录')
@@ -266,5 +255,7 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
except Exception as e: except Exception as e:
res = {'status': -1, 'message': '系统解析失败'} res = {'status': -1, 'message': '系统解析失败'}
request.cr.rollback() request.cr.rollback()
logging.info('get_cnc_processing_create error:%s' % e) traceback_error = traceback.format_exc()
logging.info('get_cnc_processing_create error:%s' % traceback_error)
# logging.info('get_cnc_processing_create error:%s' % e)
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)

View File

@@ -2305,6 +2305,8 @@ class Cutting_tool_standard_library(models.Model):
result = json.loads(r['result']) result = json.loads(r['result'])
if result['status'] == 1: if result['status'] == 1:
for item in result['cutting_tool_standard_library_all_list']: for item in result['cutting_tool_standard_library_all_list']:
if item['code'] == 'JKM-T-DJWL-ZTDJ-20250225001':
print('qwfhuiuiohfqwuio')
cutting_tool_standard_library = self.search( cutting_tool_standard_library = self.search(
[("code", '=', item['code']), [("code", '=', item['code']),
("active", 'in', [True, False])]) ("active", 'in', [True, False])])