Skip to content

Commit

Permalink
Merge pull request #103 from RamakrishnaVellala/15.0-develop-main
Browse files Browse the repository at this point in the history
G2P-1279 Not allowing duplicate values for registry configurations
  • Loading branch information
shibu-narayanan authored Nov 30, 2023
2 parents c628f17 + 9d69b95 commit 5845b0a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
19 changes: 11 additions & 8 deletions g2p_registry_base/models/reg_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re

from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -62,10 +62,13 @@ class G2PIDType(models.Model):
name = fields.Char()
id_validation = fields.Char()

_sql_constraints = [
(
"name_unique",
"unique (name)",
"Name of the ID types should be unique",
),
]
@api.constrains("name")
def _check_name(self):
id_types = self.search([])
for record in self:
if not record.name:
error_message = _("Id type should not empty.")
raise ValidationError(error_message)
for record in id_types:
if self.name.lower() == record.name.lower() and self.id != record.id:
raise ValidationError(_("Id type already exists"))
21 changes: 13 additions & 8 deletions g2p_registry_base/models/tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Part of OpenG2P Registry. See LICENSE file for full copyright and licensing details.
from random import randint

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class G2PRegistrantTags(models.Model):
Expand All @@ -16,10 +17,14 @@ def _get_default_color(self):
active = fields.Boolean(
default=True, help="Archive to hide the RegistrantTag without removing it."
)
_sql_constraints = [
(
"name_unique",
"unique (name)",
"Name of the tags should be unique",
),
]

@api.constrains("name")
def _check_name(self):
tags = self.search([])
for record in self:
if not record.name:
error_message = _("Tag name should not empty.")
raise ValidationError(error_message)
for tag in tags:
if self.name.lower() == tag.name.lower() and self.id != tag.id:
raise ValidationError(_("Tag already Exists"))
20 changes: 12 additions & 8 deletions g2p_registry_group/models/group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Part of OpenG2P Registry. See LICENSE file for full copyright and licensing details.
import logging

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)

Expand All @@ -21,10 +22,13 @@ class G2PGroupKind(models.Model):

name = fields.Char("Kind")

_sql_constraints = [
(
"name_unique",
"unique (name)",
"Name of the kind should be unique",
),
]
@api.constrains("name")
def _check_name(self):
group_types = self.search([])
for record in self:
if not record.name:
error_message = _("kind should not empty.")
raise ValidationError(error_message)
for record in group_types:
if self.name.lower() == record.name.lower() and self.id != record.id:
raise ValidationError(_("kind already exists"))
20 changes: 12 additions & 8 deletions g2p_registry_individual/models/gender.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class G2PGender(models.Model):
Expand All @@ -9,10 +10,13 @@ class G2PGender(models.Model):
value = fields.Char()
active = fields.Boolean(default=True)

_sql_constraints = [
(
"code_unique",
"unique (code)",
"Gender type should be unique",
),
]
@api.constrains("code")
def _check_name(self):
group_types = self.search([])
for record in self:
if not record.code:
error_message = _("Gender type should not empty.")
raise ValidationError(error_message)
for record in group_types:
if self.code.lower() == record.code.lower() and self.id != record.id:
raise ValidationError(_("Gender type should be unique"))
17 changes: 10 additions & 7 deletions g2p_registry_membership/models/group_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,13 @@ def write(self, vals):
else:
return super(G2PGroupMembershipKind, self).write(vals)

_sql_constraints = [
(
"name_unique",
"unique (name)",
"Name of the kind should be unique",
),
]
@api.constrains("name")
def _check_name(self):
group_types = self.search([])
for record in self:
if not record.name:
error_message = _("kind should not empty.")
raise ValidationError(error_message)
for record in group_types:
if self.name.lower() == record.name.lower() and self.id != record.id:
raise ValidationError(_("kind already exists"))

0 comments on commit 5845b0a

Please sign in to comment.