fix: incorrect value booked in the accumulated depreciation account on sell of the asset
This commit is contained in:
parent
42c8a4baa0
commit
8847ecfe25
@ -768,7 +768,14 @@ class SalesInvoice(SellingController):
|
|||||||
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)
|
if (len(asset.finance_books) > 1 and not item.finance_book
|
||||||
|
and asset.finance_books[0].finance_book):
|
||||||
|
frappe.throw(_("Select finance book for the item {0} at row {1}")
|
||||||
|
.format(item.item_code, item.idx))
|
||||||
|
|
||||||
|
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset,
|
||||||
|
item.base_net_amount, item.finance_book)
|
||||||
|
|
||||||
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))
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
"income_account",
|
"income_account",
|
||||||
"is_fixed_asset",
|
"is_fixed_asset",
|
||||||
"asset",
|
"asset",
|
||||||
|
"finance_book",
|
||||||
"col_break4",
|
"col_break4",
|
||||||
"expense_account",
|
"expense_account",
|
||||||
"deferred_revenue",
|
"deferred_revenue",
|
||||||
@ -770,11 +771,18 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "dimension_col_break",
|
"fieldname": "dimension_col_break",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "asset",
|
||||||
|
"fieldname": "finance_book",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Finance Book",
|
||||||
|
"options": "Finance Book"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2019-05-25 22:05:59.971263",
|
"modified": "2019-06-28 17:30:12.156086",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Sales Invoice Item",
|
"name": "Sales Invoice Item",
|
||||||
|
@ -156,12 +156,20 @@ 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, selling_amount=0, finance_book=None):
|
||||||
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)
|
disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
|
||||||
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
||||||
|
|
||||||
accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation)
|
idx = 1
|
||||||
|
if finance_book:
|
||||||
|
for d in asset.finance_books:
|
||||||
|
if d.finance_book == finance_book:
|
||||||
|
idx = d.idx
|
||||||
|
break
|
||||||
|
|
||||||
|
value_after_depreciation = asset.finance_books[idx - 1].value_after_depreciation
|
||||||
|
accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(value_after_depreciation)
|
||||||
|
|
||||||
gl_entries = [
|
gl_entries = [
|
||||||
{
|
{
|
||||||
@ -176,7 +184,7 @@ def get_gl_entries_on_asset_disposal(asset, selling_amount=0):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
profit_amount = flt(selling_amount) - flt(asset.value_after_depreciation)
|
profit_amount = flt(selling_amount) - flt(value_after_depreciation)
|
||||||
if profit_amount:
|
if profit_amount:
|
||||||
debit_or_credit = "debit" if profit_amount < 0 else "credit"
|
debit_or_credit = "debit" if profit_amount < 0 else "credit"
|
||||||
gl_entries.append({
|
gl_entries.append({
|
||||||
|
@ -366,8 +366,9 @@ class TestAsset(unittest.TestCase):
|
|||||||
self.assertTrue(asset.journal_entry_for_scrap)
|
self.assertTrue(asset.journal_entry_for_scrap)
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 100000.0, 0.0),
|
("_Test Accumulated Depreciations - _TC", 147.54, 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", 99852.46, 0.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
|
gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
|
||||||
@ -411,9 +412,9 @@ class TestAsset(unittest.TestCase):
|
|||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 100000.0, 0.0),
|
("_Test Accumulated Depreciations - _TC", 23051.47, 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", 0, 25000.0),
|
("_Test Gain/Loss on Asset Disposal - _TC", 51948.53, 0.0),
|
||||||
("Debtors - _TC", 25000.0, 0.0)
|
("Debtors - _TC", 25000.0, 0.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user