Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from dibik96/17.0-develop
Browse files Browse the repository at this point in the history
G2P-2718: Enumerator and user mapping logic added in registration por…
  • Loading branch information
shibu-narayanan authored Aug 12, 2024
2 parents 001dd68 + 7c3db01 commit a21ef01
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 68 deletions.
25 changes: 0 additions & 25 deletions g2p_odk_user_mapping/views/registration_user_backend_view.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
<odoo>

<!-- Search View -->
<record id="res_partner_view_search_g2p_inherits" model="ir.ui.view">
<field name="name">res.partner.search.inherits</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.res_partner_view_search" />
<field name="arch" type="xml">
<filter name="supplier" position="attributes">
<attribute name="string">Registration Portal User</attribute>
</filter>
</field>
</record>

<record id="view_res_partner_form_inherit_registration" model="ir.ui.view">
<field name="name">res.partner.form.inherit.registration</field>
<field name="model">res.partner</field>
Expand All @@ -33,16 +20,4 @@
</xpath>
</field>
</record>

<!-- Action Name -->
<record id="account.res_partner_action_supplier" model="ir.actions.act_window">
<field name="name">Registration Portal User</field>
</record>

<menuitem
id="menu_account_supplier"
name="Registration Portal User"
action="account.res_partner_action_supplier"
sequence="5"
/>
</odoo>
18 changes: 9 additions & 9 deletions g2p_portal_base/views/menu_view.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<odoo>
<!-- Action Name -->
<record id="account.res_partner_action_supplier" model="ir.actions.act_window">
<field name="name">Service Provider</field>
</record>

<!-- Search View -->
<record id="res_partner_view_search_g2p_inherit" model="ir.ui.view">
<field name="name">res.partner.search.inherit</field>
<record id="res_partner_view_search_g2p_inherits" model="ir.ui.view">
<field name="name">res.partner.search.inherits</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.res_partner_view_search" />
<field name="arch" type="xml">
<filter name="supplier" position="attributes">
<attribute name="string">Service Provider</attribute>
<attribute name="string">Registration Portal User</attribute>
</filter>
</field>
</record>

<!-- Action Name -->
<record id="account.res_partner_action_supplier" model="ir.actions.act_window">
<field name="name">Registration Portal User</field>
</record>

<menuitem
id="menu_account_supplier"
name="Service Provider"
name="Registration Portal User"
action="account.res_partner_action_supplier"
groups="g2p_registry_base.group_g2p_admin"
sequence="5"
/>
</odoo>
78 changes: 49 additions & 29 deletions g2p_registration_portal/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@
class G2PregistrationBeneficiaryManagement(http.Controller):
@http.route("/registration/group", type="http", auth="user", website=True)
def group_list(self, **kw):
group = (
request.env["res.partner"]
.sudo()
.search(
[
("active", "=", True),
("is_registrant", "=", True),
("is_group", "=", True),
]
)
)
user = request.env.user

domain = [
("active", "=", True),
("is_registrant", "=", True),
("is_group", "=", True),
]

partner = user.partner_id

subdomain = [("user_id", "=", user.id)]

if partner and partner.odk_app_user:
subdomain = [
"|",
("enumerator_id.enumerator_user_id", "=", partner.odk_app_user.odk_user_id),
("user_id", "=", user.id),
]

domain += subdomain

group = request.env["res.partner"].sudo().search(domain)

return request.render("g2p_registration_portal.group_list", {"groups": group})

Expand Down Expand Up @@ -55,19 +66,19 @@ def group_create_submit(self, **kw):
beneficiary_id = request.env["res.partner"].sudo().browse(int(kw.get("group_id")))
else:
if head_name:
beneficiary_obj = (
request.env["res.partner"]
.sudo()
.create(
{
"name": head_name,
"is_registrant": True,
"is_group": True,
"birthdate": kw.get("dob"),
"gender": kw.get("gender"),
}
)
)
user = request.env.user

data = {
"name": head_name,
"is_registrant": True,
"is_group": True,
"birthdate": kw.get("dob"),
"gender": kw.get("gender"),
"user_id": user.id,
}

beneficiary_obj = request.env["res.partner"].sudo().create(data)

