Merge pull request !10359 from 李鹏宇/dev_wang
This commit is contained in:
李鹏宇
2026-03-30 07:26:55 +00:00
committed by Gitee
2 changed files with 16 additions and 12 deletions
@@ -9,6 +9,13 @@ class ProductTemplate(models.Model):
@api.onchange('is_fixed_assets')
def _onchange_fixed_assets(self):
"""勾选/取消“是否固定资产”时,动态限制产品类别的可选范围。
- 勾选:`categ_id` 只允许名称包含“固定资产”的类别
- 取消:`categ_id` 不加限制
同时保留“已关联设备不允许取消固定资产”的校验。
"""
# 原有校验逻辑:已作为固定资产使用时不允许取消
if not self.is_fixed_assets and self._origin.is_fixed_assets:
related_equipments = self.env['maintenance.equipment'].search([
('name', '=', self.name)
@@ -16,6 +23,12 @@ class ProductTemplate(models.Model):
if related_equipments:
raise UserError('该产品已关联设备,请先删除固定资产')
# 根据是否固定资产,返回动态 domain
if self.is_fixed_assets:
domain = {'categ_id': [('name', 'ilike', '固定资产')]}
else:
domain = {'categ_id': []}
return {'domain': domain}
def update_company_id(self):
@@ -10,18 +10,9 @@
<attribute name="string">产品类型</attribute>
</xpath>
<!-- 修改categ_id字段:中文标签 + 固定资产时收紧可选类别 -->
<xpath expr="//field[@name='categ_id']" position="replace">
<!-- 非固定资产:正常类别,下拉不做限制 -->
<field name="categ_id"
string="产品类别"
attrs="{'invisible': [('is_fixed_assets', '=', True)]}"/>
<!-- 固定资产:只显示名称包含“固定资产”的类别 -->
<field name="categ_id"
string="产品类别"
attrs="{'invisible': [('is_fixed_assets', '=', False)]}"
domain="[('name', 'ilike', '固定资产')]"/>
<!-- 修改categ_id字段标签为中文 -->
<xpath expr="//field[@name='categ_id']" position="attributes">
<attribute name="string">产品类别</attribute>
</xpath>
<!-- 隐藏Internal Notes分组(通过隐藏description字段的父级group) -->