Skip to content

Commit

Permalink
squashed commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayushmina-20 committed May 4, 2022
1 parent cd0cc44 commit 28eb8a8
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 50 deletions.
1 change: 1 addition & 0 deletions odk-connector/models/odk_submissions_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def create_registration_from_submission(self, data, extra_data=None):
].create_registration_from_odk(data)
return registration
except BaseException as e:
print(e)
print("Failed in creating registration!")
return None

Expand Down
1 change: 1 addition & 0 deletions openg2p/models/beneficiary_to_batch_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def task_create_batch(self, batch_name, beneficiary_ids):
"date_end": datetime.now(),
"currency_id": bank_id[0].currency_id.id,
"payment_mode": bank_id[0].payment_mode,
"payment_address": b.payment_address,
}
)
m.generate_uuid()
Expand Down
5 changes: 3 additions & 2 deletions openg2p/models/openg2p_beneficiary.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def _default_image(self):
)

odk_batch_id = fields.Char(default=lambda *args: uuid.uuid4().hex)
payment_address = fields.Char(string="Payment Address", required=False)

def api_json(self):
return {
Expand Down Expand Up @@ -466,7 +467,7 @@ def _compute_org_fields(self):
[
"&",
("beneficiary_id", "=", rec.id),
("field_name", "=", "grand_total_le"),
("field_name", "=", "grand_total"),
]
)
try:
Expand Down Expand Up @@ -731,7 +732,7 @@ def _compute_email_formatted(self):
for beneficiary in self:
if beneficiary.email:
beneficiary.email_formatted = tools.formataddr(
(beneficiary.name or u"False", beneficiary.email or u"False")
(beneficiary.name or "False", beneficiary.email or "False")
)
else:
beneficiary.email_formatted = ""
Expand Down
2 changes: 1 addition & 1 deletion openg2p/services/matching_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def match(self, query):
for ID, number in query.get_identities()
)
matches = (
self.with_context(active_test=False)
query.with_context(active_test=False)
.env["openg2p.beneficiary.id_number"]
.search(domain)
)
Expand Down
5 changes: 3 additions & 2 deletions openg2p/views/openg2p_beneficiary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@
<field name="ssn"/>
<field name="passport_id"/>
</group>

<group string="Social" name="social" priority="2">
<field name="marital"/>
<!-- <field name="title" options='{"no_open": True}'/>-->
<!-- <field name="gender"/>-->
<!-- <field name="marital"/>-->
<!-- <field name="emergency_contact"/>-->
<!-- <field name="emergency_phone"/>-->
<field name="lang"/>
Expand All @@ -190,7 +191,7 @@
<field name="create_date" widget="date" string="Created On"/>
</group>
<group name="internal_notes_right">

<field name="payment_address" string="Payment Address"/>
</group>
</group>
<field name="comment" placeholder="Internal note..."/>
Expand Down
16 changes: 6 additions & 10 deletions openg2p_disbursement/models/openg2p_disbursement_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,12 @@ def _compute_can_generate(self):
@api.multi
def _compute_can_cancel(self):
self.ensure_one()
self.can_cancel = (
self.state
in (
"generating",
"draft",
"confirm",
"approved",
)
and not isinstance(self.id, models.NewId)
)
self.can_cancel = self.state in (
"generating",
"draft",
"confirm",
"approved",
) and not isinstance(self.id, models.NewId)

@api.multi
def _compute_can_confirm(self):
Expand Down
2 changes: 1 addition & 1 deletion openg2p_disbursement/models/openg2p_disbursement_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Openg2pDisbursementRule(models.Model):
default="1.0",
help="It is used in computation for percentage and fixed amount. "
"For e.g. A rule for Meal Voucher having fixed amount of "
u"1€ per worked day can have its quantity defined in expression "
"1€ per worked day can have its quantity defined in expression "
"like days.WORK100.number_of_days.",
required=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class DisbursementMain(models.Model):
required=False,
default="",
)
payment_address = fields.Char(string="Payment Address", required=False)

def generate_uuid(self):
for rec in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<!-- <field name="state" invisible="1"/> -->
<field name="amount"/>
<field name="currency_id"/>
<field name="payment_address"/>

</group>
<group name="secondary">
Expand Down
1 change: 1 addition & 0 deletions openg2p_registration/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from . import openg2p_registration_org_map
from . import openg2p_registration_api
from . import openg2p_deduplication
from . import openg2p_demographic_authentication
175 changes: 175 additions & 0 deletions openg2p_registration/models/openg2p_demographic_authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import requests
import json
import logging
from odoo import models

_logger = logging.getLogger(__name__)

UN_SUCCESS_WITH_ERRORS = "Unsuccessful with Errors"
SUCCESS_WITH_ERRORS = "Successful with Errors"
SUCCESS = "Successful"


class Openg2pDemographicAuthentication(models.Model):
_inherit = "openg2p.registration"

def demo_auth(self, data):
import os

DEMO_AUTHENTICATE_URL = os.getenv(
"DEMO_AUTHENTICATE_URL",
"http://openg2p-mosip-auth-mediator.openg2p-mosip/demoAuth",
)
response = requests.post(DEMO_AUTHENTICATE_URL, json=data)
_logger.info("Demo Auth Response: " + str(response.content))
return json.loads(response.content)

