添加功能

This commit is contained in:
李鹏宇
2025-10-14 14:41:25 +08:00
parent 7758e0a979
commit 549bea0715
2 changed files with 8 additions and 2 deletions
@@ -57,7 +57,10 @@ class PropertyMeterArchives(models.Model):
def create(self, vals):
record = super().create(vals)
if "name" in vals and vals["name"]:
existing_records = self.search([("name", "=", vals["name"])])
existing_records = self.search([
("name", "=", vals["name"]),
("id", "!=", record.id)
])
if existing_records:
raise ValidationError(
f"仪表编号 '{vals['name']}' 已存在,请使用其他编号!"
@@ -58,7 +58,10 @@ class PropertyMeterWater(models.Model):
def create(self, vals):
record = super().create(vals)
if "name" in vals and vals["name"]:
existing_records = self.search([("name", "=", vals["name"])])
existing_records = self.search([
("name", "=", vals["name"]),
("id", "!=", record.id)
])
if existing_records:
raise ValidationError(
f"仪表编号 '{vals['name']}' 已存在,请使用其他编号!"