检测报告发布流程
This commit is contained in:
@@ -11,6 +11,8 @@ from odoo.api import depends
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, float_round
|
||||
from odoo.osv.expression import OR
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import image_data_uri
|
||||
from base64 import b64encode
|
||||
|
||||
|
||||
class QualityPoint(models.Model):
|
||||
@@ -170,13 +172,26 @@ class QualityCheck(models.Model):
|
||||
self.check_qty = '1'
|
||||
|
||||
# 出厂检验报告编号
|
||||
report_number_id = fields.Many2one('document.document', string='出厂检验报告编号', readonly=True)
|
||||
report_number_id = fields.Many2one('documents.document', string='出厂检验报告编号', readonly=True)
|
||||
|
||||
# 出厂检验报告、关联文档的数据
|
||||
report_content = fields.Binary(string='出厂检验报告', related='report_number_id.datas')
|
||||
|
||||
is_out_check = fields.Boolean(string='是否出库检验', compute='_compute_is_out_check', readonly=True)
|
||||
|
||||
measure_line_ids = fields.One2many('quality.check.measure.line', 'check_id', string='测量明细')
|
||||
|
||||
categ_type = fields.Selection(string='产品的类别', related='product_id.categ_id.type', store=True)
|
||||
|
||||
report_result = fields.Selection([
|
||||
('OK', 'OK'),
|
||||
('NG', 'NG')
|
||||
], string='出厂检验报告结果', default='OK')
|
||||
measure_operator = fields.Char('测量员', readonly=True)
|
||||
quality_manager = fields.Char('质量管理人员', readonly=True)
|
||||
|
||||
|
||||
|
||||
def add_measure_line(self):
|
||||
"""
|
||||
新增测量值,如果测量值有5列了,则提示“最多只能有5列测量值”
|
||||
@@ -202,10 +217,46 @@ class QualityCheck(models.Model):
|
||||
pass
|
||||
|
||||
def do_publish(self):
|
||||
"""
|
||||
发布出厂检验报告
|
||||
"""
|
||||
pass
|
||||
"""发布出厂检验报告"""
|
||||
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参数
|
||||
res_ids=self.ids
|
||||
)
|
||||
|
||||
# 获取默认的文档文件夹
|
||||
workspace = self.env['documents.folder'].search([('name', '=', '出厂检验报告')], limit=1)
|
||||
|
||||
# 3. 创建文档记录
|
||||
doc_vals = {
|
||||
'name': f'FQC-{self.name}',
|
||||
'raw': pdf_content,
|
||||
'mimetype': 'application/pdf',
|
||||
'res_id': self.id,
|
||||
'folder_id': workspace.id,
|
||||
'res_model': self._name,
|
||||
}
|
||||
|
||||
# 如果已经有报告,则更新
|
||||
if self.report_number_id:
|
||||
self.report_number_id.write(doc_vals)
|
||||
else:
|
||||
# 创建新的document记录
|
||||
doc = self.env['documents.document'].create(doc_vals)
|
||||
# 关联到当前质检记录
|
||||
self.write({
|
||||
'report_number_id': doc.id,
|
||||
'measure_operator': self.env.user.name, # 记录操作人
|
||||
'quality_manager': self.env.user.name, # 记录质检人
|
||||
})
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def do_cancel_publish(self):
|
||||
"""
|
||||
@@ -219,6 +270,17 @@ class QualityCheck(models.Model):
|
||||
"""
|
||||
pass
|
||||
|
||||
def generate_qr_code(self):
|
||||
"""生成二维码URL"""
|
||||
self.ensure_one()
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
return image_data_uri(
|
||||
b64encode(self.env['ir.actions.report'].barcode(
|
||||
'QR', base_url + '/#/index/publicPay?order_id=' + str(self.id) + '&source=%2Findex%2Fmyorder',
|
||||
width=140, height=140)
|
||||
)
|
||||
)
|
||||
|
||||
@depends('product_id')
|
||||
def _compute_material_name(self):
|
||||
for record in self:
|
||||
|
||||
@@ -273,7 +273,7 @@
|
||||
<field name="total_qty" attrs="{'invisible': ['|', ('measure_on', '!=', 'product'), ('is_out_check', '=', False)]}"/>
|
||||
<field name="check_qty" attrs="{'invisible': [('measure_on', '!=', 'product')]}"/>
|
||||
<!-- <field name="categ_type"/> -->
|
||||
<!-- <field name="report_number"/> -->
|
||||
<field name="report_number_id"/>
|
||||
<field name="show_lot_text" invisible="1"/>
|
||||
<field name="move_line_id" invisible="1"/>
|
||||
<field name="product_tracking" invisible="1"/>
|
||||
@@ -343,7 +343,7 @@
|
||||
</div>
|
||||
</page>
|
||||
<page string="出厂检验报告" name="out_check" attrs="{'invisible': [('is_out_check', '=', False)]}">
|
||||
<!-- <field name="report_number"/> -->
|
||||
<field name="report_content" widget="adaptive_viewer"/>
|
||||
</page>
|
||||
|
||||
<page string="Notes" name="notes">
|
||||
|
||||
@@ -17,10 +17,14 @@
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/check_standards.xml',
|
||||
'data/documents_data.xml',
|
||||
'data/insepection_report_template.xml',
|
||||
'data/report_actions.xml',
|
||||
'views/view.xml',
|
||||
'views/quality_cnc_test_view.xml',
|
||||
'views/mrp_workorder.xml',
|
||||
'views/quality_check_view.xml'
|
||||
'views/quality_check_view.xml',
|
||||
'views/quality_company.xml'
|
||||
],
|
||||
|
||||
'assets': {
|
||||
|
||||
11
sf_quality/data/documents_data.xml
Normal file
11
sf_quality/data/documents_data.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<!-- 创建采购合同文件夹 -->
|
||||
<record id="documents_purchase_contracts_folder" model="documents.folder">
|
||||
<field name="name">出厂检验报告</field>
|
||||
<field name="description">存放出厂检验报告相关文件</field>
|
||||
<field name="sequence">11</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
146
sf_quality/data/insepection_report_template.xml
Normal file
146
sf_quality/data/insepection_report_template.xml
Normal file
@@ -0,0 +1,146 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- 定义页眉模板 -->
|
||||
<template id="report_quality_header">
|
||||
<div class="header">
|
||||
<div class="pdf-viewer-toolbar">
|
||||
<img t-if="o.company_id.favicon" t-att-src="image_data_uri(o.company_id.favicon)" style="max-height: 70px;" alt="Logo"/>
|
||||
<div class="float-right" style="text-align: right;">
|
||||
<!-- 使用完整URL的二维码生成方式 -->
|
||||
<t t-set="base_url" t-value="request.env['ir.config_parameter'].sudo().get_param('web.base.url')"/>
|
||||
<t t-set="report_url" t-value="'%s/web#id=%s&model=quality.check&view_type=form' % (base_url, o.id)"/>
|
||||
<img t-att-src="'/report/barcode/QR/%s' % report_url" style="width:80px;height:80px"/>
|
||||
<div style="font-size: 20px;">
|
||||
<strong>报告编号: </strong><span t-field="o.name"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 定义页脚模板 -->
|
||||
<template id="report_quality_footer">
|
||||
<div class="footer">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<p>售后服务: <span t-field="o.company_id.phone"/></p>
|
||||
<p>公司名称: <span t-field="o.company_id.name"/></p>
|
||||
<p>公司网址: <span t-field="o.company_id.website"/></p>
|
||||
<p>公司邮箱: <span t-field="o.company_id.email"/></p>
|
||||
<p>加工工厂: <span t-field="o.company_id.factory_name"/></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<span>第<span class="page"/> 页/共 <span class="topage"/>页</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template id="report_quality_inspection">
|
||||
<t t-call="web.html_container">
|
||||
<t t-foreach="docs" t-as="o">
|
||||
<t t-call="web.basic_layout">
|
||||
<!-- 调用自定义页眉 -->
|
||||
<t t-call="sf_quality.report_quality_header"/>
|
||||
|
||||
|
||||
<div class="page">
|
||||
<div class="text-center">
|
||||
<h2>出厂检验报告</h2>
|
||||
</div>
|
||||
<!-- <div class="col-6">
|
||||
<div t-if="o.company_id.favicon" class="float-right">
|
||||
<img t-att-src="image_data_uri(o.company_id.favicon)" style="max-height: 45px;" alt="Logo"/>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- </div> -->
|
||||
|
||||
<table class="table table-sm o_main_table mt-4" style="border: 1px solid black;">
|
||||
<tr>
|
||||
<td style="width: 15%; border: 1px solid black;"><strong>产品名称:</strong></td>
|
||||
<td style="width: 35%; border: 1px solid black;"><span t-field="o.product_id.name"/></td>
|
||||
<td style="width: 15%; border: 1px solid black;"><strong>材料:</strong></td>
|
||||
<td style="width: 35%; border: 1px solid black;"><span t-field="o.material_name"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 1px solid black;"><strong>图号:</strong></td>
|
||||
<td style="border: 1px solid black;"><span t-field="o.part_number"/></td>
|
||||
<td style="border: 1px solid black;"><strong>日期:</strong></td>
|
||||
<td style="border: 1px solid black;"><span t-field="o.write_date"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 1px solid black;"><strong>总数量:</strong></td>
|
||||
<td style="border: 1px solid black;"><span t-field="o.total_qty"/></td>
|
||||
<td style="border: 1px solid black;"><strong>检验数量:</strong></td>
|
||||
<td style="border: 1px solid black;"><span t-field="o.check_qty"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4 class="text-center mt-4">检验结果</h4>
|
||||
<table class="table table-sm mt-2" style="border: 1px solid black;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid black;">检测项目</th>
|
||||
<th style="border: 1px solid black;" colspan="5">测量值</th>
|
||||
<th style="border: 1px solid black;">判定</th>
|
||||
<th style="border: 1px solid black;">备注</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="border: 1px solid black;"></th>
|
||||
<th style="border: 1px solid black;">1</th>
|
||||
<th style="border: 1px solid black;">2</th>
|
||||
<th style="border: 1px solid black;">3</th>
|
||||
<th style="border: 1px solid black;">4</th>
|
||||
<th style="border: 1px solid black;">5</th>
|
||||
<th style="border: 1px solid black;"></th>
|
||||
<th style="border: 1px solid black;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="o.measure_line_ids" t-as="line">
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_item"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_value1"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_value2"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_value3"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_value4"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_value5"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.measure_result"/></td>
|
||||
<td style="border: 1px solid black;"><span t-field="line.remark"/></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-12">
|
||||
<h5>检验结论:
|
||||
<span t-if="o.report_result == 'OK'" style="margin-left: 20px;">☑ 合格</span>
|
||||
<span t-else="" style="margin-left: 20px;">□ 合格</span>
|
||||
<span t-if="o.report_result == 'NG'" style="margin-left: 40px;">☑ 不合格</span>
|
||||
<span t-else="" style="margin-left: 40px;">□ 不合格</span>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-6">
|
||||
<p><strong>操作员: </strong> <span t-field="o.measure_operator"/></p>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<p><strong>质检员: </strong> <span t-field="o.quality_manager"/></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-5">
|
||||
<div class="col-12 text-center">
|
||||
<p>(以下空白)</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 调用自定义页脚 -->
|
||||
<t t-call="sf_quality.report_quality_footer"/>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
</odoo>
|
||||
22
sf_quality/data/report_actions.xml
Normal file
22
sf_quality/data/report_actions.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="action_report_quality_inspection" model="ir.actions.report">
|
||||
<field name="name">出厂检验报告</field>
|
||||
<field name="model">quality.check</field> <!-- 请替换为实际的模型名称 -->
|
||||
<field name="report_type">qweb-pdf</field>
|
||||
<field name="report_name">sf_quality.report_quality_inspection</field>
|
||||
<field name="report_file">sf_quality.report_quality_inspection</field>
|
||||
<field name="print_report_name">'QC-' + object.name + '.pdf'</field>
|
||||
<field name="binding_model_id" ref="model_quality_check"/> <!-- 请替换为实际的模型ID引用 -->
|
||||
<field name="binding_type">report</field>
|
||||
</record>
|
||||
|
||||
<!-- 定义HTML预览报告动作 -->
|
||||
<record id="action_report_quality_inspection_preview" model="ir.actions.report">
|
||||
<field name="name">预览检验报告</field>
|
||||
<field name="model">quality.inspection</field>
|
||||
<field name="report_type">qweb-html</field>
|
||||
<field name="report_name">sf_quality.report_quality_inspection</field>
|
||||
<field name="binding_type">report</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -6,3 +6,4 @@ from . import quality
|
||||
from . import quality_cnc_test
|
||||
from . import mrp_workorder
|
||||
# from . import stock
|
||||
from . import quality_company
|
||||
|
||||
8
sf_quality/models/quality_company.py
Normal file
8
sf_quality/models/quality_company.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
# 为公司增加字段
|
||||
class Company(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
factory_name = fields.Char('加工工厂')
|
||||
@@ -70,6 +70,14 @@
|
||||
|
||||
<xpath expr="//header" position="inside">
|
||||
<field name="is_out_check" invisible="1"/>
|
||||
<button name="%(sf_quality.action_report_quality_inspection_preview)d"
|
||||
string="预览报告"
|
||||
type="action"
|
||||
class="oe_highlight"/>
|
||||
<!-- 如果还需要打印按钮 -->
|
||||
<button name="%(sf_quality.action_report_quality_inspection)d"
|
||||
string="打印报告"
|
||||
type="action"/>
|
||||
<button name="do_preview" string="预览" type="object" class="btn-primary" attrs="{'invisible': [('is_out_check', '=', False)]}"/>
|
||||
<button name="do_publish" string="发布" type="object" class="btn-primary" attrs="{'invisible': [('is_out_check', '=', False)]}"/>
|
||||
<button name="do_cancel_publish" string="取消发布" type="object" class="btn-primary" attrs="{'invisible': [('is_out_check', '=', False)]}"/>
|
||||
|
||||
13
sf_quality/views/quality_company.xml
Normal file
13
sf_quality/views/quality_company.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
<odoo>
|
||||
<record id="sf_quality_company_view" model="ir.ui.view">
|
||||
<field name="name">sf.quality.company.view</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="base.view_company_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="factory_name"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user