From 954ff6b848bc4bbbc5ae57809b48050c7263e822 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Thu, 13 Mar 2025 19:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E5=8F=91=E5=B8=83=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=8C=E6=AC=A1=E7=A1=AE=E8=AE=A4=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quality_control/__manifest__.py | 1 + quality_control/models/quality.py | 56 ++++++++++++++----- quality_control/security/ir.model.access.csv | 3 +- quality_control/wizard/__init__.py | 1 + quality_control/wizard/quality_wizard.py | 18 ++++++ .../wizard/quality_wizard_view.xml | 19 +++++++ 6 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 quality_control/wizard/quality_wizard.py create mode 100644 quality_control/wizard/quality_wizard_view.xml diff --git a/quality_control/__manifest__.py b/quality_control/__manifest__.py index b1eecb9a..ff899d4a 100644 --- a/quality_control/__manifest__.py +++ b/quality_control/__manifest__.py @@ -21,6 +21,7 @@ Quality Control 'data': [ 'data/quality_control_data.xml', 'wizard/import_complex_model.xml', + 'wizard/quality_wizard_view.xml', 'report/worksheet_custom_reports.xml', 'report/worksheet_custom_report_templates.xml', 'views/quality_views.xml', diff --git a/quality_control/models/quality.py b/quality_control/models/quality.py index 2c25cd34..cff74112 100644 --- a/quality_control/models/quality.py +++ b/quality_control/models/quality.py @@ -152,6 +152,7 @@ class QualityCheck(models.Model): record.total_qty = total_qty if total_qty > 0 else '' else: record.total_qty = '' + # 检验数 check_qty = fields.Char('检验数', default=lambda self: self._get_default_check_qty()) @@ -232,12 +233,33 @@ class QualityCheck(models.Model): def do_publish(self): """发布出厂检验报告""" self.ensure_one() - self._check_measure_line() - self._check_check_qty_and_total_qty() - + # self._check_measure_line() + # self._check_check_qty_and_total_qty() + + # 打开确认向导而不是直接发布 + return { + 'name': _('发布确认'), + 'type': 'ir.actions.act_window', + 'res_model': 'quality.check.publish.wizard', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_check_id': self.id, + 'default_product_name': self.product_id.name, + 'default_total_qty': self.total_qty, + 'default_check_qty': self.check_qty, + 'default_measure_count': self.column_nums, + 'default_item_count': len(self.measure_line_ids), + } + } + + def _do_publish_implementation(self): + """实际执行发布操作的方法""" + self.ensure_one() + # 1. 获取报告动作 report_action = self.env.ref('sf_quality.action_report_quality_inspection') - + # 2. 生成PDF报告 - 修改这里的调用方式 pdf_content, _ = report_action._render_qweb_pdf( report_ref=report_action.report_name, # 添加report_ref参数 @@ -254,12 +276,14 @@ class QualityCheck(models.Model): }) # 获取已发布的文档文件夹 - workspace = self.env['documents.folder'].search([('parent_folder_id', '=', self.env.ref('sf_quality.documents_purchase_contracts_folder').id), ('name', '=', '已发布')], limit=1) + workspace = self.env['documents.folder'].search( + [('parent_folder_id', '=', self.env.ref('sf_quality.documents_purchase_contracts_folder').id), + ('name', '=', '已发布')], limit=1) if self.serial_number > 99: raise UserError(_('流水号不能大于99')) - str_serial_number = '0' + str(self.serial_number) if self.serial_number < 10 else str(self.serial_number) + str_serial_number = '0' + str(self.serial_number) if self.serial_number < 10 else str(self.serial_number) str_part_number = self.part_number if self.part_number else '' # 3. 创建文档记录 doc_vals = { @@ -271,14 +295,14 @@ class QualityCheck(models.Model): 'folder_id': workspace.id, 'res_model': self._name, } - + doc = self.env['documents.document'].create(doc_vals) # 关联到当前质检记录 self.write({ 'report_number_id': doc.id, 'publish_status': 'published' }) - + # 记录发布历史 self.env['quality.check.report.history'].create({ 'check_id': self.id, @@ -295,7 +319,7 @@ class QualityCheck(models.Model): # 返回成功消息 return True - + # 发布前校验明细行列均非空 def _check_measure_line(self): for record in self: @@ -307,11 +331,14 @@ class QualityCheck(models.Model): for i in range(1, record.column_nums + 1): if not getattr(line, f'measure_value{i}'): raise UserError(_('有测量值为空')) - - + # 发布前校验检验数与总数量、检验数与测量件数(即测量列数) def _check_check_qty_and_total_qty(self): for record in self: + if not record.check_qty: + raise UserError(_('请先输入检验数')) + if not record.total_qty: + raise UserError(_('总数量不能为空')) if int(record.check_qty) <= int(record.total_qty): raise UserError(_('检验数不可超过总数量')) if int(record.column_nums) >= int(record.check_qty): @@ -323,7 +350,9 @@ class QualityCheck(models.Model): """ self.ensure_one() # 1. 获取已发布的文档文件夹 - workspace = self.env['documents.folder'].search([('parent_folder_id', '=', self.env.ref('sf_quality.documents_purchase_contracts_folder').id), ('name', '=', '已发布')], limit=1) + workspace = self.env['documents.folder'].search( + [('parent_folder_id', '=', self.env.ref('sf_quality.documents_purchase_contracts_folder').id), + ('name', '=', '已发布')], limit=1) # 2. 将当前质检单关联的出厂检验报告文档位置移动到废弃文件夹 self.report_number_id.write({ 'folder_id': self.env.ref('sf_quality.documents_purchase_contracts_folder_canceled').id, @@ -342,13 +371,11 @@ class QualityCheck(models.Model): }) return True - def do_re_publish(self): """ 重新发布出厂检验报告,参考发布规则 """ self.do_publish() - def generate_qr_code(self): """生成二维码URL""" @@ -831,4 +858,3 @@ class QualityCheckReportHistory(models.Model): ('published', '已发布'), ('canceled', '废弃') ], string='操作后文档状态') - diff --git a/quality_control/security/ir.model.access.csv b/quality_control/security/ir.model.access.csv index d06537b6..e6911403 100644 --- a/quality_control/security/ir.model.access.csv +++ b/quality_control/security/ir.model.access.csv @@ -2,4 +2,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_quality_check_wizard,access.quality_check_wizard,model_quality_check_wizard,quality.group_quality_user,1,1,1,0 access_quality_check_measure_line,quality.check.measure.line,model_quality_check_measure_line,base.group_user,1,1,1,0 access_quality_check_import_complex_model_wizard,quality.check.import.complex.model.wizard,model_quality_check_import_complex_model_wizard,quality.group_quality_user,1,1,1,0 -access_quality_check_report_history,quality.check.report.history,model_quality_check_report_history,quality.group_quality_user,1,1,1,0 \ No newline at end of file +access_quality_check_report_history,quality.check.report.history,model_quality_check_report_history,quality.group_quality_user,1,1,1,0 +access_quality_check_publish_wizard,quality.check.publish.wizard,model_quality_check_publish_wizard,quality.group_quality_user,1,1,1,0 \ No newline at end of file diff --git a/quality_control/wizard/__init__.py b/quality_control/wizard/__init__.py index 49415fd2..5aa64e16 100644 --- a/quality_control/wizard/__init__.py +++ b/quality_control/wizard/__init__.py @@ -3,3 +3,4 @@ from . import quality_check_wizard from . import import_complex_model +from . import quality_wizard diff --git a/quality_control/wizard/quality_wizard.py b/quality_control/wizard/quality_wizard.py new file mode 100644 index 00000000..3768792a --- /dev/null +++ b/quality_control/wizard/quality_wizard.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models, _ + +class QualityCheckPublishWizard(models.TransientModel): + _name = 'quality.check.publish.wizard' + _description = '质检报告发布确认' + + check_id = fields.Many2one('quality.check', string='质检单', required=True) + product_name = fields.Char('产品名称', readonly=True) + total_qty = fields.Char('总数量', readonly=True) + check_qty = fields.Char('检验数', readonly=True) + measure_count = fields.Integer('测量件数', readonly=True) + item_count = fields.Integer('检验项目数', readonly=True) + + def action_confirm_publish(self): + """确认发布""" + self.ensure_one() + return self.check_id._do_publish_implementation() \ No newline at end of file diff --git a/quality_control/wizard/quality_wizard_view.xml b/quality_control/wizard/quality_wizard_view.xml new file mode 100644 index 00000000..90bc3c05 --- /dev/null +++ b/quality_control/wizard/quality_wizard_view.xml @@ -0,0 +1,19 @@ + + + + quality.check.publish.wizard.form + quality.check.publish.wizard + +
+ + +
+
+
+
\ No newline at end of file