Merge pull request #5115 from nabinhait/test_fix

[fix] Test cases
This commit is contained in:
Anand Doshi 2016-04-04 17:43:02 +05:30
commit a32b3ea3e8
6 changed files with 24 additions and 28 deletions

View File

@ -64,22 +64,22 @@ def make_depreciation_entry(asset_name, date=None):
asset.set_status() asset.set_status()
def get_depreciation_accounts(asset): def get_depreciation_accounts(asset):
accounts = frappe.get_all("Asset Category Account", fixed_asset_account = accumulated_depreciation_account = depreciation_expense_account = None
fields = ['fixed_asset_account', 'accumulated_depreciation_account',
'depreciation_expense_account'], accounts = frappe.db.get_value("Asset Category Account",
filters={'parent': asset.asset_category, 'company_name': asset.company}) filters={'parent': asset.asset_category, 'company_name': asset.company},
fieldname = ['fixed_asset_account', 'accumulated_depreciation_account',
if accounts: 'depreciation_expense_account'], as_dict=1)
accounts = accounts[0]
fixed_asset_account = accounts.fixed_asset_account
accumulated_depreciation_account = accounts.accumulated_depreciation_account
depreciation_expense_account = accounts.depreciation_expense_account
if accounts:
fixed_asset_account = accounts.fixed_asset_account
accumulated_depreciation_account = accounts.accumulated_depreciation_account
depreciation_expense_account = accounts.depreciation_expense_account
if not accumulated_depreciation_account or not depreciation_expense_account: if not accumulated_depreciation_account or not depreciation_expense_account:
accounts = frappe.db.get_value("Company", asset.company, accounts = frappe.db.get_value("Company", asset.company,
["accumulated_depreciation_account", "depreciation_expense_account"]) ["accumulated_depreciation_account", "depreciation_expense_account"])
if not accumulated_depreciation_account: if not accumulated_depreciation_account:
accumulated_depreciation_account = accounts[0] accumulated_depreciation_account = accounts[0]
if not depreciation_expense_account: if not depreciation_expense_account:

View File

@ -148,7 +148,7 @@ def create_asset():
if not frappe.db.exists("Item", "Macbook Pro"): if not frappe.db.exists("Item", "Macbook Pro"):
create_fixed_asset_item() create_fixed_asset_item()
asset = frappe.get_doc({ asset = frappe.get_doc({
"doctype": "Asset", "doctype": "Asset",
"asset_name": "Macbook Pro 1", "asset_name": "Macbook Pro 1",
@ -173,7 +173,7 @@ def create_asset_category():
asset_category.number_of_depreciations = 3 asset_category.number_of_depreciations = 3
asset_category.number_of_months_in_a_period = 3 asset_category.number_of_months_in_a_period = 3
asset_category.append("accounts", { asset_category.append("accounts", {
"company": "_Test Company", "company_name": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC", "fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC" "depreciation_expense_account": "_Test Depreciations - _TC"
@ -189,8 +189,9 @@ def create_fixed_asset_item():
"description": "Macbook Pro Retina Display", "description": "Macbook Pro Retina Display",
"item_group": "All Item Groups", "item_group": "All Item Groups",
"stock_uom": "Nos", "stock_uom": "Nos",
"is_stock_item": 0 "is_stock_item": 0,
}).insert() "is_fixed_asset": 1
}).insert()
except frappe.DuplicateEntryError: except frappe.DuplicateEntryError:
pass pass

View File

@ -5,10 +5,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
from frappe.utils import cint
from frappe.model.document import Document from frappe.model.document import Document
class AssetCategory(Document): class AssetCategory(Document):
def validate(self): def validate(self):
for field in ("number_of_depreciations", "number_of_months_in_a_period"): for field in ("number_of_depreciations", "number_of_months_in_a_period"):
if int(self.get(field))<1: if cint(self.get(field))<1:
frappe.throw(_("{0} must be greater than 0").format(self.meta.get_label(field))) frappe.throw(_("{0} must be greater than 0").format(self.meta.get_label(field)), frappe.MandatoryError)

View File

@ -16,7 +16,7 @@ class TestAssetCategory(unittest.TestCase):
asset_category.number_of_depreciations = 3 asset_category.number_of_depreciations = 3
asset_category.number_of_months_in_a_period = 3 asset_category.number_of_months_in_a_period = 3
asset_category.append("accounts", { asset_category.append("accounts", {
"company": "_Test Company", "company_name": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC", "fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC" "depreciation_expense_account": "_Test Depreciations - _TC"

View File

@ -43,8 +43,8 @@ def before_tests():
"company_abbr" :"WP", "company_abbr" :"WP",
"industry" :"Manufacturing", "industry" :"Manufacturing",
"country" :"United States", "country" :"United States",
"fy_start_date" :"2014-01-01", "fy_start_date" :"2011-01-01",
"fy_end_date" :"2014-12-31", "fy_end_date" :"2011-12-31",
"language" :"english", "language" :"english",
"company_tagline" :"Testing", "company_tagline" :"Testing",
"email" :"test@erpnext.com", "email" :"test@erpnext.com",

View File

@ -96,13 +96,6 @@ class TestShoppingCart(unittest.TestCase):
self.assertEquals(quotation.net_total, 20) self.assertEquals(quotation.net_total, 20)
self.assertEquals(len(quotation.get("items")), 1) self.assertEquals(len(quotation.get("items")), 1)
# remove second item
update_cart("_Test Item 2", 0)
quotation = self.test_get_cart_customer()
self.assertEquals(len(quotation.get("items")), 0)
self.assertEquals(quotation.net_total, 0)
def test_tax_rule(self): def test_tax_rule(self):
self.login_as_customer() self.login_as_customer()
quotation = self.create_quotation() quotation = self.create_quotation()
@ -197,6 +190,7 @@ class TestShoppingCart(unittest.TestCase):
def remove_all_items_from_cart(self): def remove_all_items_from_cart(self):
quotation = _get_cart_quotation() quotation = _get_cart_quotation()
quotation.flags.ignore_permissions=True
quotation.delete() quotation.delete()
def create_user_if_not_exists(self, email, first_name = None): def create_user_if_not_exists(self, email, first_name = None):