Skip to content

Commit

Permalink
Merge pull request #57 from PSNAppz/17.0-1.4
Browse files Browse the repository at this point in the history
Queue unique_id generation for processing
  • Loading branch information
shibu-narayanan authored Nov 29, 2024
2 parents aa16422 + fe92d7d commit 6c226e6
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 508 deletions.
10 changes: 8 additions & 2 deletions g2p_social_registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@


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.que.id.generation"].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.

4 changes: 2 additions & 2 deletions g2p_social_registry/i18n/g2p_social_registry.pot
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ msgstr ""

#. module: g2p_social_registry
#: model:ir.model,name:g2p_social_registry.model_g2p_pending_reference_id
msgid "g2p.pending.reference_id"
msgid "g2p.que.id.generation"
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
57 changes: 57 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,57 @@
from odoo import fields, models


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

registrant_id = fields.Char(
required=True,
)

id_generation_request_status = fields.Selection(
selection=[
("pending", "Pending"),
("approved", "Approved"),
("rejected", "Rejected"),
],
required=True,
default="pending",
)

id_generation_update_status = fields.Selection(
selection=[
("not_applicable", "Not Applicable"),
("in_progress", "In Progress"),
("completed", "Completed"),
],
required=True,
default="not_applicable",
)

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

number_of_attempts_request = fields.Integer(
required=True,
default=0,
)

number_of_attempts_update = fields.Integer(
required=True,
default=0,
)

last_attempt_error_code_request = fields.Char()

last_attempt_error_code_update = fields.Char()

last_attempt_datetime_request = fields.Datetime()

last_attempt_datetime_update = fields.Datetime()

_sql_constraints = [
("registrant_id_uniq", "UNIQUE(registrant_id)", "registrant_id is an unique identifier!"),
]
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.

44 changes: 13 additions & 31 deletions g2p_social_registry/models/registrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import logging

import requests

from odoo import api, fields, models

_logger = logging.getLogger(__name__)
Expand All @@ -13,43 +11,27 @@ 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.

6 changes: 2 additions & 4 deletions g2p_social_registry/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
g2p_region_admin,Region Admin Access,g2p_social_registry.model_g2p_region,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_region_registrar,Region Registrar Access,g2p_social_registry.model_g2p_region,,1,0,0,0
g2p_pending_reference_id_admin,Pending Reference ID Admin Access,g2p_social_registry.model_g2p_pending_reference_id,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_pending_reference_id_registrar,Pending Reference ID Registrar Access,g2p_social_registry.model_g2p_pending_reference_id,,1,0,0,0
g2p_reference_id_config_admin,Reference ID Config Admin Access,g2p_social_registry.model_g2p_reference_id_config,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_reference_id_config_registrar,Reference ID Config Registrar Access,g2p_social_registry.model_g2p_reference_id_config,,1,0,0,0
g2p_que_id_generation_admin,Queue ID Generation Admin Access,g2p_social_registry.model_g2p_que_id_generation,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_que_id_generation_registrar,Queue ID Generation Registrar Access,g2p_social_registry.model_g2p_que_id_generation,,1,0,0,0
Loading

0 comments on commit 6c226e6

Please sign in to comment.