chore: remove finance_book and finance_book_id from depreciation_schedule and refactor some functions
This commit is contained in:
parent
8365d6bdb7
commit
e7d404a30a
@ -294,7 +294,7 @@ def reverse_depreciation_entry_made_after_disposal(asset, date):
|
|||||||
for schedule_idx, schedule in enumerate(depr_schedule):
|
for schedule_idx, schedule in enumerate(depr_schedule):
|
||||||
if schedule.schedule_date == date:
|
if schedule.schedule_date == date:
|
||||||
if not disposal_was_made_on_original_schedule_date(
|
if not disposal_was_made_on_original_schedule_date(
|
||||||
asset, schedule, schedule_idx, date
|
schedule_idx, row, date
|
||||||
) or disposal_happens_in_the_future(date):
|
) or disposal_happens_in_the_future(date):
|
||||||
|
|
||||||
reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
|
reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
|
||||||
@ -318,15 +318,14 @@ def get_depreciation_amount_in_je(journal_entry):
|
|||||||
|
|
||||||
|
|
||||||
# if the invoice had been posted on the date the depreciation was initially supposed to happen, the depreciation shouldn't be undone
|
# if the invoice had been posted on the date the depreciation was initially supposed to happen, the depreciation shouldn't be undone
|
||||||
def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_date_of_disposal):
|
def disposal_was_made_on_original_schedule_date(schedule_idx, row, posting_date_of_disposal):
|
||||||
for finance_book in asset.get("finance_books"):
|
|
||||||
if schedule.finance_book == finance_book.finance_book:
|
|
||||||
orginal_schedule_date = add_months(
|
orginal_schedule_date = add_months(
|
||||||
finance_book.depreciation_start_date, row * cint(finance_book.frequency_of_depreciation)
|
row.depreciation_start_date, schedule_idx * cint(row.frequency_of_depreciation)
|
||||||
)
|
)
|
||||||
|
|
||||||
if orginal_schedule_date == posting_date_of_disposal:
|
if orginal_schedule_date == posting_date_of_disposal:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,17 +50,18 @@ def update_draft_asset_depr_schedules(asset_doc, date_of_disposal=None, date_of_
|
|||||||
def prepare_draft_asset_depr_schedule_data(
|
def prepare_draft_asset_depr_schedule_data(
|
||||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, date_of_return
|
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, date_of_return
|
||||||
):
|
):
|
||||||
set_draft_asset_depr_schedule_details(asset_depr_schedule_doc, asset_doc.name, row)
|
set_draft_asset_depr_schedule_details(asset_depr_schedule_doc, asset_doc, row)
|
||||||
make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, date_of_disposal)
|
make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, date_of_disposal)
|
||||||
set_accumulated_depreciation(
|
set_accumulated_depreciation(asset_depr_schedule_doc, row, date_of_disposal, date_of_return)
|
||||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, date_of_return
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def set_draft_asset_depr_schedule_details(asset_depr_schedule_doc, asset_name, row):
|
def set_draft_asset_depr_schedule_details(asset_depr_schedule_doc, asset_doc, row):
|
||||||
asset_depr_schedule_doc.asset = asset_name
|
asset_depr_schedule_doc.asset = asset_doc.name
|
||||||
asset_depr_schedule_doc.finance_book = row.finance_book
|
asset_depr_schedule_doc.finance_book = row.finance_book
|
||||||
asset_depr_schedule_doc.finance_book_id = row.idx
|
asset_depr_schedule_doc.finance_book_id = row.idx
|
||||||
|
asset_depr_schedule_doc.opening_accumulated_depreciation = (
|
||||||
|
asset_doc.opening_accumulated_depreciation
|
||||||
|
)
|
||||||
asset_depr_schedule_doc.depreciation_method = row.depreciation_method
|
asset_depr_schedule_doc.depreciation_method = row.depreciation_method
|
||||||
asset_depr_schedule_doc.total_number_of_depreciations = row.total_number_of_depreciations
|
asset_depr_schedule_doc.total_number_of_depreciations = row.total_number_of_depreciations
|
||||||
asset_depr_schedule_doc.frequency_of_depreciation = row.frequency_of_depreciation
|
asset_depr_schedule_doc.frequency_of_depreciation = row.frequency_of_depreciation
|
||||||
@ -99,9 +100,7 @@ def make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
|||||||
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
||||||
|
|
||||||
make_depr_schedule(new_asset_depr_schedule_doc, asset_doc, row, date_of_disposal)
|
make_depr_schedule(new_asset_depr_schedule_doc, asset_doc, row, date_of_disposal)
|
||||||
set_accumulated_depreciation(
|
set_accumulated_depreciation(new_asset_depr_schedule_doc, row, date_of_disposal, date_of_return)
|
||||||
new_asset_depr_schedule_doc, asset_doc, row, date_of_disposal, date_of_return
|
|
||||||
)
|
|
||||||
|
|
||||||
new_asset_depr_schedule_doc.notes = notes
|
new_asset_depr_schedule_doc.notes = notes
|
||||||
|
|
||||||
@ -243,8 +242,6 @@ def _make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, start, date_of_
|
|||||||
date_of_disposal,
|
date_of_disposal,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
row.depreciation_method,
|
row.depreciation_method,
|
||||||
row.finance_book,
|
|
||||||
row.idx,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -309,8 +306,6 @@ def _make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, start, date_of_
|
|||||||
schedule_date,
|
schedule_date,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
row.depreciation_method,
|
row.depreciation_method,
|
||||||
row.finance_book,
|
|
||||||
row.idx,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -339,8 +334,6 @@ def add_depr_schedule_row(
|
|||||||
schedule_date,
|
schedule_date,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
depreciation_method,
|
depreciation_method,
|
||||||
finance_book,
|
|
||||||
finance_book_id,
|
|
||||||
):
|
):
|
||||||
asset_depr_schedule_doc.append(
|
asset_depr_schedule_doc.append(
|
||||||
"depreciation_schedule",
|
"depreciation_schedule",
|
||||||
@ -348,15 +341,12 @@ def add_depr_schedule_row(
|
|||||||
"schedule_date": schedule_date,
|
"schedule_date": schedule_date,
|
||||||
"depreciation_amount": depreciation_amount,
|
"depreciation_amount": depreciation_amount,
|
||||||
"depreciation_method": depreciation_method,
|
"depreciation_method": depreciation_method,
|
||||||
"finance_book": finance_book,
|
|
||||||
"finance_book_id": finance_book_id,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def set_accumulated_depreciation(
|
def set_accumulated_depreciation(
|
||||||
asset_depr_schedule_doc,
|
asset_depr_schedule_doc,
|
||||||
asset_doc,
|
|
||||||
row,
|
row,
|
||||||
date_of_disposal=None,
|
date_of_disposal=None,
|
||||||
date_of_return=None,
|
date_of_return=None,
|
||||||
@ -367,17 +357,14 @@ def set_accumulated_depreciation(
|
|||||||
for d in asset_depr_schedule_doc.get("depreciation_schedule")
|
for d in asset_depr_schedule_doc.get("depreciation_schedule")
|
||||||
if d.depreciation_method == "Straight Line"
|
if d.depreciation_method == "Straight Line"
|
||||||
]
|
]
|
||||||
finance_books = []
|
|
||||||
|
accumulated_depreciation = flt(asset_depr_schedule_doc.opening_accumulated_depreciation)
|
||||||
|
value_after_depreciation = flt(row.value_after_depreciation)
|
||||||
|
|
||||||
for i, d in enumerate(asset_depr_schedule_doc.get("depreciation_schedule")):
|
for i, d in enumerate(asset_depr_schedule_doc.get("depreciation_schedule")):
|
||||||
if ignore_booked_entry and d.journal_entry:
|
if ignore_booked_entry and d.journal_entry:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if int(d.finance_book_id) not in finance_books:
|
|
||||||
accumulated_depreciation = flt(asset_doc.opening_accumulated_depreciation)
|
|
||||||
value_after_depreciation = flt(asset_doc.get_value_after_depreciation(d.finance_book_id))
|
|
||||||
finance_books.append(int(d.finance_book_id))
|
|
||||||
|
|
||||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||||
value_after_depreciation -= flt(depreciation_amount)
|
value_after_depreciation -= flt(depreciation_amount)
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class AssetValueAdjustment(Document):
|
|||||||
|
|
||||||
d.db_update()
|
d.db_update()
|
||||||
|
|
||||||
set_accumulated_depreciation(new_asset_depr_schedule_doc, asset, d, ignore_booked_entry=True)
|
set_accumulated_depreciation(new_asset_depr_schedule_doc, d, ignore_booked_entry=True)
|
||||||
for asset_data in depr_schedule:
|
for asset_data in depr_schedule:
|
||||||
if not asset_data.journal_entry:
|
if not asset_data.journal_entry:
|
||||||
asset_data.db_update()
|
asset_data.db_update()
|
||||||
|
@ -7,25 +7,15 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"finance_book",
|
|
||||||
"schedule_date",
|
"schedule_date",
|
||||||
"depreciation_amount",
|
"depreciation_amount",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"accumulated_depreciation_amount",
|
"accumulated_depreciation_amount",
|
||||||
"journal_entry",
|
"journal_entry",
|
||||||
"make_depreciation_entry",
|
"make_depreciation_entry",
|
||||||
"finance_book_id",
|
|
||||||
"depreciation_method"
|
"depreciation_method"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
|
||||||
"fieldname": "finance_book",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Finance Book",
|
|
||||||
"options": "Finance Book",
|
|
||||||
"read_only": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "schedule_date",
|
"fieldname": "schedule_date",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
@ -69,14 +59,6 @@
|
|||||||
"fieldtype": "Button",
|
"fieldtype": "Button",
|
||||||
"label": "Make Depreciation Entry"
|
"label": "Make Depreciation Entry"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "finance_book_id",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"hidden": 1,
|
|
||||||
"label": "Finance Book Id",
|
|
||||||
"print_hide": 1,
|
|
||||||
"read_only": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "depreciation_method",
|
"fieldname": "depreciation_method",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
@ -89,7 +71,7 @@
|
|||||||
],
|
],
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-11-29 18:27:05.748012",
|
"modified": "2022-12-06 20:35:50.264281",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Depreciation Schedule",
|
"name": "Depreciation Schedule",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user