def demo_auth_merge(self, data):
auth_res = self.demo_auth(data)
should_merge = False
should_create_beneficiary = False
stage_id = 0
if auth_res["authIdStatus"] == SUCCESS:
stage_id = 6
should_merge = self.post_auth_find_duplicate_beneficiary(
auth_res["authId"], auth_res["authIdType"]
)
if not should_merge:
should_create_beneficiary = True
elif auth_res["authIdStatus"] == SUCCESS_WITH_ERRORS:
stage_id = 2
elif auth_res["authIdStatus"] == UN_SUCCESS_WITH_ERRORS:
stage_id = 2
return {
"stage_id": stage_id,
"should_merge": should_merge,
"should_create_beneficiary": should_create_beneficiary,
"auth_id": auth_res["authId"],
"auth_id_type": auth_res["authIdType"],
"auth_id_status": auth_res["authIdStatus"],
"auth_id_message": auth_res["authIdMessage"],
}

def post_auth_create_id(self, response):
return self.env["openg2p.registration.identity"].create(
{
"name": response["auth_id"],
"type": response["auth_id_type"],
"status": response["auth_id_status"],
"message": response["auth_id_message"],
"registration_id": self.id,
}
)
res = self.env["openg2p.registration.identity"].search(
[("registration_id", "=", self.id)]
)
if res:
self.write({"identities": res.ids})

def post_auth_find_duplicate_beneficiary(self, auth_id, auth_id_type):
type_code_id = (
self.env["openg2p.beneficiary.id_category"]
.search([("code", "=", auth_id_type)], limit=1)
.id
)
length = len(
self.env["openg2p.beneficiary.id_number"].search(
[("name", "=", auth_id), ("category_id", "=", type_code_id)]
)
)
_logger.info(f"auth_id : {auth_id}. Post Auth. Size of duplicates: {length}")
return length > 0

def post_auth_merge(self, response):
auth_id = response["auth_id"]
auth_id_type = response["auth_id_type"]

type_code_id = (
self.env["openg2p.beneficiary.id_category"]
.search([("code", "=", auth_id_type)], limit=1)
.id
)
auth_id_object = self.env["openg2p.beneficiary.id_number"].search(
[("name", "=", auth_id), ("category_id", "=", type_code_id)]
)
existing_beneficiary = auth_id_object.beneficiary_id
_logger.info(f"auth_id: {auth_id}. Entered Post Auth Merge.")
# Fields to be merged
overwrite_data = {
"firstname": self.firstname,
"lastname": self.lastname,
"location_id": self.location_id.id,
"street": self.street,
"street2": self.street2,
"city": self.city,
"state_id": self.state_id.id,
"zip": self.zip,
"country_id": self.country_id.id,
"phone": self.phone,
"mobile": self.mobile,
"email": self.email,
"lang": self.lang,
"image": self.image,
"marital": self.marital,
"bank_account_id": self.bank_account_id.id,
"emergency_contact": self.emergency_contact,
"emergency_phone": self.emergency_phone,
}
program_ids = self.program_ids.ids
# Removing None fields
cleaned_overwrite_data = self.del_none(overwrite_data)

# Deriving existing fields to create new beneficiary
existing_data = {
"firstname": existing_beneficiary.firstname,
"lastname": existing_beneficiary.lastname,
"othernames": existing_beneficiary.othernames,
"location_id": existing_beneficiary.location_id.id,
"street": existing_beneficiary.street,
"street2": existing_beneficiary.street2,
"city": existing_beneficiary.city,
"state_id": existing_beneficiary.state_id.id,
"zip": existing_beneficiary.zip,
"country_id": existing_beneficiary.country_id.id,
"phone": existing_beneficiary.phone,
"mobile": existing_beneficiary.mobile,
"email": existing_beneficiary.email,
"title": existing_beneficiary.title.id,
"lang": existing_beneficiary.lang,
"gender": existing_beneficiary.gender,
"birthday": existing_beneficiary.birthday,
"image": existing_beneficiary.image,
"marital": existing_beneficiary.marital,
"bank_account_id": existing_beneficiary.bank_account_id.id,
"emergency_contact": existing_beneficiary.emergency_contact,
"emergency_phone": existing_beneficiary.emergency_phone,
"program_ids": [
(4, program) for program in existing_beneficiary.program_ids.ids
],
}

cleaned_existing_data = self.del_none(existing_data)

# Merging specfic fields to beneficiary
existing_beneficiary.write(cleaned_overwrite_data)

# Creating new beneficiary whose active=False
new_beneficiary = self.env["openg2p.beneficiary"].create(cleaned_existing_data)
# Create new registration with existing data
self.write({"beneficiary_id": existing_beneficiary.id})

# Storing merged id's in fields
existing_beneficiary.write(
{"merged_beneficiary_ids": [(4, new_beneficiary.id)]}
)
existing_beneficiary.write(
{"program_ids": [(4, program) for program in program_ids]}
)

# Setting active false
new_beneficiary.active = False

# self.clear_beneficiaries()

# Archiving the current Registration
# self.archive_registration()
Loading

0 comments on commit 28eb8a8

Please sign in to comment.