检测报告发布流程
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">
|
||||
|
||||
Reference in New Issue
Block a user