Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] spp_change_request: improve UI #723

Open
wants to merge 2 commits into
base: 5-sl-compliance-criteria
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions spp_change_request/models/change_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ChangeRequestBase(models.Model):
"Registrant",
domain=[("is_registrant", "=", True)],
) #: Registrant who submitted the change request
registrant_id_visible = fields.Boolean("Registrant Visible", compute="_compute_registrant_id_visible")
registrant_id_domain = fields.Binary(
compute="_compute_registrant_id_domain",
readonly=True,
Expand All @@ -73,13 +74,19 @@ class ChangeRequestBase(models.Model):
"Applicant",
domain=[("is_registrant", "=", True), ("is_group", "=", False)],
)
applicant_id_required = fields.Boolean("Applicant Required", compute="_compute_applicant_id_required")
applicant_id_visible = fields.Boolean("Applicant Visible", compute="_compute_applicant_id_visible")
# Applicant who submitted the change request (In case the registrant is a group, the applicant is the individual)
applicant_id_domain = fields.Binary(
compute="_compute_applicant_id_domain",
readonly=True,
store=False,
)
applicant_phone = fields.Char("Applicant's Phone Number") #: Applicant's phone number
applicant_phone_required = fields.Boolean("Applicant's Phone Required", compute="_compute_applicant_phone_required")
applicant_information_visible = fields.Boolean(
"Applicant Information Visible", compute="_compute_applicant_information_visible"
)

request_type_ref_id = fields.Reference(string="Change Request Template", selection="_selection_request_type_ref_id")
validator_ids = fields.One2many(
Expand Down Expand Up @@ -148,11 +155,64 @@ class ChangeRequestBase(models.Model):
auto_join=True,
)

@api.model
def _registrant_id_not_visible_in_request_type(self):
return []

@api.depends("request_type")
def _compute_registrant_id_visible(self):
for rec in self:
rec.registrant_id_visible = (
bool(rec.request_type) and rec.request_type not in self._registrant_id_not_visible_in_request_type()
)

@api.model
def _applicant_id_not_required_in_request_type(self):
return []

@api.model
def _applicant_id_not_visible_in_request_type(self):
return []

@api.depends("request_type")
def _compute_applicant_id_required(self):
for rec in self:
rec.applicant_id_required = rec.request_type not in self._applicant_id_not_required_in_request_type()

@api.depends("request_type")
def _compute_applicant_id_visible(self):
for rec in self:
rec.applicant_id_visible = (
bool(rec.request_type) and rec.request_type not in self._applicant_id_not_visible_in_request_type()
)

@api.model
def _applicant_phone_not_required_in_request_type(self):
return []

@api.depends("request_type")
def _compute_applicant_phone_required(self):
for rec in self:
rec.applicant_phone_required = rec.request_type not in self._applicant_phone_not_required_in_request_type()

@api.model
def _applicant_information_not_visible_in_request_type(self):
return []

@api.depends("request_type")
def _compute_applicant_information_visible(self):
for rec in self:
rec.applicant_information_visible = (
bool(rec.request_type)
and rec.request_type not in self._applicant_information_not_visible_in_request_type()
)

@api.onchange("request_type")
def _onchange_request_type(self):
self._compute_request_type_target()
self.registrant_id = None

@api.depends("request_type")
def _compute_request_type_target(self):
for rec in self:
request_type_target = None
Expand Down Expand Up @@ -670,7 +730,7 @@ def open_request_detail(self):
for rec in self:
# Open Request Form
mode = "edit"
if self.env.user.id not in [self.assign_to_id.id, self.create_uid]:
if self.env.user.id not in [self.assign_to_id.id, self.create_uid.id]:
mode = "readonly"
return rec.open_change_request_form(target="current", mode=mode)

Expand All @@ -680,7 +740,7 @@ def _check_phone_exist(self):

:raise UserError: Exception raised when applicant_phone is not existing.
"""
if not self.applicant_phone:
if not self.applicant_phone and self.applicant_phone_required:
raise UserError(_("Phone No. is required."))

def create_request_detail_no_redirect(self):
Expand Down
30 changes: 22 additions & 8 deletions spp_change_request/views/change_request_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
string="Request Validation"
icon="fa-paper-plane"
class="btn-primary"
invisible="state != 'draft'"
invisible="state != 'draft' or not id"
groups="g2p_registry_base.group_g2p_admin,spp_change_request.group_spp_change_request_agent"
/>
<button
Expand Down Expand Up @@ -98,7 +98,7 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
string="Cancel Change Request"
icon="fa-times-circle"
class="btn-default"
invisible="state not in ['draft', 'pending', 'rejected', 'validated']"
invisible="state not in ['draft', 'pending', 'rejected', 'validated'] or not id"
groups="g2p_registry_base.group_g2p_admin,spp_change_request.group_spp_change_request_administrator,spp_change_request.group_spp_change_request_agent"
/>
<button
Expand Down Expand Up @@ -178,8 +178,16 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
</h2>
<field name="request_type_target" invisible="1" />
<field name="registrant_id_domain" invisible="1" />
<label for="registrant_id" string="Registrant:" />
<h2>
<field name="applicant_id_required" invisible="1" />
<field name="registrant_id_visible" invisible="1" />
<field name="applicant_id_visible" invisible="1" />
<field name="applicant_information_visible" invisible="1" />
<label
for="registrant_id"
string="Registrant:"
invisible="not registrant_id_visible"
/>
<h2 invisible="not registrant_id_visible">
<field
name="registrant_id"
options="{'no_create': True,'no_open':True}"
Expand All @@ -198,14 +206,14 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
style="margin-left: 10px;"
/> -->
</h2>
<label for="applicant_id" string="Applicant:" />
<h3>
<label for="applicant_id" string="Applicant:" invisible="not applicant_id_visible" />
<h3 invisible="not applicant_id_visible">
<field
name="applicant_id"
options="{'no_create': True,'no_open':True}"
readonly="state != 'draft' or request_type_ref_id"
domain="applicant_id_domain"
required="1"
required="applicant_id_required"
force_save="1"
class="oe_inline"
/>
Expand All @@ -231,7 +239,13 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
/>
</h3>
</div>
<group colspan="4" col="4" string="Applicant Information">
<group
colspan="4"
col="4"
string="Applicant Information"
name="applicant_information"
invisible="not applicant_information_visible"
>
<field
name="applicant_phone"
string="Phone No."
Expand Down
Loading