From 8c43fc2b769292d748b0b64a277cf0c17517f606 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 17 Jun 2025 09:41:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=96=B9=E6=B3=95=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wizard/sf_demand_plan_print_wizard.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py b/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py index 8fe70302..25c7791a 100644 --- a/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py +++ b/sf_demand_plan/wizard/sf_demand_plan_print_wizard.py @@ -30,9 +30,14 @@ class SfDemandPlanPrintWizard(models.TransientModel): workorder_id = fields.Many2one('mrp.workorder', string='工单') cnc_worksheet = fields.Binary('程序单') + @api.model def demand_plan_print(self, print_ids): plan_print_ids = self.env['sf.demand.plan.print.wizard'].sudo().search( [('id', 'in', print_ids)]) + if not plan_print_ids: + return {'message': '记录不存在'} + success_records = [] + failed_records = [] for record in plan_print_ids: pdf_data = record.machining_drawings if record.type == '1' else record.cnc_worksheet if pdf_data: @@ -48,9 +53,20 @@ class SfDemandPlanPrintWizard(models.TransientModel): elif record.type == '2': c_num += 1 record.demand_plan_id.print_count = f"T{t_num}C{c_num}" + success_records.append({ + 'filename_url': record.filename_url, + }) except Exception as e: record.status = 'fail' _logger.error(f"文件{record.filename_url}打印失败: {str(e)}") + failed_records.append({ + 'filename_url': record.filename_url, + }) + if failed_records: + message = f"成功打印 {len(success_records)} 个文件,失败 {len(failed_records)} 个" + else: + message = f"所有 {len(success_records)} 个文件打印成功" + return {'message': message} class MrpWorkorder(models.Model):