GL Entries on sale of an asset (#11538)

This commit is contained in:
Nabin Hait 2017-11-13 15:06:35 +05:30 committed by GitHub
parent feeb47dbbe
commit 6605919ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 25 deletions

View File

@ -151,11 +151,14 @@ def restore_asset(asset_name):
asset.set_status() asset.set_status()
@frappe.whitelist() @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) 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) 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 = [ gl_entries = [
{ {
"account": fixed_asset_account, "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):
if flt(asset.value_after_depreciation) and profit_amount:
debit_or_credit = "debit" if profit_amount < 0 else "credit"
gl_entries.append({ gl_entries.append({
"account": disposal_account, "account": expense_account,
"cost_center": depreciation_cost_center, "cost_center": cost_center,
debit_or_credit: abs(profit_amount), "debit": flt(asset.value_after_depreciation),
debit_or_credit + "_in_account_currency": abs(profit_amount) "debit_in_account_currency": flt(asset.value_after_depreciation)
}) })
return gl_entries return gl_entries

View File

@ -188,7 +188,6 @@ class TestAsset(unittest.TestCase):
asset.load_from_db() asset.load_from_db()
depr_entry = asset.get("schedules")[0].journal_entry depr_entry = asset.get("schedules")[0].journal_entry
self.assertFalse(depr_entry) self.assertFalse(depr_entry)
def test_scrap_asset(self): def test_scrap_asset(self):
asset = frappe.get_doc("Asset", "Macbook Pro 1") asset = frappe.get_doc("Asset", "Macbook Pro 1")
@ -234,8 +233,9 @@ class TestAsset(unittest.TestCase):
expected_gle = ( expected_gle = (
("_Test Accumulated Depreciations - _TC", 30000.0, 0.0), ("_Test Accumulated Depreciations - _TC", 30000.0, 0.0),
("_Test Depreciations - _TC", 70000.0, 0.0),
("_Test Fixed Asset - _TC", 0.0, 100000.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) ("Debtors - _TC", 25000.0, 0.0)
) )

View File

@ -670,28 +670,28 @@ class SalesInvoice(SellingController):
# income account gl entries # income account gl entries
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_net_amount): 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: if item.is_fixed_asset:
asset = frappe.get_doc("Asset", item.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: for gle in fixed_asset_gl_entries:
gle["against"] = self.customer gle["against"] = self.customer
gl_entries.append(self.get_gl_dict(gle)) gl_entries.append(self.get_gl_dict(gle))
asset.db_set("disposal_date", self.posting_date) asset.db_set("disposal_date", self.posting_date)
asset.set_status("Sold" if self.docstatus==1 else None) 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 # expense account gl entries
if cint(self.update_stock) and \ if cint(self.update_stock) and \

View File

@ -177,7 +177,7 @@ def get_party_account(party_type, party, company):
frappe.throw(_("Please select a Company")) frappe.throw(_("Please select a Company"))
if not party: if not party:
frappe.throw(_("Please select a Party")) return
account = frappe.db.get_value("Party Account", account = frappe.db.get_value("Party Account",
{"parenttype": party_type, "parent": party, "company": company}, "account") {"parenttype": party_type, "parent": party, "company": company}, "account")