diff --git a/quality_control/models/quality.py b/quality_control/models/quality.py index 1af23aff..75c954ab 100644 --- a/quality_control/models/quality.py +++ b/quality_control/models/quality.py @@ -125,10 +125,9 @@ class QualityPoint(models.Model): class QualityCheck(models.Model): _inherit = "quality.check" - part_name = fields.Char('零件名称', compute='_compute_part_name_number', readonly=True) - part_number = fields.Char('零件图号', compute='_compute_part_name_number', readonly=True) - # 材料 - material_name = fields.Char('材料名称', compute='_compute_material_name', readonly=True) + part_name = fields.Char('零件名称', related='product_id.part_name') + part_number = fields.Char('零件图号', related='product_id.part_number') + material_name = fields.Char('材料名称', compute='_compute_material_name') # # 总数量,值为调拨单_产品明细_数量 # total_qty = fields.Float('总数量', compute='_compute_total_qty', readonly=True) @@ -137,15 +136,37 @@ class QualityCheck(models.Model): # # 出厂检验报告编号 # report_number = fields.Char('出厂检验报告编号', compute='_compute_report_number', readonly=True) # 总数量,值为调拨单_产品明细_数量 - total_qty = fields.Float('总数量', readonly=True) + total_qty = fields.Char('总数量', readonly=True) # 检验数 - check_qty = fields.Float('检验数', creadonly=True) + check_qty = fields.Char('检验数', default=lambda self: self._get_default_check_qty()) + + def _get_default_check_qty(self): + """根据条件设置检验数的默认值""" + # 这里需要使用_origin来获取已存储的记录,因为新记录在创建时可能还没有这些值 + if self._origin: + if self._origin.measure_on == 'product' and self._origin.test_type_id.name == '出厂检验报告': + return '' + elif self._origin.measure_on == 'product': + return '1' + return '' + + @api.onchange('test_type_id', 'measure_on') + def _onchange_check_qty(self): + """当测试类型或测量对象变化时,更新检验数""" + if self.measure_on == 'product' and self.test_type_id.name == '出厂检验报告': + self.check_qty = '' + elif self.measure_on == 'product': + self.check_qty = '1' + # 出厂检验报告编号 report_number_id = fields.Many2one('document.document', string='出厂检验报告编号', readonly=True) 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) + + def add_measure_line(self): """ 新增测量值,如果测量值有5列了,则提示“最多只能有5列测量值” @@ -164,11 +185,6 @@ class QualityCheck(models.Model): pass # self.ensure_one() - @depends('product_id') - def _compute_part_name_number(self): - for record in self: - record.part_number = record.product_id.part_number - record.part_name = record.product_id.part_name @depends('product_id') def _compute_material_name(self): @@ -177,10 +193,10 @@ class QualityCheck(models.Model): materials_type_name = record.product_id.materials_type_id.name if record.product_id.materials_type_id else '' record.material_name = materials_id_name + ' ' + materials_type_name - @depends('point_id') + @depends('test_type_id') def _compute_is_out_check(self): for record in self: - if record.point_id.title == '出厂检验报告': + if record.test_type_id.name == '出厂检验报告': record.is_out_check = True else: record.is_out_check = False diff --git a/quality_control/views/quality_views.xml b/quality_control/views/quality_views.xml index fe198f4a..b10295b8 100644 --- a/quality_control/views/quality_views.xml +++ b/quality_control/views/quality_views.xml @@ -265,12 +265,14 @@ + - - - - - + + + + + + @@ -343,14 +345,6 @@ - - - - - - - - diff --git a/sf_quality/data/check_standards.xml b/sf_quality/data/check_standards.xml index ace59578..98be59e8 100644 --- a/sf_quality/data/check_standards.xml +++ b/sf_quality/data/check_standards.xml @@ -1,11 +1,9 @@ - - 出厂检验报告 - - product - all + + 出厂检验报告 + factory_inspection diff --git a/sf_quality/models/custom_quality.py b/sf_quality/models/custom_quality.py index f2277b7e..9fdb2920 100644 --- a/sf_quality/models/custom_quality.py +++ b/sf_quality/models/custom_quality.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from odoo import models, fields - +from odoo import models, fields, api +from odoo.exceptions import ValidationError class SfQualityPoint(models.Model): _inherit = 'quality.point' @@ -16,4 +16,14 @@ class SfQualityPoint(models.Model): operation_id = fields.Many2one( 'mrp.routing.workcenter', 'Step', check_company=True, domain="[('is_outsource', '=', False),('company_id', 'in', (company_id, False))]") + + @api.onchange('test_type_id') + def _onchange_test_type_id(self): + """ + 如果类型选择了出厂检验报告,检查measure_on的值是否为product,如果为product,则类型的值不变,如果 + 不是,则提示错误 + """ + if self.test_type_id.name == '出厂检验报告': + if self.measure_on != 'product': + raise ValidationError('出厂检验报告的测量对象必须为产品') diff --git a/sf_quality/views/quality_check_view.xml b/sf_quality/views/quality_check_view.xml index 83ffcbca..4b1d6736 100644 --- a/sf_quality/views/quality_check_view.xml +++ b/sf_quality/views/quality_check_view.xml @@ -37,11 +37,11 @@ - - + + - - + +