Skip to content

Commit

Permalink
Merge pull request #94 from dibik96/15.0-1.1.0
Browse files Browse the repository at this point in the history
G2P-1397: Group and Individual Rest API ID Type validation
  • Loading branch information
shibu-narayanan authored Oct 30, 2023
2 parents 2462d8a + e771a1a commit 3711bed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion g2p_registry_base/models/reg_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

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


class G2PRegistrantID(models.Model):
Expand Down Expand Up @@ -67,4 +68,3 @@ class G2PIDType(models.Model):
"Name of the ID types should be unique",
),
]

16 changes: 16 additions & 0 deletions g2p_registry_rest_api/models/registrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def validate_id_type_no_spaces(cls, value): # noqa: B902
)
return value

@validator("value")
def validate_id_value(cls, value, values):
id_type = values.get("id_type")
if id_type:
id_type_id = request.env["g2p.id.type"].search(
[("name", "=", id_type)], limit=1
)
if not re.match(id_type_id.id_validation, value):
raise G2PApiValidationError(
error_message=G2PErrorCodes.G2P_REQ_005.get_error_message(),
error_code=G2PErrorCodes.G2P_REQ_005.get_error_code(),
error_description=f"The provided {id_type_id.name} ID '{value}' is invalid.",
)

return value


class RegistrantInfoIn(NaiveOrmModel):
name: str
Expand Down

0 comments on commit 3711bed

Please sign in to comment.