beneficiary_id = beneficiary_obj.id
beneficiary = request.env["res.partner"].sudo().browse(beneficiary_id)

Expand Down Expand Up @@ -118,6 +129,7 @@ def group_update(self, _id, **kw):
"individuals": beneficiary.group_membership_ids.mapped("individual"),
},
)

except Exception:
return request.render(
"g2p_registration_portal.error_template",
Expand Down Expand Up @@ -160,9 +172,9 @@ def group_submit(self, **kw):
{"error_message": "An error occurred. Please try again later."},
)

# Creating members
# Creating Group members
@http.route(
["/registration/individual/create/"],
["/registration/member/create/"],
type="http",
auth="user",
website=True,
Expand Down Expand Up @@ -213,6 +225,7 @@ def individual_create(self, **kw):
given_name = kw.get("given_name")
family_name = kw.get("family_name")
addl_name = kw.get("addl_name")
user = request.env.user

name = f"{given_name}, {addl_name} {family_name}"

Expand All @@ -225,6 +238,7 @@ def individual_create(self, **kw):
"gender": kw.get("gender"),
"is_registrant": True,
"is_group": False,
"user_id": user.id,
}

# TODO: Relationship logic need to build later
Expand Down Expand Up @@ -338,10 +352,12 @@ def update_member_submit(self, **kw):
_logger.error("Error occurred during member submit: %s", e)
return json.dumps({"error": "Failed to update member details"})

############### Controller for Individual Benificiary Creation ################
############### Controller for Individual Creation ################

@http.route("/registration/individual", type="http", auth="user", website=True)
def individual_list(self, **kw):
user = request.env.user

individual = (
request.env["res.partner"]
.sudo()
Expand All @@ -350,13 +366,14 @@ def individual_list(self, **kw):
("active", "=", True),
("is_registrant", "=", True),
("is_group", "=", False),
("user_id", "=", user.id),
]
)
)
return request.render("g2p_registration_portal.individual_list", {"individual": individual})

@http.route(
["/registration/individual/registrar/create/"],
["/registration/individual/create/"],
type="http",
auth="user",
website=True,
Expand All @@ -370,13 +387,15 @@ def individual_registrar_create(self, **kw):
)

@http.route(
["/registration/individual/beneficiary/create/submit"],
["/registration/individual/create/submit"],
type="http",
auth="user",
website=True,
csrf=False,
)
def individual_create_submit(self, **kw):
user = request.env.user

try:
name = ""
if kw.get("family_name"):
Expand All @@ -399,6 +418,7 @@ def individual_create_submit(self, **kw):
"birthdate": birthdate,
"gender": kw.get("gender"),
"email": kw.get("email"),
"user_id": user.id,
"is_registrant": True,
"is_group": False,
}
Expand Down
2 changes: 1 addition & 1 deletion g2p_registration_portal/static/src/js/member_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ $(document).on("click", "#member_submit", function () {
}

$.ajax({
url: "/registration/individual/create/",
url: "/registration/member/create/",
method: "POST",
data: {
group_id: group,
Expand Down
8 changes: 4 additions & 4 deletions g2p_registration_portal/views/individual_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="main-container">
<div class="container-adjuster">
<h5 class="all-title">Individual</h5>
<a t-attf-href="/registration/individual/registrar/create/" style="float:right;">
<a t-attf-href="/registration/individual/create/" style="float:right;">
<button type="button" class="btn btn-primary create-new"> Create New <span
class="mx-1"
/>
Expand Down Expand Up @@ -70,6 +70,7 @@
<th>Last name</th>
<th>Gender</th>
<th>Last update</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
Expand Down Expand Up @@ -423,7 +424,7 @@

<form
id="creategroupForm"
action="/registration/individual/beneficiary/create/submit"
action="/registration/individual/create/submit"
method="POST"
enctype="multipart/form-data"
>
Expand Down Expand Up @@ -566,8 +567,7 @@
Gender</span>
<span class="s_website_form_mark"> *</span>
</label>
<span class="s_website_form_mark">
*</span>

<div class="row">
<div class="col">
<select
Expand Down

0 comments on commit a21ef01

Please sign in to comment.