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

OM-231 Updated payment logic for unassigned voucher, added due date check #28

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
15 changes: 13 additions & 2 deletions msystems/views/mpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from urllib.parse import urljoin, quote_plus
from zeep.exceptions import SignatureVerificationFailed

from core import datetime
from invoice.apps import InvoiceConfig
from invoice.models import Bill, BillPayment
from msystems.apps import MsystemsConfig
Expand Down Expand Up @@ -67,6 +68,12 @@ def _check_amount_due(bill_item, amount_due):
raise Fault(faultcode='InvalidParameter',
faultstring=f'Amount "{amount_due}" does not match the order line {bill_item.code}')

def _check_due_date(bill):
now = datetime.datetime.now()
if not now < bill.date_due:
raise Fault(faultcode='InvalidParameter',
faultstring=f'Order {bill.code} has expired on {bill.date_due}')


def _get_voucher(bill_item):
voucher = WorkerVoucher.objects.filter(id=bill_item.line_id).first()
Expand Down Expand Up @@ -167,12 +174,16 @@ def ConfirmOrderPayment(ctx, confirmation: PaymentConfirmation) -> None:
_check_service_id(confirmation.ServiceID)
bill = _get_order(confirmation.OrderKey)
_check_amount_due(bill, decimal.Decimal(confirmation.TotalAmount))
_check_due_date(bill)

with transaction.atomic():
for bill_item in bill.line_items_bill.filter(is_deleted=False):
voucher = _get_voucher(bill_item)
if voucher.status != WorkerVoucher.Status.ASSIGNED:
voucher.status = WorkerVoucher.Status.ASSIGNED
if voucher.status == WorkerVoucher.Status.AWAITING_PAYMENT:
if voucher.insuree is not None:
voucher.status = WorkerVoucher.Status.ASSIGNED
else:
voucher.status = WorkerVoucher.Status.UNASSIGNED
voucher.save(username=voucher.user_updated.username)

if bill.status != Bill.Status.PAID:
Expand Down
Loading