codacy review

This commit is contained in:
tundebabzy 2018-03-02 12:27:12 +01:00
parent 9e863b9572
commit e13570f343
14 changed files with 52 additions and 83 deletions

View File

@ -1,8 +1,2 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Subscriber', {
refresh: function(frm) {
}
});

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class Subscriber(Document):

View File

@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
import frappe
import unittest
class TestSubscriber(unittest.TestCase):

View File

@ -1,8 +1,2 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Subscription Invoice', {
refresh: function(frm) {
}
});

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class SubscriptionInvoice(Document):

View File

@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
import frappe
import unittest
class TestSubscriptionInvoice(unittest.TestCase):

View File

@ -1,8 +1,2 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Subscription Plan', {
refresh: function(frm) {
}
});

View File

@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
import frappe
import unittest
class TestSubscriptionPlan(unittest.TestCase):

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class SubscriptionPlanDetail(Document):

View File

@ -1,8 +1,2 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Subscription Settings', {
refresh: function(frm) {
}
});

View File

@ -3,7 +3,6 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class SubscriptionSettings(Document):

View File

@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
import frappe
import unittest
class TestSubscriptionSettings(unittest.TestCase):

View File

@ -29,9 +29,8 @@ class Subscriptions(Document):
def set_current_invoice_start(self, date=None):
"""
This sets the date of the beginning of the current billing period.
If the `date` parameter is not given , it will be automatically set as today's
This sets the date of the beginning of the current billing period.
If the `date` parameter is not given , it will be automatically set as today's
date.
"""
if self.trial_period_start and self.is_trialling():
@ -49,7 +48,7 @@ class Subscriptions(Document):
trial period.
If is not in a trial period, it will be `x` days from the beginning of the
current billing period where `x` is the billing interval from the
current billing period where `x` is the billing interval from the
`Subscription Plan` in the `Subscription`.
"""
if self.is_trialling():
@ -63,7 +62,7 @@ class Subscriptions(Document):
def get_billing_cycle(self):
"""
Returns a dict containing billing cycle information deduced from the
Returns a dict containing billing cycle information deduced from the
`Subscription Plan` in the `Subscription`.
"""
return self.get_billing_cycle_data()
@ -125,7 +124,7 @@ class Subscriptions(Document):
"""
Sets the `Subscription` `status` based on the preference set in `Subscription Settings`.
Used when the `Subscription` needs to decide what to do after the current generated
Used when the `Subscription` needs to decide what to do after the current generated
invoice is past it's due date and grace period.
"""
subscription_settings = frappe.get_single('Subscription Settings')
@ -262,7 +261,7 @@ class Subscriptions(Document):
# Due date
invoice.append(
'payment_schedule',
'payment_schedule',
{
'due_date': add_days(self.current_invoice_end, cint(self.days_until_due)),
'invoice_portion': 100
@ -276,8 +275,7 @@ class Subscriptions(Document):
if self.additional_discount_amount:
invoice.additional_discount_amount = self.additional_discount_amount
if (self.additional_discount_percentage or self.additional_discount_amount) \
and not self.apply_additional_discount:
if not self.apply_additional_discount and (self.additional_discount_percentage or self.additional_discount_amount):
self.apply_additional_discount = 'Grand Total'
invoice.save()
@ -331,7 +329,7 @@ class Subscriptions(Document):
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:
1. Generate a new invoice
@ -359,8 +357,8 @@ class Subscriptions(Document):
def process_for_past_due_date(self):
"""
Called by `process` if the status of the `Subscription` is 'Past Due Date'.
Called by `process` if the status of the `Subscription` is 'Past Due Date'.
The possible outcomes of this method are:
1. Change the `Subscription` status to 'Active'
2. Change the `Subscription` status to 'Canceled'

View File

@ -10,45 +10,48 @@ from erpnext.accounts.doctype.subscriptions.subscriptions import get_prorata_fac
from frappe.utils.data import nowdate, add_days, add_to_date, add_months, date_diff
def create_plan():
if not frappe.db.exists('Subscription Plan', '_Test Plan Name'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name'
plan.item = '_Test Non Stock Item'
plan.cost = 900
plan.billing_interval = 'Month'
plan.billing_interval_count = 1
plan.insert()
if not frappe.db.exists('Subscription Plan', '_Test Plan Name 2'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name 2'
plan.item = '_Test Non Stock Item'
plan.cost = 1999
plan.billing_interval = 'Month'
plan.billing_interval_count = 1
plan.insert()
if not frappe.db.exists('Subscription Plan', '_Test Plan Name 3'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name 3'
plan.item = '_Test Non Stock Item'
plan.cost = 1999
plan.billing_interval = 'Day'
plan.billing_interval_count = 14
plan.insert()
def create_subscriber():
if not frappe.db.exists('Subscriber', '_Test Customer'):
subscriber = frappe.new_doc('Subscriber')
subscriber.subscriber_name = '_Test Customer'
subscriber.customer = '_Test Customer'
subscriber.insert()
class TestSubscriptions(unittest.TestCase):
def create_plan(self):
if not frappe.db.exists('Subscription Plan', '_Test Plan Name'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name'
plan.item = '_Test Non Stock Item'
plan.cost = 900
plan.billing_interval = 'Month'
plan.billing_interval_count = 1
plan.insert()
if not frappe.db.exists('Subscription Plan', '_Test Plan Name 2'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name 2'
plan.item = '_Test Non Stock Item'
plan.cost = 1999
plan.billing_interval = 'Month'
plan.billing_interval_count = 1
plan.insert()
if not frappe.db.exists('Subscription Plan', '_Test Plan Name 3'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Name 3'
plan.item = '_Test Non Stock Item'
plan.cost = 1999
plan.billing_interval = 'Day'
plan.billing_interval_count = 14
plan.insert()
def create_subscriber(self):
if not frappe.db.exists('Subscriber', '_Test Customer'):
subscriber = frappe.new_doc('Subscriber')
subscriber.subscriber_name = '_Test Customer'
subscriber.customer = '_Test Customer'
subscriber.insert()
def setUp(self):
self.create_plan()
self.create_subscriber()
create_plan()
create_subscriber()
def test_create_subscription_with_trial_with_correct_period(self):
subscription = frappe.new_doc('Subscriptions')
@ -161,7 +164,7 @@ class TestSubscriptions(unittest.TestCase):
self.assertEqual(subscription.status, 'Past Due Date')
subscription.process()
subscription.process()
# This should change status to Canceled since grace period is 0
self.assertEqual(subscription.status, 'Canceled')
@ -245,7 +248,7 @@ class TestSubscriptions(unittest.TestCase):
self.assertEqual(subscription.current_invoice_start, nowdate())
self.assertEqual(subscription.current_invoice_end, add_to_date(nowdate(), months=1, days=-1))
self.assertEqual(len(subscription.invoices), 0)
subscription.process() # no changes expected still
self.assertEqual(subscription.status, 'Active')
self.assertEqual(subscription.current_invoice_start, nowdate())
@ -358,7 +361,7 @@ class TestSubscriptions(unittest.TestCase):
self.assertEqual(subscription.status, 'Past Due Date')
self.assertEqual(len(subscription.invoices), invoices)
subscription.cancel_subscription()
subscription.cancel_subscription()
self.assertEqual(subscription.status, 'Canceled')
self.assertEqual(len(subscription.invoices), invoices)