diff --git a/jikimo_work_reporting_api/controllers/main.py b/jikimo_work_reporting_api/controllers/main.py index 76b55dc9..04535be0 100644 --- a/jikimo_work_reporting_api/controllers/main.py +++ b/jikimo_work_reporting_api/controllers/main.py @@ -5,7 +5,7 @@ from odoo.addons.sf_machine_connect.models.ftp_operate import transfer_nc_files class MainController(http.Controller): - @http.route('/api/manual_download_program', type='json', methods=['POST'], auth='wechat_token', cors='*') + @http.route('/api/manual_download_program', type='json', methods=['POST'], auth='public', cors='*') def manual_download_program(self): """ 人工线下加工传输编程文件 @@ -18,6 +18,11 @@ class MainController(http.Controller): maintenance_equipment = request.env['maintenance.equipment'].sudo().search([('name', '=', maintenance_equipment_name)], limit=1) if not maintenance_equipment: return {'code': 400, 'message': '机床不存在'} + # 获取刀具组 + tool_groups_id = request.env['sf.tool.groups'].sudo().search([('equipment_ids', 'in', maintenance_equipment.id)], limit=1) + if not tool_groups_id: + return {'code': 400, 'message': '刀具组不存在'} + ftp_resconfig = request.env['res.config.settings'].sudo().get_values() source_ftp_info = { 'host': ftp_resconfig['ftp_host'], @@ -36,7 +41,8 @@ class MainController(http.Controller): source_ftp_info, target_ftp_info, '/' + str(model_id), - '/home/jikimo/testdir'): + '/home/jikimo/testdir', + end_with=tool_groups_id.name + '-all.nc'): return {'code': 200, 'message': 'success'} else: return {'code': 500, 'message': '传输失败'} diff --git a/sf_base/views/common_view.xml b/sf_base/views/common_view.xml index 74b8f177..dbdfec49 100644 --- a/sf_base/views/common_view.xml +++ b/sf_base/views/common_view.xml @@ -5,7 +5,7 @@ sf.production.process.parameter - + @@ -15,7 +15,7 @@ sf.production.process.parameter -
+

@@ -104,7 +104,7 @@ sf.production.process.category - +

@@ -120,7 +120,7 @@ - + @@ -139,7 +139,7 @@ sf.production.process.category - + @@ -163,7 +163,7 @@ sf.production.process - + @@ -175,7 +175,7 @@ sf.production.process - +

@@ -395,7 +395,7 @@ tree,form - 表面工艺 + 工艺 ir.actions.act_window sf.production.process tree,form @@ -414,13 +414,13 @@ - 表面工艺类别 + 工艺类别 ir.actions.act_window sf.production.process.category tree,form - 表面工艺可选参数 + 工艺可选参数 ir.actions.act_window sf.production.process.parameter tree,form diff --git a/sf_base/views/menu_view.xml b/sf_base/views/menu_view.xml index cf7c7aaf..1ff47db8 100644 --- a/sf_base/views/menu_view.xml +++ b/sf_base/views/menu_view.xml @@ -78,7 +78,7 @@ 工艺可选参数编码序列 sf.production.process.parameter - WKSP - 9 + 3 + 1 \ No newline at end of file diff --git a/sf_dlm_management/models/sf_production_common.py b/sf_dlm_management/models/sf_production_common.py index cd19e938..0c937175 100644 --- a/sf_dlm_management/models/sf_production_common.py +++ b/sf_dlm_management/models/sf_production_common.py @@ -11,20 +11,23 @@ class SfProductionProcessParameter(models.Model): @api.model def create(self, vals): - if vals.get('code', '/') == '/' or vals.get('code', '/') is False: - vals['code'] = self.env['ir.sequence'].next_by_code('sf.production.process.parameter') or '/' + # if vals.get('code', '/') == '/' or vals.get('code', '/') is False: + # vals['code'] = '101'+self.routing_id.code +self.env['ir.sequence'].next_by_code('sf.production.process.parameter') if not vals.get('process_id') and vals.get('routing_id'): vals['gain_way'] = '外协' routing_id = self.env['mrp.routing.workcenter'].browse(vals.get('routing_id')) if routing_id.surface_technics_id: vals['process_id'] = routing_id.surface_technics_id.id + if vals.get('code', '/') == '/' or vals.get('code', '/') is False: + vals['code'] = '101' + routing_id.code + self.env['ir.sequence'].next_by_code( + 'sf.production.process.parameter') obj = super(SfProductionProcessParameter, self).create(vals) return obj def create_service_product(self): service_categ = self.env.ref( 'sf_dlm.product_category_surface_technics_sf').sudo() - product_name = f"{self.process_id.name}{self.name}" + product_name = f"{self.process_id.name}_{self.name}" product_id = self.env['product.template'].search( [("name", '=', product_name)]) if product_id: diff --git a/sf_dlm_management/views/product_template_management_view.xml b/sf_dlm_management/views/product_template_management_view.xml index d6420417..c53c0dc4 100644 --- a/sf_dlm_management/views/product_template_management_view.xml +++ b/sf_dlm_management/views/product_template_management_view.xml @@ -41,7 +41,7 @@ attrs="{'invisible': [('categ_type', 'not in', ['成品','坯料', '原材料'])],'readonly': [('id', '!=', False)]}"/> + attrs="{'invisible': ['|',('detailed_type', '!=', '服务'),('detailed_type', '=', False)]}"/> 1: raise ValidationError("工艺参数不能与多个产品关联") + + @api.onchange('outsourced_service_products') + def _onchange_validate_partner_limit(self): + for record in self: + if len(record.outsourced_service_products) > 1: + raise ValidationError("工艺参数不能与多个产品关联") @api.depends('outsourced_service_products') def _compute_is_product_button(self): for record in self: diff --git a/sf_manufacturing/models/workorder_printer.py b/sf_manufacturing/models/workorder_printer.py index 46eb3b8b..fde7f113 100644 --- a/sf_manufacturing/models/workorder_printer.py +++ b/sf_manufacturing/models/workorder_printer.py @@ -1,11 +1,5 @@ -import qrcode -import base64 + import logging -import tempfile -import os -import platform -import socket -import subprocess from io import BytesIO from odoo import models, fields, api from odoo.exceptions import UserError @@ -14,95 +8,7 @@ _logger = logging.getLogger(__name__) class MrpWorkorder(models.Model): _name = 'mrp.workorder' - _inherit = ['mrp.workorder', 'printing.utils'] - - def print_pdf(self, printer_config, pdf_data): - """跨平台打印函数,支持网络打印机(IP:端口)""" - # 将PDF数据保存到临时文件 - with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file: - pdf_binary = base64.b64decode(pdf_data) - temp_file.write(pdf_binary) - temp_file_path = temp_file.name - - _logger.info(f"开始打印PDF文件: {temp_file_path}") - - try: - # 获取打印机名称或IP地址 - printer_name = printer_config.printer_id.name - if not printer_name: - raise UserError('打印机名称未配置') - - # 使用打印机配置中的IP地址和端口 - printer_ip = printer_config.printer_id.ip_address - printer_port = printer_config.printer_id.port - _logger.info(f"使用网络打印机: IP={printer_ip}, 端口={printer_port}") - - if platform.system() == 'Windows': - _logger.info(f"Windows环境不支持网络打印机") - else: # Linux环境 - # try: - # import cups - - # # 处理网络打印机情况 - # _logger.info(f"Linux环境下连接网络打印机: {printer_ip}:{printer_port}") - - # # 创建连接 - # conn = cups.Connection() - - # # 检查打印机是否已经添加到系统 - # printers = conn.getPrinters() - # _logger.info(f"可用打印机列表: {list(printers.keys())}") - - # network_printer_name = f"IP_{printer_ip}_{printer_port}" - - # # 如果打印机不存在,尝试添加 - # if network_printer_name not in printers: - # _logger.info(f"添加网络打印机: {network_printer_name}") - # conn.addPrinter( - # network_printer_name, - # device=f"socket://{printer_ip}:{printer_port}", - # info=f"Network Printer {printer_ip}:{printer_port}", - # location="Network" - # ) - # # 设置打印机为启用状态 - # conn.enablePrinter(network_printer_name) - # _logger.info(f"网络打印机添加成功: {network_printer_name}") - - # # 打印文件 - # _logger.info(f"开始打印到网络打印机: {network_printer_name}") - # job_id = conn.printFile(network_printer_name, temp_file_path, "工单打印", {}) - # _logger.info(f"打印作业ID: {job_id}") - - - # except ImportError as ie: - # _logger.error(f"导入CUPS库失败: {str(ie)}") - - # 尝试使用lp命令打印 - try: - _logger.info("尝试使用lp命令打印...") - - # 使用socket设置打印 - cmd = f"lp -h {printer_ip}:{printer_port} -d {printer_name} {temp_file_path}" - - _logger.info(f"执行lp打印命令: {cmd}") - result = subprocess.run(cmd, shell=True, check=True, capture_output=True) - _logger.info(f"lp打印结果: {result.stdout.decode()}") - except Exception as e: - _logger.error(f"lp命令打印失败: {str(e)}") - raise UserError(f'打印失败,请安装cups打印库: pip install pycups 或确保lp命令可用') - - return True - except Exception as e: - _logger.error(f"打印失败详细信息: {str(e)}") - raise UserError(f'打印失败: {str(e)}') - finally: - # 清理临时文件 - if os.path.exists(temp_file_path): - try: - os.unlink(temp_file_path) - _logger.info(f"临时文件已清理: {temp_file_path}") - except Exception as e: - _logger.error(f"清理临时文件失败: {str(e)}") + _inherit = ['mrp.workorder'] def _compute_state(self): super(MrpWorkorder, self)._compute_state() @@ -111,21 +17,18 @@ class MrpWorkorder(models.Model): for wo in work_ids: if wo.state == 'ready' and not wo.production_id.product_id.is_print_program: # 触发打印程序 - pdf_data = self.processing_drawing - try: - if pdf_data: - # 获取默认打印机配置 - printer_config = self.env['printer.configuration'].sudo().search([('model', '=', self._name), ('printer_id.type', '=', 'normal')], limit=1) - if not printer_config: - raise UserError('请先配置打印机') - + pdf_data = workorder.processing_drawing + if pdf_data: + try: # 执行打印 - if self.print_pdf(printer_config, pdf_data): - wo.production_id.product_id.is_print_program = True - _logger.info(f"工单 {wo.name} 的PDF已成功打印") - - except Exception as e: - _logger.error(f'打印配置错误: {str(e)}') + printer = self.env['printing.printer'].get_default() + printer.print_document(report=None, content = pdf_data, doc_format='pdf') + + wo.production_id.product_id.is_print_program = True + _logger.info(f"工单 {wo.name} 的PDF已成功打印") + + except Exception as e: + _logger.error(f"工单 {wo.name} 的PDF打印失败: {str(e)}") class ProductTemplate(models.Model): _inherit = 'product.template' diff --git a/sf_manufacturing/views/mrp_routing_workcenter_view.xml b/sf_manufacturing/views/mrp_routing_workcenter_view.xml index d1eb0618..6dfe2c5b 100644 --- a/sf_manufacturing/views/mrp_routing_workcenter_view.xml +++ b/sf_manufacturing/views/mrp_routing_workcenter_view.xml @@ -30,7 +30,7 @@ - +

- + - + @@ -83,15 +87,16 @@ - - - - + + + + - + @@ -157,8 +162,8 @@ - - + + @@ -173,13 +178,16 @@ - + - - + + - +
@@ -275,7 +283,7 @@ ir.actions.act_window sf.production.plan tree,gantt,form - + {'search_default_draft': 1, 'display_complete': True}
@@ -341,7 +349,7 @@ parent="mrp.menu_mrp_manufacturing" /> - + + + + + + + + + + + + + + + + + + + + + + + + +