codacy tinzz
This commit is contained in:
parent
fbdd5d30e9
commit
2379451b68
@ -305,7 +305,7 @@ class Subscriptions(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
elif plan_items:
|
elif plan_items:
|
||||||
prorate_factor = self.get_prorata_factor(self.current_invoice_end, self.current_invoice_start)
|
prorate_factor = get_prorata_factor(self.current_invoice_end, self.current_invoice_start)
|
||||||
|
|
||||||
item_names = frappe.db.sql(
|
item_names = frappe.db.sql(
|
||||||
'select item as item_code, cost * %s as rate from `tabSubscription Plan` where name in %s',
|
'select item as item_code, cost * %s as rate from `tabSubscription Plan` where name in %s',
|
||||||
@ -331,7 +331,7 @@ class Subscriptions(Document):
|
|||||||
def process_for_active(self):
|
def process_for_active(self):
|
||||||
"""
|
"""
|
||||||
Called by `process` if the status of the `Subscription` is 'Active'.
|
Called by `process` if the status of the `Subscription` is 'Active'.
|
||||||
|
|
||||||
The possible outcomes of this method are:
|
The possible outcomes of this method are:
|
||||||
1. Generate a new invoice
|
1. Generate a new invoice
|
||||||
2. Change the `Subscription` status to 'Past Due Date'
|
2. Change the `Subscription` status to 'Past Due Date'
|
||||||
@ -421,19 +421,20 @@ class Subscriptions(Document):
|
|||||||
else:
|
else:
|
||||||
frappe.throw(_('You cannot restart a Subscription that is not cancelled.'))
|
frappe.throw(_('You cannot restart a Subscription that is not cancelled.'))
|
||||||
|
|
||||||
def get_prorata_factor(self, period_end, period_start):
|
|
||||||
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
|
|
||||||
|
|
||||||
def get_precision(self):
|
def get_precision(self):
|
||||||
invoice = self.get_current_invoice()
|
invoice = self.get_current_invoice()
|
||||||
if invoice:
|
if invoice:
|
||||||
return invoice.precision('grand_total')
|
return invoice.precision('grand_total')
|
||||||
|
|
||||||
|
|
||||||
|
def get_prorata_factor(period_end, period_start):
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def process_all():
|
def process_all():
|
||||||
"""
|
"""
|
||||||
Task to updates the status of all `Subscription` apart from those that are cancelled
|
Task to updates the status of all `Subscription` apart from those that are cancelled
|
||||||
|
@ -6,6 +6,7 @@ from __future__ import unicode_literals
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from erpnext.accounts.doctype.subscriptions.subscriptions import get_prorata_factor
|
||||||
from frappe.utils.data import nowdate, add_days, add_to_date, add_months, date_diff, flt
|
from frappe.utils.data import nowdate, add_days, add_to_date, add_months, date_diff, flt
|
||||||
|
|
||||||
|
|
||||||
@ -297,7 +298,7 @@ class TestSubscriptions(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
flt(
|
flt(
|
||||||
subscription.get_prorata_factor(subscription.current_invoice_end, subscription.current_invoice_start),
|
get_prorata_factor(subscription.current_invoice_end, subscription.current_invoice_start),
|
||||||
2),
|
2),
|
||||||
flt(prorate_factor, 2)
|
flt(prorate_factor, 2)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user