[tests] creation of asset and asset category

This commit is contained in:
Nabin Hait 2016-03-10 10:53:31 +05:30
parent 4fdb05228d
commit 4d668dbaa3
7 changed files with 101 additions and 10 deletions

View File

@ -35,7 +35,12 @@ def _make_test_records(verbose):
# related to Account Inventory Integration
["_Test Account Stock In Hand", "Current Assets", 0, None, None],
["_Test Account Fixed Assets", "Current Assets", 0, None, None],
# fixed asset depreciation
["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None],
["_Test Accumulated Depreciations", "Current Assets", 0, None, None],
["_Test Depreciations", "Expenses", 0, None, None],
["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None],
# Receivable / Payable Account
["_Test Receivable", "Current Assets", 0, "Receivable", None],

View File

@ -30,6 +30,9 @@ class Asset(Document):
if flt(self.expected_value_after_useful_life) >= flt(self.gross_purchase_amount):
frappe.throw(_("Expected Value After Useful Life must be less than Gross Purchase Amount"))
if not flt(self.gross_purchase_amount):
frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError)
if not self.current_value:
self.current_value = flt(self.gross_purchase_amount)
else:

View File

@ -6,7 +6,71 @@ from __future__ import unicode_literals
import frappe
import unittest
# test_records = frappe.get_test_records('Asset')
class TestAsset(unittest.TestCase):
pass
def setUp(self):
create_asset()
def test_fixed_asset_must_be_non_stock_item(self):
item = frappe.get_doc("Item", "Macbook Pro")
item.is_stock_item = 1
self.assertRaises(frappe.ValidationError, item.save)
def test_asset_purchase(self):
asset = create_asset()
self.assertEqual(asset.current_value, 100000)
def create_asset():
if not frappe.db.exists("Asset Category", "Computers"):
create_asset_category()
if not frappe.db.exists("Item", "Macbook Pro"):
create_fixed_asset_item()
asset = frappe.get_doc({
"doctype": "Asset",
"asset_name": "Macbook Pro 1",
"asset_category": "Computers",
"item_code": "Macbook Pro",
"purchase_date": "2015-01-01",
"next_depreciation_date": "2015-12-31",
"gross_purchase_amount": 100000,
"expected_value_after_useful_life": 10000
})
try:
asset.save()
except frappe.DuplicateEntryError:
pass
return asset
def create_asset_category():
asset_category = frappe.new_doc("Asset Category")
asset_category.asset_category_name = "Computers"
asset_category.number_of_depreciations = 5
asset_category.number_of_months_in_a_period = 12
asset_category.append("accounts", {
"company": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC"
})
asset_category.insert()
def create_fixed_asset_item():
try:
frappe.get_doc({
"doctype": "Item",
"item_code": "Macbook Pro",
"item_name": "Macbook Pro",
"description": "Macbook Pro Retina Display",
"item_group": "All Item Groups",
"stock_uom": "Nos",
"is_fixed_asset": 1,
"is_stock_item": 0
}).insert()
except frappe.DuplicateEntryError:
pass

View File

@ -12,4 +12,4 @@ class AssetCategory(Document):
for field in ("depreciation_method", "number_of_depreciations",
"number_of_months_in_a_period", "accounts"):
if not self.get(field):
frappe.throw(_("{0} is mandatory").format(self.meta.get_label(field)))
frappe.throw(_("{0} is mandatory").format(self.meta.get_label(field)), frappe.MandatoryError)

View File

@ -6,7 +6,24 @@ from __future__ import unicode_literals
import frappe
import unittest
# test_records = frappe.get_test_records('Asset Category')
class TestAssetCategory(unittest.TestCase):
pass
def test_mandatory_fields(self):
asset_category = frappe.new_doc("Asset Category")
asset_category.asset_category_name = "Computers"
self.assertRaises(frappe.MandatoryError, asset_category.insert)
asset_category.number_of_depreciations = 5
asset_category.number_of_months_in_a_period = 12
asset_category.append("accounts", {
"company": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accoumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC"
})
try:
asset_category.insert()
except frappe.DuplicateEntryError:
pass

View File

@ -257,7 +257,7 @@
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0

View File

@ -49,7 +49,9 @@ def before_tests():
"company_tagline" :"Testing",
"email" :"test@erpnext.com",
"password" :"test",
"chart_of_accounts" : "Standard"
"chart_of_accounts" : "Standard",
"domain" : "Manufacturing",
})
frappe.db.sql("delete from `tabLeave Allocation`")