Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PSNAppz committed Nov 28, 2024
1 parent 6ae5dfc commit fe92d7d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 90 deletions.
10 changes: 8 additions & 2 deletions g2p_social_registry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# 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), ("unique_id", "=", False)])
for partner in partners:
env["g2p.que.id.generation"].create({"registrant_id": partner.id, "id_generation_request_status": "pending",
"id_generation_update_status": "not_applicable"})
env["g2p.que.id.generation"].create(
{
"registrant_id": partner.id,
"id_generation_request_status": "pending",
"id_generation_update_status": "not_applicable",
}
)
41 changes: 13 additions & 28 deletions g2p_social_registry/models/g2p_que_id_generation.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,56 @@
from odoo import models, fields, api
from datetime import datetime
from odoo import fields, models


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

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

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

id_generation_update_status = fields.Selection(
selection=[
('not_applicable', 'Not Applicable'),
('in_progress', 'In Progress'),
('completed', 'Completed'),
("not_applicable", "Not Applicable"),
("in_progress", "In Progress"),
("completed", "Completed"),
],
string="ID Generation Update Status",
required=True,
default='not_applicable',
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_request = fields.Char()

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

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

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

_sql_constraints = [
("registrant_id_uniq", "UNIQUE(registrant_id)", "registrant_id is an unique identifier!"),
Expand Down
11 changes: 7 additions & 4 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 @@ -30,5 +28,10 @@ def generate_unique_id_id(self):
for rec in self:
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"})
g2p_que_id_model.create(
{
"registrant_id": rec.id,
"id_generation_request_status": "pending",
"id_generation_update_status": "not_applicable",
}
)
106 changes: 50 additions & 56 deletions g2p_social_registry/tests/test_g2p_que_id_generation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from odoo.tests import TransactionCase
from odoo.exceptions import ValidationError
from odoo import fields
from psycopg2 import IntegrityError
from odoo.tests import TransactionCase


class TestG2PQueIDGeneration(TransactionCase):
Expand All @@ -26,45 +24,43 @@ def test_create_g2p_queue_record(self):
"""
self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.")
self.assertEqual(
self.g2p_queue.registrant_id, str(self.partner1.id),
"Registrant ID does not match the expected partner."
self.g2p_queue.registrant_id,
str(self.partner1.id),
"Registrant ID does not match the expected partner.",
)
self.assertEqual(
self.g2p_queue.id_generation_request_status, "pending",
"Default ID Generation Request Status should be 'pending'."
self.g2p_queue.id_generation_request_status,
"pending",
"Default ID Generation Request Status should be 'pending'.",
)
self.assertEqual(
self.g2p_queue.id_generation_update_status, "not_applicable",
"Default ID Generation Update Status should be 'not_applicable'."
self.g2p_queue.id_generation_update_status,
"not_applicable",
"Default ID Generation Update Status should be 'not_applicable'.",
)
self.assertEqual(
self.g2p_queue.number_of_attempts_request, 0,
"Default number_of_attempts_request should be 0."
self.g2p_queue.number_of_attempts_request, 0, "Default number_of_attempts_request should be 0."
)
self.assertEqual(
self.g2p_queue.number_of_attempts_update, 0,
"Default number_of_attempts_update should be 0."
self.g2p_queue.number_of_attempts_update, 0, "Default number_of_attempts_update should be 0."
)
self.assertFalse(
self.g2p_queue.last_attempt_error_code_request,
"last_attempt_error_code_request should be empty by default."
"last_attempt_error_code_request should be empty by default.",
)
self.assertFalse(
self.g2p_queue.last_attempt_error_code_update,
"last_attempt_error_code_update should be empty by default."
"last_attempt_error_code_update should be empty by default.",
)
self.assertFalse(
self.g2p_queue.last_attempt_datetime_request,
"last_attempt_datetime_request should be empty by default."
"last_attempt_datetime_request should be empty by default.",
)
self.assertFalse(
self.g2p_queue.last_attempt_datetime_update,
"last_attempt_datetime_update should be empty by default."
)
self.assertTrue(
self.g2p_queue.queued_datetime,
"queued_datetime should be set by default."
"last_attempt_datetime_update should be empty by default.",
)
self.assertTrue(self.g2p_queue.queued_datetime, "queued_datetime should be set by default.")

def test_multiple_g2p_queue_records(self):
"""
Expand All @@ -82,26 +78,27 @@ def test_multiple_g2p_queue_records(self):

self.assertTrue(record2, "Second G2PQueIDGeneration record was not created.")
self.assertEqual(
record2.registrant_id, str(self.partner2.id),
"Registrant ID for the second record does not match the expected partner."
record2.registrant_id,
str(self.partner2.id),
"Registrant ID for the second record does not match the expected partner.",
)
self.assertEqual(
record2.id_generation_request_status, "approved",
"ID Generation Request Status should be 'approved'."
record2.id_generation_request_status,
"approved",
"ID Generation Request Status should be 'approved'.",
)
self.assertEqual(
record2.id_generation_update_status, "in_progress",
"ID Generation Update Status should be 'in_progress'."
record2.id_generation_update_status,
"in_progress",
"ID Generation Update Status should be 'in_progress'.",
)

self.assertEqual(
record2.last_attempt_error_code_request, "ERR001",
"last_attempt_error_code_request should be 'ERR001'."
)
self.assertTrue(
record2.last_attempt_datetime_request,
"last_attempt_datetime_request should be set."
record2.last_attempt_error_code_request,
"ERR001",
"last_attempt_error_code_request should be 'ERR001'.",
)
self.assertTrue(record2.last_attempt_datetime_request, "last_attempt_datetime_request should be set.")

def test_field_assignments(self):
"""
Expand All @@ -116,19 +113,19 @@ def test_field_assignments(self):
)

self.assertEqual(
self.g2p_queue.id_generation_request_status, "approved",
"ID Generation Request Status should be updated to 'approved'."
self.g2p_queue.id_generation_request_status,
"approved",
"ID Generation Request Status should be updated to 'approved'.",
)
self.assertEqual(
self.g2p_queue.id_generation_update_status, "completed",
"ID Generation Update Status should be updated to 'completed'."
self.g2p_queue.id_generation_update_status,
"completed",
"ID Generation Update Status should be updated to 'completed'.",
)
self.assertEqual(
self.g2p_queue.number_of_attempts_request, 1,
"number_of_attempts_request should be updated to 1."
self.g2p_queue.number_of_attempts_request, 1, "number_of_attempts_request should be updated to 1."
)


def test_default_values_on_creation(self):
"""
Test that default values are correctly set when creating a new record without specifying them.
Expand All @@ -140,38 +137,35 @@ def test_default_values_on_creation(self):
)

self.assertEqual(
new_record.id_generation_request_status, "pending",
"Default ID Generation Request Status should be 'pending'."
new_record.id_generation_request_status,
"pending",
"Default ID Generation Request Status should be 'pending'.",
)
self.assertEqual(
new_record.id_generation_update_status, "not_applicable",
"Default ID Generation Update Status should be 'not_applicable'."
new_record.id_generation_update_status,
"not_applicable",
"Default ID Generation Update Status should be 'not_applicable'.",
)
self.assertEqual(
new_record.number_of_attempts_request, 0,
"Default number_of_attempts_request should be 0."
new_record.number_of_attempts_request, 0, "Default number_of_attempts_request should be 0."
)
self.assertEqual(
new_record.number_of_attempts_update, 0,
"Default number_of_attempts_update should be 0."
new_record.number_of_attempts_update, 0, "Default number_of_attempts_update should be 0."
)
self.assertFalse(
new_record.last_attempt_error_code_request,
"last_attempt_error_code_request should be empty by default."
"last_attempt_error_code_request should be empty by default.",
)
self.assertFalse(
new_record.last_attempt_error_code_update,
"last_attempt_error_code_update should be empty by default."
"last_attempt_error_code_update should be empty by default.",
)
self.assertFalse(
new_record.last_attempt_datetime_request,
"last_attempt_datetime_request should be empty by default."
"last_attempt_datetime_request should be empty by default.",
)
self.assertFalse(
new_record.last_attempt_datetime_update,
"last_attempt_datetime_update should be empty by default."
)
self.assertTrue(
new_record.queued_datetime,
"queued_datetime should be set by default."
"last_attempt_datetime_update should be empty by default.",
)
self.assertTrue(new_record.queued_datetime, "queued_datetime should be set by default.")

0 comments on commit fe92d7d

Please sign in to comment.