Skip to content

Commit

Permalink
Merge pull request #123 from mkumar-02/G2P-907
Browse files Browse the repository at this point in the history
G2P-907 Changed client message to sticky for async operations
  • Loading branch information
shibu-narayanan authored Oct 16, 2023
2 parents b7d0631 + cafad1a commit 07b1172
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 23 deletions.
4 changes: 2 additions & 2 deletions g2p_entitlement_voucher/models/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _compute_show_voucher_buttons(self):
rec.show_print_voucher_button = True

def generate_vouchers_action(self):
err, message, vouchers = self.program_id.get_manager(
err, message, sticky, vouchers = self.program_id.get_manager(
constants.MANAGER_ENTITLEMENT
).generate_vouchers(self)
return {
Expand All @@ -50,7 +50,7 @@ def generate_vouchers_action(self):
"params": {
"title": _("Voucher"),
"message": message,
"sticky": True,
"sticky": sticky,
"type": "success",
"next": {
"type": "ir.actions.act_window_close",
Expand Down
14 changes: 10 additions & 4 deletions g2p_entitlement_voucher/models/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def approve_entitlements(self, entitlements):
)

if self.auto_generate_voucher_on_approval:
err, message, vouchers = self.generate_vouchers(entitlements)
err, message, sticky, vouchers = self.generate_vouchers(entitlements)

return res

def generate_vouchers(self, entitlements=None):
"""Generate Voucher.
:param entitlements: A recordset of entitlements
:return: err, message, vouchers recordset
:return: err, message, sticky, vouchers recordset
"""
if not entitlements:
entitlements = self.env["g2p.entitlement"].search(
Expand All @@ -91,6 +91,7 @@ def generate_vouchers(self, entitlements=None):
)
if entitlements_count < self.MIN_ROW_JOB_QUEUE:
err_count = 0
sticky = False
return_list = None
for cycle_entitlements in cycle_entitlements_list:
cycle = cycle_entitlements[0].cycle_id
Expand All @@ -112,15 +113,20 @@ def generate_vouchers(self, entitlements=None):
)
else:
message = _(f"{entitlements_count} Vouchers Generated.")
return err_count, message, return_list
return err_count, message, sticky, return_list
else:
for cycle_entitlements in cycle_entitlements_list:
cycle = cycle_entitlements[0].cycle_id
cycle_entitlements_count = len(cycle_entitlements)
self._generate_vouchers_async(
cycle, cycle_entitlements, cycle_entitlements_count
)
return -1, _(f"Started Voucher generation for {entitlements_count}."), None
return (
-1,
_(f"Started Voucher generation for {entitlements_count}."),
True,
None,
)

def _generate_vouchers(self, entitlements):
# TODO: Handle errors
Expand Down
2 changes: 1 addition & 1 deletion g2p_program_assessment/models/program_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def reject_application_assessment(self):
"params": {
"title": _("Reject"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
2 changes: 1 addition & 1 deletion g2p_program_assessment/wizard/create_entitlement_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def create_entitlement(self):
"params": {
"title": _("Entitlement"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
6 changes: 3 additions & 3 deletions g2p_programs/models/accounting/fund_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def post_fund(self):
"params": {
"title": _("Program Fund"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
},
}
Expand All @@ -96,7 +96,7 @@ def cancel_fund(self):
"params": {
"title": _("Program Fund"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
},
}
Expand All @@ -114,7 +114,7 @@ def reset_draft(self):
"params": {
"title": _("Program Fund"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind, # types: success,warning,danger,info
},
}
Expand Down
2 changes: 1 addition & 1 deletion g2p_programs/models/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def approve_entitlement(self):
"params": {
"title": _("Entitlement"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
7 changes: 5 additions & 2 deletions g2p_programs/models/managers/cycle_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def approve_cycle(self, cycle, auto_approve=False, entitlement_manager=None):
"params": {
"title": _("Cycle"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down Expand Up @@ -457,22 +457,25 @@ def add_beneficiaries(self, cycle, beneficiaries, state="draft"):
if len(beneficiaries) == 0:
message = _("No beneficiaries to import.")
kind = "warning"
sticky = False
elif len(beneficiaries) < self.MIN_ROW_JOB_QUEUE:
self._add_beneficiaries(cycle, beneficiaries, state, do_count=True)
message = _("%s beneficiaries imported.", len(beneficiaries))
kind = "success"
sticky = False
else:
self._add_beneficiaries_async(cycle, beneficiaries, state)
message = _("Import of %s beneficiaries started.", len(beneficiaries))
kind = "warning"
sticky = True

return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Enrollment"),
"message": message,
"sticky": True,
"sticky": sticky,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
2 changes: 1 addition & 1 deletion g2p_programs/models/managers/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def validate_entitlements(self, cycle):
"params": {
"title": _("Entitlement"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
6 changes: 5 additions & 1 deletion g2p_programs/models/managers/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,28 @@ def prepare_payments(self, cycle, entitlements=None):
if payments:
kind = "success"
message = _("%s new payments was issued.", len(payments))
sticky = False
else:
kind = "danger"
message = _("There are no new payments issued!")
sticky = False
else:
self._prepare_payments_async(cycle, entitlements, entitlements_count)
kind = "success"
message = _("Preparing Payments Asynchronously.")
sticky = True
else:
kind = "danger"
message = _("All entitlements selected are not approved!")
sticky = False

return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Payment"),
"message": message,
"sticky": True,
"sticky": sticky,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
4 changes: 3 additions & 1 deletion g2p_programs/models/managers/program_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,19 @@ def enroll_eligible_registrants(self, state=None):
count = self._enroll_eligible_registrants(state, do_count=True)
message = _("%s Beneficiaries enrolled.", count)
kind = "success"
sticky = False
else:
self._enroll_eligible_registrants_async(state, members_count)
message = _("Eligibility check of %s beneficiaries started.", members_count)
kind = "warning"
sticky = True
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Enrollment"),
"message": message,
"sticky": True,
"sticky": sticky,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
4 changes: 2 additions & 2 deletions g2p_programs/models/program_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def enroll_eligible_registrants(self):
"params": {
"title": _("Enrollment"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand All @@ -226,7 +226,7 @@ def enroll_eligible_registrants(self):
"params": {
"title": _("Enrollment"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down
8 changes: 4 additions & 4 deletions g2p_programs/models/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def create_new_cycle(self):
"params": {
"title": _("Cycle"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand All @@ -358,7 +358,7 @@ def create_new_cycle(self):
"params": {
"title": _("Cycle"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down Expand Up @@ -417,7 +417,7 @@ def end_program(self):
"params": {
"title": _("Program"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand All @@ -444,7 +444,7 @@ def reactivate_program(self):
"params": {
"title": _("Project"),
"message": message,
"sticky": True,
"sticky": False,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
Expand Down

0 comments on commit 07b1172

Please sign in to comment.