Skip to content

Commit

Permalink
Transaction comments and user log for limited services
Browse files Browse the repository at this point in the history
Added transactino comments and userlog enteries for maximum services.
Currently if basic transaction or custominvoice limits are reached
nothing happens. If main service gets paid, child service gets paid
to maximum limit.

Signed-off-by: Erkki Hietaranta <[email protected]>
  • Loading branch information
sbeach92 committed Feb 24, 2024
1 parent 5e16697 commit 8ca8518
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions utils/businesslogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,12 @@ def _check_transaction_pays_custominvoice(transaction):
)
if inlimit == True:
BusinessLogic._service_paid_by_transaction(subscription, transaction, invoice.days)
transaction.comment = transaction.comment + f" by {invoice}"
transaction.save()
else:
subscription.user.log(
f"Payment of {invoice} would extend {subscription.service} paid to date over maximum by {inlimit} days. Transaction is not used"
)
transaction.comment = (
f"Service {subscription.service} paid untill date would get over maximum limit by {inlimit} days. Transaction is not used"
transaction.comment += (
f"Service {subscription.service} paid untill date would get over maximum limit by {inlimit} days. Transaction is not used\n"
)
transaction.save()
else:
Expand Down Expand Up @@ -376,8 +374,8 @@ def _updatesubscription(user, subscription, servicesubscriptions):
f"Payment would extend {subscription.service} paid to date over maximum by {inlimit} days. {transaction} is not used"
)
transaction.user = subscription.user
transaction.comment = (
f"Service {subscription.service} paid untill date would get over maximum limit by {inlimit} days. Transaction is not used"
transaction.comment += (
f"Service {subscription.service} paid untill date would get over maximum limit by {inlimit} days. Transaction is not used\n"
)
transaction.save()
else:
Expand Down Expand Up @@ -511,7 +509,29 @@ def _service_paid_by_transaction(servicesubscription, transaction, add_days):
logger.debug(f"Child prosess add days calculted by {added_days.days} - {servicesubscription.service.days_per_payment} + {paid_servicesubscription.service.days_per_payment} - {child_days} and gained {extra_days} days more")
#Calculate child subscription payment to happen at same time that latest parrent subsciption,
#useful with custominvoices that pays Parent subscription multiple times
BusinessLogic._service_paid_by_transaction(paid_servicesubscription, transaction, extra_days)
inlimit = BusinessLogic._service_maxdays_after_payment_inlimit(
paid_servicesubscription,
transaction,
extra_days,
)
if inlimit == True:
BusinessLogic._service_paid_by_transaction(
paid_servicesubscription,
transaction,
extra_days)
else:
paid_servicesubscription.user.log(
f"{servicesubscription.service} would pay {paid_servicesubscription.service}, but paid to date would get over maximum by {inlimit} days. Paying to maximum, benefit of {inlimit} days is lost"
)
transaction.user = paid_servicesubscription.user
transaction.comment += (
f"Service {paid_servicesubscription.service} paid to maximum. Benefit of {inlimit} days is lost\n"
)
transaction.save()
BusinessLogic._service_paid_by_transaction(
paid_servicesubscription,
transaction,
extra_days - inlimit)

BusinessLogic._check_servicesubscription_state(
paid_servicesubscription
Expand Down

0 comments on commit 8ca8518

Please sign in to comment.