对发布按钮进行二次确认控制

This commit is contained in:
mgw
2025-03-13 19:13:57 +08:00
parent af3a2880e8
commit 954ff6b848
6 changed files with 82 additions and 16 deletions

View File

@@ -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',

View File

@@ -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='操作后文档状态')

View File

@@ -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
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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_quality_check_wizard access.quality_check_wizard model_quality_check_wizard quality.group_quality_user 1 1 1 0
3 access_quality_check_measure_line quality.check.measure.line model_quality_check_measure_line base.group_user 1 1 1 0
4 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
5 access_quality_check_report_history quality.check.report.history model_quality_check_report_history quality.group_quality_user 1 1 1 0
6 access_quality_check_publish_wizard quality.check.publish.wizard model_quality_check_publish_wizard quality.group_quality_user 1 1 1 0

View File

@@ -3,3 +3,4 @@
from . import quality_check_wizard
from . import import_complex_model
from . import quality_wizard

View File

@@ -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()

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_quality_check_publish_wizard_form" model="ir.ui.view">
<field name="name">quality.check.publish.wizard.form</field>
<field name="model">quality.check.publish.wizard</field>
<field name="arch" type="xml">
<form string="发布确认">
<div class="alert alert-info" role="alert" style="margin-bottom:0px;">
<p>您即将发布出厂检验报告:产品<strong><field name="product_name" class="oe_inline"/></strong>,总数量<strong><field name="total_qty" class="oe_inline"/></strong>,检验数<strong><field name="check_qty" class="oe_inline"/></strong>,测量<strong><field name="measure_count" class="oe_inline"/></strong>件,检验项目<strong><field name="item_count" class="oe_inline"/></strong>项。</p>
<p>注意:发布后所有用户可扫描下载本报告</p>
</div>
<footer>
<button name="action_confirm_publish" string="发布" type="object" class="btn-primary"/>
<button string="取消" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>