对发布按钮进行二次确认控制
This commit is contained in:
@@ -21,6 +21,7 @@ Quality Control
|
|||||||
'data': [
|
'data': [
|
||||||
'data/quality_control_data.xml',
|
'data/quality_control_data.xml',
|
||||||
'wizard/import_complex_model.xml',
|
'wizard/import_complex_model.xml',
|
||||||
|
'wizard/quality_wizard_view.xml',
|
||||||
'report/worksheet_custom_reports.xml',
|
'report/worksheet_custom_reports.xml',
|
||||||
'report/worksheet_custom_report_templates.xml',
|
'report/worksheet_custom_report_templates.xml',
|
||||||
'views/quality_views.xml',
|
'views/quality_views.xml',
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class QualityCheck(models.Model):
|
|||||||
record.total_qty = total_qty if total_qty > 0 else ''
|
record.total_qty = total_qty if total_qty > 0 else ''
|
||||||
else:
|
else:
|
||||||
record.total_qty = ''
|
record.total_qty = ''
|
||||||
|
|
||||||
# 检验数
|
# 检验数
|
||||||
check_qty = fields.Char('检验数', default=lambda self: self._get_default_check_qty())
|
check_qty = fields.Char('检验数', default=lambda self: self._get_default_check_qty())
|
||||||
|
|
||||||
@@ -232,8 +233,29 @@ class QualityCheck(models.Model):
|
|||||||
def do_publish(self):
|
def do_publish(self):
|
||||||
"""发布出厂检验报告"""
|
"""发布出厂检验报告"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
self._check_measure_line()
|
# self._check_measure_line()
|
||||||
self._check_check_qty_and_total_qty()
|
# 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. 获取报告动作
|
# 1. 获取报告动作
|
||||||
report_action = self.env.ref('sf_quality.action_report_quality_inspection')
|
report_action = self.env.ref('sf_quality.action_report_quality_inspection')
|
||||||
@@ -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:
|
if self.serial_number > 99:
|
||||||
raise UserError(_('流水号不能大于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 ''
|
str_part_number = self.part_number if self.part_number else ''
|
||||||
# 3. 创建文档记录
|
# 3. 创建文档记录
|
||||||
doc_vals = {
|
doc_vals = {
|
||||||
@@ -308,10 +332,13 @@ class QualityCheck(models.Model):
|
|||||||
if not getattr(line, f'measure_value{i}'):
|
if not getattr(line, f'measure_value{i}'):
|
||||||
raise UserError(_('有测量值为空'))
|
raise UserError(_('有测量值为空'))
|
||||||
|
|
||||||
|
|
||||||
# 发布前校验检验数与总数量、检验数与测量件数(即测量列数)
|
# 发布前校验检验数与总数量、检验数与测量件数(即测量列数)
|
||||||
def _check_check_qty_and_total_qty(self):
|
def _check_check_qty_and_total_qty(self):
|
||||||
for record in 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):
|
if int(record.check_qty) <= int(record.total_qty):
|
||||||
raise UserError(_('检验数不可超过总数量'))
|
raise UserError(_('检验数不可超过总数量'))
|
||||||
if int(record.column_nums) >= int(record.check_qty):
|
if int(record.column_nums) >= int(record.check_qty):
|
||||||
@@ -323,7 +350,9 @@ class QualityCheck(models.Model):
|
|||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
# 1. 获取已发布的文档文件夹
|
# 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. 将当前质检单关联的出厂检验报告文档位置移动到废弃文件夹
|
# 2. 将当前质检单关联的出厂检验报告文档位置移动到废弃文件夹
|
||||||
self.report_number_id.write({
|
self.report_number_id.write({
|
||||||
'folder_id': self.env.ref('sf_quality.documents_purchase_contracts_folder_canceled').id,
|
'folder_id': self.env.ref('sf_quality.documents_purchase_contracts_folder_canceled').id,
|
||||||
@@ -342,14 +371,12 @@ class QualityCheck(models.Model):
|
|||||||
})
|
})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def do_re_publish(self):
|
def do_re_publish(self):
|
||||||
"""
|
"""
|
||||||
重新发布出厂检验报告,参考发布规则
|
重新发布出厂检验报告,参考发布规则
|
||||||
"""
|
"""
|
||||||
self.do_publish()
|
self.do_publish()
|
||||||
|
|
||||||
|
|
||||||
def generate_qr_code(self):
|
def generate_qr_code(self):
|
||||||
"""生成二维码URL"""
|
"""生成二维码URL"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@@ -831,4 +858,3 @@ class QualityCheckReportHistory(models.Model):
|
|||||||
('published', '已发布'),
|
('published', '已发布'),
|
||||||
('canceled', '废弃')
|
('canceled', '废弃')
|
||||||
], string='操作后文档状态')
|
], string='操作后文档状态')
|
||||||
|
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ access_quality_check_wizard,access.quality_check_wizard,model_quality_check_wiza
|
|||||||
access_quality_check_measure_line,quality.check.measure.line,model_quality_check_measure_line,base.group_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_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
|
||||||
|
@@ -3,3 +3,4 @@
|
|||||||
|
|
||||||
from . import quality_check_wizard
|
from . import quality_check_wizard
|
||||||
from . import import_complex_model
|
from . import import_complex_model
|
||||||
|
from . import quality_wizard
|
||||||
|
|||||||
18
quality_control/wizard/quality_wizard.py
Normal file
18
quality_control/wizard/quality_wizard.py
Normal 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()
|
||||||
19
quality_control/wizard/quality_wizard_view.xml
Normal file
19
quality_control/wizard/quality_wizard_view.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user