Skip to content

Commit

Permalink
fix write, added loop for multiple records
Browse files Browse the repository at this point in the history
  • Loading branch information
emjay0921 committed Oct 22, 2024
1 parent 89b3eb5 commit f6efa37
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions g2p_registry_membership/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ class G2PMembershipGroup(models.Model):
def write(self, values):
res = super().write(values)
if self:
unique_kinds = self.env["g2p.group.membership.kind"].search([("is_unique", "=", True)])
for unique_kind in unique_kinds:
count = sum(1 for rec in self.group_membership_ids if unique_kind.id in rec.kind.ids)
if count > 1:
raise ValidationError(_("Only one %s is allowed per group") % unique_kind.name)
for rec in self:
unique_kinds = self.env["g2p.group.membership.kind"].search([("is_unique", "=", True)])
for unique_kind in unique_kinds:
count = sum(1 for member in rec.group_membership_ids if unique_kind.id in member.kind.ids)
if count > 1:
raise ValidationError(_("Only one %s is allowed per group") % unique_kind.name)
return res

@api.model
Expand Down

0 comments on commit f6efa37

Please sign in to comment.