def test_inter_company_transfer(self): se = make_serialized_item(target_warehouse="_Test Warehouse - _TC") serial_nos = get_serial_nos(se.get("items")[0].serial_no) create_delivery_note(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0]) wh = create_warehouse("_Test Warehouse", company="_Test Company 1") make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1, serial_no=serial_nos[0], company="_Test Company 1", warehouse=wh) serial_no = dataent.db.get_value("Serial No", serial_nos[0], ["warehouse", "company"], as_dict=1) self.assertEqual(serial_no.warehouse, wh) self.assertEqual(serial_no.company, "_Test Company 1")
def test_asset_expected_value_after_useful_life(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-06-06" }) asset.insert() accumulated_depreciation_after_full_schedule = \ max([d.accumulated_depreciation_amount for d in asset.get("schedules")]) asset_value_after_full_schedule = ( flt(asset.gross_purchase_amount) - flt(accumulated_depreciation_after_full_schedule)) self.assertTrue(asset.finance_books[0].expected_value_after_useful_life >= asset_value_after_full_schedule)
def test_schedule_for_straight_line_method(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "next_depreciation_date": "2020-12-31", "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-06-06" }) asset.save() self.assertEqual(asset.status, "Draft") expected_schedules = [["2020-06-06", 147.54, 147.54], ["2021-04-06", 44852.46, 45000.0], ["2022-02-06", 45000.0, 90000.00]] schedules = [[ cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount ] for d in asset.get("schedules")] self.assertEqual(schedules, expected_schedules)
def test_current_asset_value(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset_doc = dataent.get_doc('Asset', asset_name) month_end_date = get_last_day(nowdate()) purchase_date = nowdate() if nowdate() != month_end_date else add_days( nowdate(), -15) asset_doc.available_for_use_date = purchase_date asset_doc.purchase_date = purchase_date asset_doc.calculate_depreciation = 1 asset_doc.append( "finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset_doc.submit() current_value = get_current_asset_value(asset_doc.name) self.assertEqual(current_value, 100000.0)
def test_depreciation_entry_cancellation(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-12-31" }) asset.insert() asset.submit() post_depreciation_entries(date="2021-01-01") asset.load_from_db() # cancel depreciation entry depr_entry = asset.get("schedules")[0].journal_entry self.assertTrue(depr_entry) dataent.get_doc("Journal Entry", depr_entry).cancel() asset.load_from_db() depr_entry = asset.get("schedules")[0].journal_entry self.assertFalse(depr_entry)
def test_purchase_asset(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 month_end_date = get_last_day(nowdate()) purchase_date = nowdate() if nowdate() != month_end_date else add_days( nowdate(), -15) asset.available_for_use_date = purchase_date asset.purchase_date = purchase_date asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset.submit() pi = make_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount, asset.company, asset.purchase_date) pi.supplier = "_Test Supplier" pi.insert() pi.submit() asset.load_from_db() self.assertEqual(asset.supplier, "_Test Supplier") self.assertEqual(asset.purchase_date, getdate(purchase_date)) self.assertEqual(asset.purchase_invoice, pi.name) expected_gle = (("Asset Received But Not Billed - _TC", 100000.0, 0.0), ("Creditors - _TC", 0.0, 100000.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no = %s order by account""", pi.name) self.assertEqual(gle, expected_gle) pi.cancel() asset.load_from_db() self.assertEqual(asset.supplier, None) self.assertEqual(asset.purchase_invoice, None) self.assertFalse( dataent.db.get_value("GL Entry", { "voucher_type": "Purchase Invoice", "voucher_no": pi.name }))
def test_expense_head(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=2, rate=200000.0, location="Test Location") doc = make_invoice(pr.name) self.assertEquals('Asset Received But Not Billed - _TC', doc.items[0].expense_account)
def test_asset_sale(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-12-31" }) asset.insert() asset.submit() post_depreciation_entries(date="2021-01-01") si = make_sales_invoice(asset=asset.name, item_code="Macbook Pro", company="_Test Company") si.customer = "_Test Customer" si.due_date = nowdate() si.get("items")[0].rate = 25000 si.insert() si.submit() self.assertEqual(dataent.db.get_value("Asset", asset.name, "status"), "Sold") expected_gle = (("_Test Accumulated Depreciations - _TC", 23051.47, 0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0), ("_Test Gain/Loss on Asset Disposal - _TC", 51948.53, 0.0), ("Debtors - _TC", 25000.0, 0.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no = %s order by account""", si.name) self.assertEqual(gle, expected_gle) si.cancel() dataent.delete_doc("Sales Invoice", si.name) self.assertEqual(dataent.db.get_value("Asset", asset.name, "status"), "Partially Depreciated")
def test_create_asset_maintenance(self): pr = make_purchase_receipt(item_code="Photocopier", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset_doc = dataent.get_doc('Asset', asset_name) month_end_date = get_last_day(nowdate()) purchase_date = nowdate() if nowdate() != month_end_date else add_days( nowdate(), -15) asset_doc.available_for_use_date = purchase_date asset_doc.purchase_date = purchase_date asset_doc.calculate_depreciation = 1 asset_doc.append( "finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset_doc.save() if not dataent.db.exists("Asset Maintenance", "Photocopier"): asset_maintenance = dataent.get_doc({ "doctype": "Asset Maintenance", "asset_name": "Photocopier", "maintenance_team": "Team Awesome", "company": "_Test Company", "asset_maintenance_tasks": get_maintenance_tasks() }).insert() next_due_date = calculate_next_due_date(nowdate(), "Monthly") self.assertEqual( asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)
def test_scrap_asset(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-06-06" }) asset.insert() asset.submit() post_depreciation_entries(date="2021-01-01") scrap_asset(asset.name) asset.load_from_db() self.assertEqual(asset.status, "Scrapped") self.assertTrue(asset.journal_entry_for_scrap) expected_gle = (("_Test Accumulated Depreciations - _TC", 147.54, 0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0), ("_Test Gain/Loss on Asset Disposal - _TC", 99852.46, 0.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no = %s order by account""", asset.journal_entry_for_scrap) self.assertEqual(gle, expected_gle) restore_asset(asset.name) asset.load_from_db() self.assertFalse(asset.journal_entry_for_scrap) self.assertEqual(asset.status, "Partially Depreciated")
def test_asset_depreciation_value_adjustment(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset_doc = dataent.get_doc('Asset', asset_name) asset_doc.calculate_depreciation = 1 month_end_date = get_last_day(nowdate()) purchase_date = nowdate() if nowdate() != month_end_date else add_days( nowdate(), -15) asset_doc.available_for_use_date = purchase_date asset_doc.purchase_date = purchase_date asset_doc.calculate_depreciation = 1 asset_doc.append( "finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset_doc.submit() current_value = get_current_asset_value(asset_doc.name) adj_doc = make_asset_value_adjustment( asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0) adj_doc.submit() expected_gle = (("_Test Accumulated Depreciations - _TC", 0.0, 50000.0), ("_Test Depreciations - _TC", 50000.0, 0.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no = %s order by account""", adj_doc.journal_entry) self.assertEqual(gle, expected_gle)
def test_depreciation(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.purchase_date = '2020-01-30' asset.available_for_use_date = "2020-01-30" asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-12-31" }) asset.insert() asset.submit() asset.load_from_db() self.assertEqual(asset.status, "Submitted") dataent.db.set_value("Company", "_Test Company", "series_for_depreciation_entry", "DEPR-") post_depreciation_entries(date="2021-01-01") asset.load_from_db() # check depreciation entry series self.assertEqual(asset.get("schedules")[0].journal_entry[:4], "DEPR") expected_gle = (("_Test Accumulated Depreciations - _TC", 0.0, 32129.24), ("_Test Depreciations - _TC", 32129.24, 0.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where against_voucher_type='Asset' and against_voucher = %s order by account""", asset.name) self.assertEqual(gle, expected_gle) self.assertEqual(asset.get("value_after_depreciation"), 0)
def test_movement_for_serialized_asset(self): asset_item = "Test Serialized Asset Item" pr = make_purchase_receipt(item_code=asset_item, rate = 1000, qty=3, location = "Mumbai") asset_name = dataent.db.get_value('Asset', {'purchase_receipt': pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) month_end_date = get_last_day(nowdate()) asset.available_for_use_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15) asset.calculate_depreciation = 1 asset.append("finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset.submit() serial_nos = dataent.db.get_value('Asset Movement', {'reference_name': pr.name}, 'serial_no') mov1 = create_asset_movement(asset=asset_name, purpose = 'Transfer', company=asset.company, source_location = "Mumbai", target_location="Pune", serial_no=serial_nos) self.assertEqual(mov1.target_location, "Pune") serial_no = dataent.db.get_value('Serial No', {'asset': asset_name}, 'name') employee = make_employee("*****@*****.**") create_asset_movement(asset=asset_name, purpose = 'Transfer', company=asset.company, serial_no=serial_no, to_employee=employee) self.assertEqual(dataent.db.get_value('Serial No', serial_no, 'employee'), employee) create_asset_movement(asset=asset_name, purpose = 'Transfer', company=asset.company, serial_no=serial_no, from_employee=employee, to_employee="_T-Employee-00001") self.assertEqual(dataent.db.get_value('Serial No', serial_no, 'location'), "Pune") mov4 = create_asset_movement(asset=asset_name, purpose = 'Transfer', company=asset.company, source_location = "Pune", target_location="Nagpur", serial_no=serial_nos) self.assertEqual(mov4.target_location, "Nagpur") self.assertEqual(dataent.db.get_value('Serial No', serial_no, 'location'), "Nagpur") self.assertEqual(dataent.db.get_value('Serial No', serial_no, 'employee'), "_T-Employee-00001")
def test_schedule_for_prorated_straight_line_method(self): set_prorated_depreciation_schedule() pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.purchase_date = '2020-01-30' asset.is_existing_asset = 0 asset.available_for_use_date = "2020-01-30" asset.append( "finance_books", { "expected_value_after_useful_life": 10000, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-12-31" }) asset.insert() asset.save() expected_schedules = [["2020-12-31", 28000.0, 28000.0], ["2021-12-31", 30000.0, 58000.0], ["2022-12-31", 30000.0, 88000.0], ["2023-01-30", 2000.0, 90000.0]] schedules = [[ cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2) ] for d in asset.get("schedules")] self.assertEqual(schedules, expected_schedules) remove_prorated_depreciation_schedule()
def test_landed_cost_voucher_for_odd_numbers(self): set_perpetual_inventory(1) pr = make_purchase_receipt(do_not_save=True) pr.items[0].cost_center = "_Test Company - _TC" for x in range(2): pr.append( "items", { "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", "cost_center": "_Test Company - _TC", "qty": 5, "rate": 50 }) pr.submit() lcv = submit_landed_cost_voucher("Purchase Receipt", pr.name, 123.22) self.assertEqual(lcv.items[0].applicable_charges, 41.07) self.assertEqual(lcv.items[2].applicable_charges, 41.08) set_perpetual_inventory(0)
def test_movement(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2020-06-06' asset.purchase_date = '2020-06-06' asset.append("finance_books", { "expected_value_after_useful_life": 10000, "next_depreciation_date": "2020-12-31", "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": "2020-06-06" }) if asset.docstatus == 0: asset.submit() if not dataent.db.exists("Location", "Test Location 2"): dataent.get_doc({ 'doctype': 'Location', 'location_name': 'Test Location 2' }).insert() movement1 = create_asset_movement(asset= asset.name, purpose = 'Transfer', company=asset.company, source_location="Test Location", target_location="Test Location 2") self.assertEqual(dataent.db.get_value("Asset", asset.name, "location"), "Test Location 2") movement2 = create_asset_movement(asset= asset.name, purpose = 'Transfer', company=asset.company, source_location = "Test Location 2", target_location="Test Location") self.assertEqual(dataent.db.get_value("Asset", asset.name, "location"), "Test Location") movement1.cancel() self.assertEqual(dataent.db.get_value("Asset", asset.name, "location"), "Test Location") movement2.cancel() self.assertEqual(dataent.db.get_value("Asset", asset.name, "location"), "Test Location")
def test_depreciation_entry_for_wdv(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=8000.0, location="Test Location") asset_name = dataent.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = dataent.get_doc('Asset', asset_name) asset.calculate_depreciation = 1 asset.available_for_use_date = '2030-06-06' asset.purchase_date = '2030-06-06' asset.append( "finance_books", { "expected_value_after_useful_life": 1000, "depreciation_method": "Written Down Value", "total_number_of_depreciations": 3, "frequency_of_depreciation": 12, "depreciation_start_date": "2030-12-31" }) asset.save(ignore_permissions=True) self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) expected_schedules = [ ["2030-12-31", 4000.0, 4000.0], ["2031-12-31", 2000.0, 6000.0], ["2032-12-31", 1000.0, 7000.0], ] schedules = [[ cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2) ] for d in asset.get("schedules")] self.assertEqual(schedules, expected_schedules)
def test_cwip_accounting(self): from epaas.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_purchase_invoice_from_pr) pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=5000, do_not_submit=True, location="Test Location") pr.set('taxes', [{ 'category': 'Total', 'add_deduct_tax': 'Add', 'charge_type': 'On Net Total', 'account_head': '_Test Account Service Tax - _TC', 'description': '_Test Account Service Tax', 'cost_center': 'Main - _TC', 'rate': 5.0 }, { 'category': 'Valuation and Total', 'add_deduct_tax': 'Add', 'charge_type': 'On Net Total', 'account_head': '_Test Account Shipping Charges - _TC', 'description': '_Test Account Shipping Charges', 'cost_center': 'Main - _TC', 'rate': 5.0 }]) pr.submit() expected_gle = (("Asset Received But Not Billed - _TC", 0.0, 5250.0), ("CWIP Account - _TC", 5250.0, 0.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no = %s order by account""", pr.name) self.assertEqual(gle, expected_gle) pi = make_purchase_invoice_from_pr(pr.name) pi.submit() expected_gle = ( ("_Test Account Service Tax - _TC", 250.0, 0.0), ("_Test Account Shipping Charges - _TC", 250.0, 0.0), ("Asset Received But Not Billed - _TC", 5250.0, 0.0), ("Creditors - _TC", 0.0, 5500.0), ("Expenses Included In Asset Valuation - _TC", 0.0, 250.0), ) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no = %s order by account""", pi.name) self.assertEqual(gle, expected_gle) asset = dataent.db.get_value('Asset', { 'purchase_receipt': pr.name, 'docstatus': 0 }, 'name') asset_doc = dataent.get_doc('Asset', asset) month_end_date = get_last_day(nowdate()) asset_doc.available_for_use_date = nowdate( ) if nowdate() != month_end_date else add_days(nowdate(), -15) self.assertEqual(asset_doc.gross_purchase_amount, 5250.0) asset_doc.append( "finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) asset_doc.submit() expected_gle = (("_Test Fixed Asset - _TC", 5250.0, 0.0), ("CWIP Account - _TC", 0.0, 5250.0)) gle = dataent.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s order by account""", asset_doc.name) self.assertEqual(gle, expected_gle)