控制字段、page显隐逻辑

This commit is contained in:
mgw
2025-03-12 12:43:13 +08:00
parent de1bdbe18b
commit 5e51ee8db3
5 changed files with 55 additions and 37 deletions

View File

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

View File

@@ -265,12 +265,14 @@
<group>
<group>
<field name="company_id" invisible="1"/>
<field name="categ_type" invisible="1"/>
<field name="product_id" attrs="{'invisible' : [('measure_on', '=', 'operation')]}"/>
<field name="part_name"/>
<field name="part_number"/>
<field name="material_name"/>
<field name="total_qty"/>
<field name="check_qty"/>
<field name="part_name" attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>
<field name="part_number" attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>
<field name="material_name" attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>
<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="show_lot_text" invisible="1"/>
<field name="move_line_id" invisible="1"/>
@@ -343,14 +345,6 @@
<page string="出厂检验报告" name="out_check" attrs="{'invisible': [('is_out_check', '=', False)]}">
<!-- <field name="report_number"/> -->
</page>
<page string="2D加工图纸" name="2d_drawing" attrs="{'invisible': [('is_out_check', '=', False)]}">
<!-- <field name="2d_drawing"/> -->
</page>
<page string="质检标准" name="quality_standard" attrs="{'invisible': [('is_out_check', '=', False)]}">
<!-- <field name="quality_standard"/> -->
</page>
<page string="Notes" name="notes">
<group>

View File

@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="quality_point_out_check_report" model="quality.point">
<field name="title">出厂检验报告</field>
<field name="picking_type_ids" eval="[(4, ref('stock.picking_type_out'))]"/> <!-- 作业类型:发料出库 -->
<field name="measure_on">product</field> <!-- 控制方式:产品 -->
<field name="measure_frequency_type">all</field> <!-- 控制频率:全部 -->
<record id="test_type_factory_inspection" model="quality.point.test_type">
<field name="name">出厂检验报告</field>
<field name="technical_name">factory_inspection</field>
</record>
</data>
</odoo>

View File

@@ -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('出厂检验报告的测量对象必须为产品')

View File

@@ -37,11 +37,11 @@
</group>
</group>
</page>
<page string="2D图纸" attrs="{'invisible': [('production_id', '=', False)]}">
<field name="machining_drawings" string="" widget="adaptive_viewer"/>
<page string="2D加工图纸" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])]}">
<field name='machining_drawings' widget="adaptive_viewer"/>
</page>
<page string="客户质量标准" attrs="{'invisible': [('production_id', '=', False)]}">
<field name="quality_standard" string="" widget="adaptive_viewer"/>
<page string="质检标准" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])]}">
<field name='quality_standard' widget="adaptive_viewer"/>
</page>
<page string="其他"
attrs="{'invisible': ['|',('quality_state', 'not in', ['pass', 'fail']), ('production_id', '=', False)]}">