codacy tinzz

This commit is contained in:
tundebabzy 2018-03-03 17:18:47 +01:00
parent fbdd5d30e9
commit 2379451b68
2 changed files with 12 additions and 10 deletions

View File

@ -305,7 +305,7 @@ class Subscriptions(Document):
)
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(
'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):
"""
Called by `process` if the status of the `Subscription` is 'Active'.
The possible outcomes of this method are:
1. Generate a new invoice
2. Change the `Subscription` status to 'Past Due Date'
@ -421,19 +421,20 @@ class Subscriptions(Document):
else:
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):
invoice = self.get_current_invoice()
if invoice:
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():
"""
Task to updates the status of all `Subscription` apart from those that are cancelled

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import unittest
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
@ -297,7 +298,7 @@ class TestSubscriptions(unittest.TestCase):
self.assertEqual(
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),
flt(prorate_factor, 2)
)