Skip to content

Commit

Permalink
Dynamic pricing for custom invoices
Browse files Browse the repository at this point in the history
Some users might found Dynamic pricing of payments missleading
as normal access fee can be paid with dynamic pricing, but
reorrucing custom invoice recalls flat rate.

This commit changes custom invoice logic so that it allows
dynamic pricing. Minimium payment is calculated from service
minimum payment * service payment times.

It can be disabled from settings.py or constance admin panel

Signed-off-by: Erkki Hietaranta <erkki.hietaranta@gmail.com>
  • Loading branch information
sbeach92 committed Feb 14, 2024
1 parent a1e9707 commit 30d4c59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drfx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DEFAULT_ACCOUNT_SERVICE = 2

CUSTOM_INVOICE_REFERENCE_BASE = 10000
CUSTOM_INVOICE_DYNAMIC_PRICING = True
SERVICE_INVOICE_REFERENCE_BASE = 20000

MEMBERSHIP_APPLICATION_NOTIFY_ADDRESS = "example@example.com"
Expand Down Expand Up @@ -386,4 +387,5 @@
# "ACCOUNT_IBAN": (ACCOUNT_IBAN, "IBAN of the association's bank account"),
# "ACCOUNT_BIC": (ACCOUNT_BIC, "BIC of the association's bank account"),
# "ACCOUNT_NAME": (ACCOUNT_NAME, "Name of the association's bank account"),
"CUSTOM_INVOICE_DYNAMIC_PRICING": (CUSTOM_INVOICE_DYNAMIC_PRICING, "Allow dynamic pricing when paying with custom invoice", bool)
}
5 changes: 5 additions & 0 deletions users/models/custom_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ def __str__(self):
"amount": self.amount,
"reference": self.reference_number,
}

# cost is used if not set
def cost_min(self):
cm = self.days / self.subscription.service.days_per_payment * self.subscription.service.cost_min
return cm
6 changes: 4 additions & 2 deletions utils/businesslogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def _check_transaction_pays_custominvoice(transaction):
)

for invoice in invoices:
if transaction.amount >= invoice.amount:
#if transaction.amount >= invoice.amount:
invoice_cost_min = invoice.cost_min()
if config.CUSTOM_INVOICE_DYNAMIC_PRICING and transaction.amount >= invoice_cost_min or transaction.amount >= invoice.amount:
subscription = ServiceSubscription.objects.get(
user=invoice.user, id=invoice.subscription.id
)
Expand Down Expand Up @@ -431,7 +433,7 @@ def _service_paid_by_transaction(servicesubscription, transaction, add_days):
else:
extra_days = timedelta(
#Calculate child subscription payment to happen same time that latest parrent subsciption,
#useful with custominvoices that pays subsription multiple times
#useful with custominvoices that pays Parent subscription multiple times
days = add_days - servicesubscription.service.days_per_payment + paid_servicesubscription.service.days_per_payment
)
paid_servicesubscription.paid_until = transaction.date + extra_days
Expand Down

0 comments on commit 30d4c59

Please sign in to comment.