Skip to content

Commit

Permalink
Remove ref_id to replace with unique_id.
Browse files Browse the repository at this point in the history
  • Loading branch information
PSNAppz committed Nov 28, 2024
1 parent aa16422 commit 4cbe1a0
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 502 deletions.
6 changes: 3 additions & 3 deletions g2p_social_registry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Part of OpenG2P Registry. See LICENSE file for full copyright and licensing details.
from . import models


def post_init_hook(env):
partners = env["res.partner"].search([("is_registrant", "=", True), ("ref_id", "=", False)])
partners = env["res.partner"].search([("is_registrant", "=", True), ("unique_id", "=", False)])
for partner in partners:
env["g2p.pending.reference_id"].create({"registrant_id": partner.id, "status": "failed"})
env["g2p.pending.reference_id"].create({"registrant_id": partner.id, "id_generation_request_status": "pending",
"id_generation_update_status": "not_applicable"})
3 changes: 0 additions & 3 deletions g2p_social_registry/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
"external_dependencies": {"python": ["python-jose"]},
"data": [
"security/ir.model.access.csv",
"data/cron_job.xml",
"data/default_ref_id_config.xml",
"views/main_view.xml",
"views/region.xml",
"views/registrant_view.xml",
"views/res_config_settings_view.xml",
],
"assets": {},
"demo": [],
Expand Down
17 changes: 0 additions & 17 deletions g2p_social_registry/data/cron_job.xml

This file was deleted.

9 changes: 0 additions & 9 deletions g2p_social_registry/data/default_ref_id_config.xml

This file was deleted.

2 changes: 1 addition & 1 deletion g2p_social_registry/i18n/g2p_social_registry.pot
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,5 @@ msgstr ""

#. module: g2p_social_registry
#: model:ir.model.constraint,message:g2p_social_registry.constraint_res_partner_ref_id_uniq
msgid "ref_id is an unique identifier!"
msgid "unique_id is an unique identifier!"
msgstr ""
4 changes: 1 addition & 3 deletions g2p_social_registry/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.

from . import region
from . import ref_id_config
from . import res_config_settings
from . import registrant
from . import pending_ref_id
from . import g2p_que_id_generation
70 changes: 70 additions & 0 deletions g2p_social_registry/models/g2p_que_id_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from odoo import models, fields, api
from datetime import datetime


class G2PQueIDGeneration(models.Model):
_name = "g2p.que.id.generation"
_description = "G2P Queue ID Generation"

registrant_id = fields.Char(
string="Registrant ID",
required=True,
unique=True,
)

id_generation_request_status = fields.Selection(
selection=[
('pending', 'Pending'),
('approved', 'Approved'),
('rejected', 'Rejected'),
],
string="ID Generation Request Status",
required=True,
default='pending',
)

id_generation_update_status = fields.Selection(
selection=[
('not_applicable', 'Not Applicable'),
('in_progress', 'In Progress'),
('completed', 'Completed'),
],
string="ID Generation Update Status",
required=True,
default='not_applicable',
)

queued_datetime = fields.Datetime(
string="Queued Datetime",
required=True,
default=fields.Datetime.now,
)

number_of_attempts_request = fields.Integer(
string="Number of Attempts (Request)",
required=True,
default=0,
)

number_of_attempts_update = fields.Integer(
string="Number of Attempts (Update)",
required=True,
default=0,
)

last_attempt_error_code_request = fields.Char(
string="Last Attempt Error Code (Request)"
)

last_attempt_error_code_update = fields.Char(
string="Last Attempt Error Code (Update)"
)

last_attempt_datetime_request = fields.Datetime(
string="Last Attempt Datetime (Request)"
)

last_attempt_datetime_update = fields.Datetime(
string="Last Attempt Datetime (Update)"
)

36 changes: 0 additions & 36 deletions g2p_social_registry/models/pending_ref_id.py

This file was deleted.

76 changes: 0 additions & 76 deletions g2p_social_registry/models/ref_id_config.py

This file was deleted.

37 changes: 8 additions & 29 deletions g2p_social_registry/models/registrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,22 @@ class ResPartner(models.Model):
_inherit = "res.partner"

region = fields.Many2one("g2p.region")
ref_id = fields.Char(string="Reference ID", index=True)
unique_id = fields.Char(string="Reference ID", index=True)

_sql_constraints = [
("ref_id_uniq", "UNIQUE(ref_id)", "ref_id is an unique identifier!"),
("unique_id_uniq", "UNIQUE(unique_id)", "unique_id is an unique identifier!"),
]

@api.model
def create(self, vals):
record = super().create(vals)
if vals.get("is_registrant"):
record.generate_ref_id()
record.generate_unique_id_id()
return record

def generate_ref_id(self):
def generate_unique_id_id(self):
for rec in self:
try:
config = self.env["g2p.reference_id.config"].get_config()

access_token = config.get_access_token()
headers = {"Cookie": f"Authorization={access_token}"}

response = requests.get(config.base_api_url, headers=headers, timeout=config.api_timeout)
_logger.debug("ID Generator API response: %s", response.text)
response.raise_for_status()
res = response.json()

unique_id = res.get("response")["uin"]
rec.ref_id = rec.get_ref_id_prefix() + unique_id if rec.get_ref_id_prefix() else unique_id

except Exception as e:
_logger.error("Failed to generate ref_id for partner %s: %s", rec.id, str(e))

pending_ref_id_model = self.env["g2p.pending.reference_id"]

if not pending_ref_id_model.search([("registrant_id", "=", rec.id)]):
pending_ref_id_model.create({"registrant_id": rec.id, "status": "failed"})

def get_ref_id_prefix(self):
# Override this method for customization
return
g2p_que_id_model = self.env["g2p.que.id.generation"]
if not g2p_que_id_model.search([("registrant_id", "=", rec.id)]):
g2p_que_id_model.create({"registrant_id": rec.id, "id_generation_request_status": "pending",
"id_generation_update_status": "not_applicable"})
73 changes: 0 additions & 73 deletions g2p_social_registry/models/res_config_settings.py

This file was deleted.

4 changes: 1 addition & 3 deletions g2p_social_registry/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Part of OpenG2P Social Registry. See LICENSE file for full copyright and licensing details.

from . import test_ref_id_config
from . import test_res_config_settings
from . import test_pending_ref_id
from . import test_g2p_que_id_generation
Loading

0 comments on commit 4cbe1a0

Please sign in to comment.