mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
fix: Prorata factor fixes in subscription (#24638)
* fix: Prorata factor fixes in subscription * fix: Test Case
This commit is contained in:
@@ -298,7 +298,8 @@ class Subscription(Document):
|
|||||||
Returns the `Item`s linked to `Subscription Plan`
|
Returns the `Item`s linked to `Subscription Plan`
|
||||||
"""
|
"""
|
||||||
if prorate:
|
if prorate:
|
||||||
prorate_factor = get_prorata_factor(self.current_invoice_end, self.current_invoice_start)
|
prorate_factor = get_prorata_factor(self.current_invoice_end, self.current_invoice_start,
|
||||||
|
self.generate_invoice_at_period_start)
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
customer = self.customer
|
customer = self.customer
|
||||||
@@ -468,11 +469,13 @@ class Subscription(Document):
|
|||||||
if invoice:
|
if invoice:
|
||||||
return invoice.precision('grand_total')
|
return invoice.precision('grand_total')
|
||||||
|
|
||||||
|
def get_prorata_factor(period_end, period_start, is_prepaid):
|
||||||
def get_prorata_factor(period_end, period_start):
|
if is_prepaid:
|
||||||
diff = flt(date_diff(nowdate(), period_start) + 1)
|
prorate_factor = 1
|
||||||
plan_days = flt(date_diff(period_end, period_start) + 1)
|
else:
|
||||||
prorate_factor = diff / plan_days
|
diff = flt(date_diff(nowdate(), period_start) + 1)
|
||||||
|
plan_days = flt(date_diff(period_end, period_start) + 1)
|
||||||
|
prorate_factor = diff / plan_days
|
||||||
|
|
||||||
return prorate_factor
|
return prorate_factor
|
||||||
|
|
||||||
|
|||||||
@@ -291,7 +291,8 @@ class TestSubscription(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
flt(
|
flt(
|
||||||
get_prorata_factor(subscription.current_invoice_end, subscription.current_invoice_start),
|
get_prorata_factor(subscription.current_invoice_end, subscription.current_invoice_start,
|
||||||
|
subscription.generate_invoice_at_period_start),
|
||||||
2),
|
2),
|
||||||
flt(prorate_factor, 2)
|
flt(prorate_factor, 2)
|
||||||
)
|
)
|
||||||
@@ -528,9 +529,7 @@ class TestSubscription(unittest.TestCase):
|
|||||||
current_inv = subscription.get_current_invoice()
|
current_inv = subscription.get_current_invoice()
|
||||||
self.assertEqual(current_inv.status, "Unpaid")
|
self.assertEqual(current_inv.status, "Unpaid")
|
||||||
|
|
||||||
diff = flt(date_diff(nowdate(), subscription.current_invoice_start) + 1)
|
prorate_factor = 1
|
||||||
plan_days = flt(date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1)
|
|
||||||
prorate_factor = flt(diff / plan_days)
|
|
||||||
|
|
||||||
self.assertEqual(flt(current_inv.grand_total, 2), flt(prorate_factor * 900, 2))
|
self.assertEqual(flt(current_inv.grand_total, 2), flt(prorate_factor * 900, 2))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user