From 6605919ecdae39234a6d808fff223723c99f2827 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 13 Nov 2017 15:06:35 +0530 Subject: [PATCH] GL Entries on sale of an asset (#11538) --- .../accounts/doctype/asset/depreciation.py | 19 +++++++------- erpnext/accounts/doctype/asset/test_asset.py | 4 +-- .../doctype/sales_invoice/sales_invoice.py | 26 +++++++++---------- erpnext/accounts/party.py | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/asset/depreciation.py b/erpnext/accounts/doctype/asset/depreciation.py index 495433a8b1..c72cb968da 100644 --- a/erpnext/accounts/doctype/asset/depreciation.py +++ b/erpnext/accounts/doctype/asset/depreciation.py @@ -151,11 +151,14 @@ def restore_asset(asset_name): asset.set_status() @frappe.whitelist() -def get_gl_entries_on_asset_disposal(asset, selling_amount=0): +def get_gl_entries_on_asset_disposal(asset, is_sale=False): fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset) - disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company) accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation) + expense_account, cost_center = get_disposal_account_and_cost_center(asset.company) + if is_sale: + expense_account = depr_expense_account + gl_entries = [ { "account": fixed_asset_account, @@ -169,14 +172,12 @@ def get_gl_entries_on_asset_disposal(asset, selling_amount=0): } ] - profit_amount = flt(selling_amount) - flt(asset.value_after_depreciation) - if flt(asset.value_after_depreciation) and profit_amount: - debit_or_credit = "debit" if profit_amount < 0 else "credit" + if flt(asset.value_after_depreciation): gl_entries.append({ - "account": disposal_account, - "cost_center": depreciation_cost_center, - debit_or_credit: abs(profit_amount), - debit_or_credit + "_in_account_currency": abs(profit_amount) + "account": expense_account, + "cost_center": cost_center, + "debit": flt(asset.value_after_depreciation), + "debit_in_account_currency": flt(asset.value_after_depreciation) }) return gl_entries diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py index 831373a9c9..fd66d1fb67 100644 --- a/erpnext/accounts/doctype/asset/test_asset.py +++ b/erpnext/accounts/doctype/asset/test_asset.py @@ -188,7 +188,6 @@ class TestAsset(unittest.TestCase): asset.load_from_db() depr_entry = asset.get("schedules")[0].journal_entry self.assertFalse(depr_entry) - def test_scrap_asset(self): asset = frappe.get_doc("Asset", "Macbook Pro 1") @@ -234,8 +233,9 @@ class TestAsset(unittest.TestCase): expected_gle = ( ("_Test Accumulated Depreciations - _TC", 30000.0, 0.0), + ("_Test Depreciations - _TC", 70000.0, 0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0), - ("_Test Gain/Loss on Asset Disposal - _TC", 45000.0, 0.0), + ("_Test Gain/Loss on Asset Disposal - _TC", 0.0, 25000.0), ("Debtors - _TC", 25000.0, 0.0) ) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 995a333eba..db9969d133 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -670,28 +670,28 @@ class SalesInvoice(SellingController): # income account gl entries for item in self.get("items"): if flt(item.base_net_amount): + account_currency = get_account_currency(item.income_account) + gl_entries.append( + self.get_gl_dict({ + "account": item.income_account, + "against": self.customer, + "credit": item.base_net_amount, + "credit_in_account_currency": item.base_net_amount \ + if account_currency==self.company_currency else item.net_amount, + "cost_center": item.cost_center + }, account_currency) + ) + if item.is_fixed_asset: asset = frappe.get_doc("Asset", item.asset) - fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, item.base_net_amount) + fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, is_sale=True) for gle in fixed_asset_gl_entries: gle["against"] = self.customer gl_entries.append(self.get_gl_dict(gle)) asset.db_set("disposal_date", self.posting_date) asset.set_status("Sold" if self.docstatus==1 else None) - else: - account_currency = get_account_currency(item.income_account) - gl_entries.append( - self.get_gl_dict({ - "account": item.income_account, - "against": self.customer, - "credit": item.base_net_amount, - "credit_in_account_currency": item.base_net_amount \ - if account_currency==self.company_currency else item.net_amount, - "cost_center": item.cost_center - }, account_currency) - ) # expense account gl entries if cint(self.update_stock) and \ diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 3a0b2d5e1e..f655830864 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -177,7 +177,7 @@ def get_party_account(party_type, party, company): frappe.throw(_("Please select a Company")) if not party: - frappe.throw(_("Please select a Party")) + return account = frappe.db.get_value("Party Account", {"parenttype": party_type, "parent": party, "company": company}, "account")