chore: improve tests
This commit is contained in:
parent
6f4e6fafa9
commit
482116db9f
@ -210,6 +210,9 @@ class TestAsset(AssetSetup):
|
|||||||
submit=1,
|
submit=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
post_depreciation_entries(date=add_months(purchase_date, 2))
|
post_depreciation_entries(date=add_months(purchase_date, 2))
|
||||||
asset.load_from_db()
|
asset.load_from_db()
|
||||||
|
|
||||||
@ -221,6 +224,11 @@ class TestAsset(AssetSetup):
|
|||||||
|
|
||||||
scrap_asset(asset.name)
|
scrap_asset(asset.name)
|
||||||
asset.load_from_db()
|
asset.load_from_db()
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
accumulated_depr_amount = flt(
|
accumulated_depr_amount = flt(
|
||||||
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
||||||
@ -261,6 +269,11 @@ class TestAsset(AssetSetup):
|
|||||||
self.assertSequenceEqual(gle, expected_gle)
|
self.assertSequenceEqual(gle, expected_gle)
|
||||||
|
|
||||||
restore_asset(asset.name)
|
restore_asset(asset.name)
|
||||||
|
second_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
third_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(third_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
asset.load_from_db()
|
asset.load_from_db()
|
||||||
self.assertFalse(asset.journal_entry_for_scrap)
|
self.assertFalse(asset.journal_entry_for_scrap)
|
||||||
@ -288,6 +301,9 @@ class TestAsset(AssetSetup):
|
|||||||
submit=1,
|
submit=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
post_depreciation_entries(date=add_months(purchase_date, 2))
|
post_depreciation_entries(date=add_months(purchase_date, 2))
|
||||||
|
|
||||||
si = make_sales_invoice(asset=asset.name, item_code="Macbook Pro", company="_Test Company")
|
si = make_sales_invoice(asset=asset.name, item_code="Macbook Pro", company="_Test Company")
|
||||||
@ -299,6 +315,12 @@ class TestAsset(AssetSetup):
|
|||||||
|
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
||||||
|
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
pro_rata_amount, _, _ = asset.get_pro_rata_amt(
|
pro_rata_amount, _, _ = asset.get_pro_rata_amt(
|
||||||
asset.finance_books[0], 9000, get_last_day(add_months(purchase_date, 1)), date
|
asset.finance_books[0], 9000, get_last_day(add_months(purchase_date, 1)), date
|
||||||
)
|
)
|
||||||
@ -375,6 +397,9 @@ class TestAsset(AssetSetup):
|
|||||||
submit=1,
|
submit=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
post_depreciation_entries(date="2021-01-01")
|
post_depreciation_entries(date="2021-01-01")
|
||||||
|
|
||||||
self.assertEqual(asset.asset_quantity, 10)
|
self.assertEqual(asset.asset_quantity, 10)
|
||||||
@ -383,9 +408,18 @@ class TestAsset(AssetSetup):
|
|||||||
|
|
||||||
new_asset = split_asset(asset.name, 2)
|
new_asset = split_asset(asset.name, 2)
|
||||||
asset.load_from_db()
|
asset.load_from_db()
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
depr_schedule_of_asset = get_draft_or_active_depr_schedule(asset.name)
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
depr_schedule_of_new_asset = get_draft_or_active_depr_schedule(new_asset.name)
|
first_asset_depr_schedule_of_new_asset = get_draft_or_active_asset_depr_schedule_doc(
|
||||||
|
new_asset.name
|
||||||
|
)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule_of_new_asset.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
|
depr_schedule_of_asset = second_asset_depr_schedule.get("depreciation_schedule")
|
||||||
|
depr_schedule_of_new_asset = first_asset_depr_schedule_of_new_asset.get("depreciation_schedule")
|
||||||
|
|
||||||
self.assertEqual(new_asset.asset_quantity, 2)
|
self.assertEqual(new_asset.asset_quantity, 2)
|
||||||
self.assertEqual(new_asset.gross_purchase_amount, 24000)
|
self.assertEqual(new_asset.gross_purchase_amount, 24000)
|
||||||
@ -1351,9 +1385,9 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
# cancel depreciation entry
|
# cancel depreciation entry
|
||||||
depr_entry = get_draft_or_active_depr_schedule(asset.name)[0].journal_entry
|
depr_entry = get_draft_or_active_depr_schedule(asset.name)[0].journal_entry
|
||||||
self.assertTrue(depr_entry)
|
self.assertTrue(depr_entry)
|
||||||
|
|
||||||
frappe.get_doc("Journal Entry", depr_entry).cancel()
|
frappe.get_doc("Journal Entry", depr_entry).cancel()
|
||||||
|
|
||||||
asset.load_from_db()
|
|
||||||
depr_entry = get_draft_or_active_depr_schedule(asset.name)[0].journal_entry
|
depr_entry = get_draft_or_active_depr_schedule(asset.name)[0].journal_entry
|
||||||
self.assertFalse(depr_entry)
|
self.assertFalse(depr_entry)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from erpnext.assets.doctype.asset.test_asset import (
|
|||||||
set_depreciation_settings_in_company,
|
set_depreciation_settings_in_company,
|
||||||
)
|
)
|
||||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||||
get_draft_or_active_depr_schedule,
|
get_draft_or_active_asset_depr_schedule_doc,
|
||||||
)
|
)
|
||||||
from erpnext.stock.doctype.item.test_item import create_item
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
|
|
||||||
@ -256,6 +256,9 @@ class TestAssetCapitalization(unittest.TestCase):
|
|||||||
submit=1,
|
submit=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(consumed_asset.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
# Create and submit Asset Captitalization
|
# Create and submit Asset Captitalization
|
||||||
asset_capitalization = create_asset_capitalization(
|
asset_capitalization = create_asset_capitalization(
|
||||||
entry_type="Decapitalization",
|
entry_type="Decapitalization",
|
||||||
@ -285,9 +288,17 @@ class TestAssetCapitalization(unittest.TestCase):
|
|||||||
consumed_asset.reload()
|
consumed_asset.reload()
|
||||||
self.assertEqual(consumed_asset.status, "Decapitalized")
|
self.assertEqual(consumed_asset.status, "Decapitalized")
|
||||||
|
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(consumed_asset.name)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
|
depr_schedule_of_consumed_asset = second_asset_depr_schedule.get("depreciation_schedule")
|
||||||
|
|
||||||
consumed_depreciation_schedule = [
|
consumed_depreciation_schedule = [
|
||||||
d
|
d
|
||||||
for d in get_draft_or_active_depr_schedule(consumed_asset.name)
|
for d in depr_schedule_of_consumed_asset
|
||||||
if getdate(d.schedule_date) == getdate(capitalization_date)
|
if getdate(d.schedule_date) == getdate(capitalization_date)
|
||||||
]
|
]
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
@ -122,8 +122,10 @@ def convert_draft_asset_depr_schedules_into_active(asset_doc):
|
|||||||
asset_doc.name, row.finance_book
|
asset_doc.name, row.finance_book
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not asset_depr_schedule_doc:
|
||||||
|
continue
|
||||||
|
|
||||||
if asset_depr_schedule_doc.status == "Draft":
|
if asset_depr_schedule_doc.status == "Draft":
|
||||||
asset_depr_schedule_doc.status = "Active"
|
|
||||||
asset_depr_schedule_doc.submit()
|
asset_depr_schedule_doc.submit()
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from erpnext.assets.doctype.asset.test_asset import (
|
|||||||
set_depreciation_settings_in_company,
|
set_depreciation_settings_in_company,
|
||||||
)
|
)
|
||||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||||
get_draft_or_active_depr_schedule,
|
get_draft_or_active_asset_depr_schedule_doc,
|
||||||
)
|
)
|
||||||
from erpnext.stock.doctype.item.test_item import create_item
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
|
|
||||||
@ -235,13 +235,23 @@ class TestAssetRepair(unittest.TestCase):
|
|||||||
|
|
||||||
def test_increase_in_asset_life(self):
|
def test_increase_in_asset_life(self):
|
||||||
asset = create_asset(calculate_depreciation=1, submit=1)
|
asset = create_asset(calculate_depreciation=1, submit=1)
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
initial_num_of_depreciations = num_of_depreciations(asset)
|
initial_num_of_depreciations = num_of_depreciations(asset)
|
||||||
create_asset_repair(asset=asset, capitalize_repair_cost=1, submit=1)
|
create_asset_repair(asset=asset, capitalize_repair_cost=1, submit=1)
|
||||||
|
|
||||||
asset.reload()
|
asset.reload()
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset.name)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
self.assertEqual((initial_num_of_depreciations + 1), num_of_depreciations(asset))
|
self.assertEqual((initial_num_of_depreciations + 1), num_of_depreciations(asset))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
get_draft_or_active_depr_schedule(asset.name)[-1].accumulated_depreciation_amount,
|
second_asset_depr_schedule.get("depreciation_schedule")[-1].accumulated_depreciation_amount,
|
||||||
asset.finance_books[0].value_after_depreciation,
|
asset.finance_books[0].value_after_depreciation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ import frappe
|
|||||||
from frappe.utils import add_days, get_last_day, nowdate
|
from frappe.utils import add_days, get_last_day, nowdate
|
||||||
|
|
||||||
from erpnext.assets.doctype.asset.test_asset import create_asset_data
|
from erpnext.assets.doctype.asset.test_asset import create_asset_data
|
||||||
|
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||||
|
get_draft_or_active_asset_depr_schedule_doc,
|
||||||
|
)
|
||||||
from erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment import (
|
from erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment import (
|
||||||
get_current_asset_value,
|
get_current_asset_value,
|
||||||
)
|
)
|
||||||
@ -73,12 +76,21 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
asset_doc.submit()
|
asset_doc.submit()
|
||||||
|
|
||||||
|
first_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset_doc.name)
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||||
|
|
||||||
current_value = get_current_asset_value(asset_doc.name)
|
current_value = get_current_asset_value(asset_doc.name)
|
||||||
adj_doc = make_asset_value_adjustment(
|
adj_doc = make_asset_value_adjustment(
|
||||||
asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0
|
asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0
|
||||||
)
|
)
|
||||||
adj_doc.submit()
|
adj_doc.submit()
|
||||||
|
|
||||||
|
first_asset_depr_schedule.load_from_db()
|
||||||
|
|
||||||
|
second_asset_depr_schedule = get_draft_or_active_asset_depr_schedule_doc(asset_doc.name)
|
||||||
|
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||||
|
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 0.0, 50000.0),
|
("_Test Accumulated Depreciations - _TC", 0.0, 50000.0),
|
||||||
("_Test Depreciations - _TC", 50000.0, 0.0),
|
("_Test Depreciations - _TC", 50000.0, 0.0),
|
||||||
|
Loading…
Reference in New Issue
Block a user