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

G2P-1499: Able to send payments without preparing payment batch #144

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
35 changes: 19 additions & 16 deletions g2p_payment_cash/models/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ class G2PPaymentManagerCash(models.Model):

# This will just mark all the payments as done when then cash is given out
def _send_payments(self, batches):
_logger.info("DEBUG! send_payments Manager: Payment via CASH")
for batch in batches:
batch.batch_has_started = True
for payment in batch.payment_ids:
payment.update(
{
"state": "reconciled",
"status": "paid",
"amount_paid": payment.amount_issued,
"payment_datetime": datetime.utcnow(),
}
)
batch.batch_has_completed = True

message = _("Payment files created successfully")
kind = "success"
if not batches:
message = _("No payment batches to process.")
kind = "danger" # Use a valid type like "danger" for an error message
else:
_logger.info("DEBUG! send_payments Manager: Payment via CASH")
for batch in batches:
batch.batch_has_started = True
for payment in batch.payment_ids:
payment.update(
{
"state": "reconciled",
"status": "paid",
"amount_paid": payment.amount_issued,
"payment_datetime": datetime.utcnow(),
}
)
batch.batch_has_completed = True
message = _("Payment files created successfully")
kind = "success"
return {
"type": "ir.actions.client",
"tag": "display_notification",
Expand Down
52 changes: 26 additions & 26 deletions g2p_programs/models/managers/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ def _prepare_payments_async(self, cycle, entitlements, entitlements_count):
)
main_job.delay()

def send_payments(self, batches):
# TODO: Return client action with proper message.
batches_count = len(batches)
if batches_count < self.MAX_BATCHES_FOR_SYNC_SEND:
return self._send_payments(batches)
else:
cycles, cycle_batches = self._group_batches_by_cycle(batches)
for batches in cycle_batches:
cycle = batches[0].cycle_id
self._send_payments_async(cycle, batches)
message = _("Sending Payments Asynchronously")
kind = "success"
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Payment"),
"message": message,
"sticky": True,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
},
},
}

def _send_payments(self, batches):
# Create a payment list (CSV)
# _logger.debug("DEBUG! send_payments Manager: DEFAULT")
Expand Down Expand Up @@ -299,32 +325,6 @@ def _send_payments(self, batches):
},
}

def send_payments(self, batches):
# TODO: Return client action with proper message.
batches_count = len(batches)
if batches_count < self.MAX_BATCHES_FOR_SYNC_SEND:
return self._send_payments(batches)
else:
cycles, cycle_batches = self._group_batches_by_cycle(batches)
for batches in cycle_batches:
cycle = batches[0].cycle_id
self._send_payments_async(cycle, batches)
message = _("Sending Payments Asynchronously")
kind = "success"
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Payment"),
"message": message,
"sticky": True,
"type": kind,
"next": {
"type": "ir.actions.act_window_close",
},
},
}

def _send_payments_async(self, cycle, batches):
_logger.debug("Send Payments asynchronously")
cycle.message_post(
Expand Down
Loading