Merge pull request #18104 from rohitwaghchaure/incorrect_value_of_accumualated_depreciation_in_the_sales_invoice_develop

fix: incorrect value booked in the accumulated depreciation account on sell of the asset
This commit is contained in:
rohitwaghchaure 2019-07-02 01:23:56 +05:30 committed by GitHub
commit f949c5ddf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 20 deletions

View File

@ -768,7 +768,14 @@ class SalesInvoice(SellingController):
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)
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:
gle["against"] = self.customer
gl_entries.append(self.get_gl_dict(gle))

View File

@ -57,6 +57,7 @@
"income_account",
"is_fixed_asset",
"asset",
"finance_book",
"col_break4",
"expense_account",
"deferred_revenue",
@ -770,11 +771,18 @@
{
"fieldname": "dimension_col_break",
"fieldtype": "Column Break"
},
{
"depends_on": "asset",
"fieldname": "finance_book",
"fieldtype": "Link",
"label": "Finance Book",
"options": "Finance Book"
}
],
"idx": 1,
"istable": 1,
"modified": "2019-05-25 22:05:59.971263",
"modified": "2019-06-28 17:30:12.156086",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",

View File

@ -156,12 +156,20 @@ 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, selling_amount=0, finance_book=None):
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)
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 = [
{
@ -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:
debit_or_credit = "debit" if profit_amount < 0 else "credit"
gl_entries.append({

View File

@ -366,8 +366,9 @@ class TestAsset(unittest.TestCase):
self.assertTrue(asset.journal_entry_for_scrap)
expected_gle = (
("_Test Accumulated Depreciations - _TC", 100000.0, 0.0),
("_Test Fixed Asset - _TC", 0.0, 100000.0)
("_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 = 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")
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 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)
)