def test_purchase_asset(self): asset = frappe.get_doc("Asset", "Macbook Pro 1") 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("2015-01-01")) self.assertEqual(asset.purchase_invoice, pi.name) expected_gle = ( ("_Test Fixed Asset - _TC", 100000.0, 0.0), ("Creditors - _TC", 0.0, 100000.0) ) gle = frappe.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(frappe.db.get_value("GL Entry", {"voucher_type": "Purchase Invoice", "voucher_no": pi.name}))
def test_purchase_asset(self): asset = frappe.get_doc("Asset", "Macbook Pro 1") 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("2015-01-01")) self.assertEqual(asset.purchase_invoice, pi.name) expected_gle = ( ("_Test Fixed Asset - _TC", 100000.0, 0.0), ("Creditors - _TC", 0.0, 100000.0) ) gle = frappe.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(frappe.db.get_value("GL Entry", {"voucher_type": "Purchase Invoice", "voucher_no": pi.name}))
def test_purchase_asset(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = frappe.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 = frappe.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( frappe.db.get_value("GL Entry", { "voucher_type": "Purchase Invoice", "voucher_no": pi.name }))
def make_asset_purchase_entry(): asset_list = frappe.get_all("Asset", filters={"purchase_invoice": ["in", ("", None)]}, fields=["name", "item_code", "gross_purchase_amount", "company", "purchase_date"]) # make purchase invoice for asset in asset_list: pi = make_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount, asset.company, asset.purchase_date) pi.supplier = get_random("Supplier") pi.save() pi.submit() return asset_list
def test_purchase_asset(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset = frappe.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 = frappe.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(frappe.db.get_value("GL Entry", {"voucher_type": "Purchase Invoice", "voucher_no": pi.name}))
def make_asset_purchase_entry(): asset_list = frappe.get_all( "Asset", filters={"purchase_invoice": ["in", ("", None)]}, fields=[ "name", "item_code", "gross_purchase_amount", "company", "purchase_date" ]) # make purchase invoice for asset in asset_list: pi = make_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount, asset.company, asset.purchase_date) pi.supplier = get_random("Supplier") pi.save() pi.submit() return asset_list