Skip to content

Commit

Permalink
OM-231 Updated payment logic for unassigned voucher, added due date c…
Browse files Browse the repository at this point in the history
…heck (#28)
  • Loading branch information
malinowskikam authored Jul 29, 2024
1 parent 6aa2eb9 commit bf21258
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit bf21258

Please sign in to comment.