mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
refactor: renamed number of depreciations booked to opening booked de… (#41515)
* refactor: renamed number of depreciations booked to opening booked depreciations * feat: introduced new field for showing total number of booked depreciations
This commit is contained in:
@@ -194,6 +194,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.update_asset_value()
|
self.update_asset_value()
|
||||||
self.update_inter_company_jv()
|
self.update_inter_company_jv()
|
||||||
self.update_invoice_discounting()
|
self.update_invoice_discounting()
|
||||||
|
self.update_booked_depreciation()
|
||||||
|
|
||||||
def on_update_after_submit(self):
|
def on_update_after_submit(self):
|
||||||
if hasattr(self, "repost_required"):
|
if hasattr(self, "repost_required"):
|
||||||
@@ -225,6 +226,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.unlink_inter_company_jv()
|
self.unlink_inter_company_jv()
|
||||||
self.unlink_asset_adjustment_entry()
|
self.unlink_asset_adjustment_entry()
|
||||||
self.update_invoice_discounting()
|
self.update_invoice_discounting()
|
||||||
|
self.update_booked_depreciation()
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.pay_to_recd_from or self.accounts[0].account
|
return self.pay_to_recd_from or self.accounts[0].account
|
||||||
@@ -442,6 +444,28 @@ class JournalEntry(AccountsController):
|
|||||||
if status:
|
if status:
|
||||||
inv_disc_doc.set_status(status=status)
|
inv_disc_doc.set_status(status=status)
|
||||||
|
|
||||||
|
def update_booked_depreciation(self):
|
||||||
|
for d in self.get("accounts"):
|
||||||
|
if (
|
||||||
|
self.voucher_type == "Depreciation Entry"
|
||||||
|
and d.reference_type == "Asset"
|
||||||
|
and d.reference_name
|
||||||
|
and frappe.get_cached_value("Account", d.account, "root_type") == "Expense"
|
||||||
|
and d.debit
|
||||||
|
):
|
||||||
|
asset = frappe.get_doc("Asset", d.reference_name)
|
||||||
|
for fb_row in asset.get("finance_books"):
|
||||||
|
if fb_row.finance_book == self.finance_book:
|
||||||
|
depr_schedule = get_depr_schedule(asset.name, "Active", fb_row.finance_book)
|
||||||
|
total_number_of_booked_depreciations = asset.opening_number_of_booked_depreciations
|
||||||
|
for je in depr_schedule:
|
||||||
|
if je.journal_entry:
|
||||||
|
total_number_of_booked_depreciations += 1
|
||||||
|
fb_row.db_set(
|
||||||
|
"total_number_of_booked_depreciations", total_number_of_booked_depreciations
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
def unlink_advance_entry_reference(self):
|
def unlink_advance_entry_reference(self):
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.is_advance == "Yes" and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
if d.is_advance == "Yes" and d.reference_type in ("Sales Invoice", "Purchase Invoice"):
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
"calculate_depreciation",
|
"calculate_depreciation",
|
||||||
"column_break_33",
|
"column_break_33",
|
||||||
"opening_accumulated_depreciation",
|
"opening_accumulated_depreciation",
|
||||||
"number_of_depreciations_booked",
|
"opening_number_of_booked_depreciations",
|
||||||
"is_fully_depreciated",
|
"is_fully_depreciated",
|
||||||
"section_break_36",
|
"section_break_36",
|
||||||
"finance_books",
|
"finance_books",
|
||||||
@@ -257,12 +257,6 @@
|
|||||||
"label": "Opening Accumulated Depreciation",
|
"label": "Opening Accumulated Depreciation",
|
||||||
"options": "Company:company:default_currency"
|
"options": "Company:company:default_currency"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"depends_on": "eval:(doc.is_existing_asset)",
|
|
||||||
"fieldname": "number_of_depreciations_booked",
|
|
||||||
"fieldtype": "Int",
|
|
||||||
"label": "Number of Depreciations Booked"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
"collapsible_depends_on": "eval:doc.calculate_depreciation || doc.is_existing_asset",
|
"collapsible_depends_on": "eval:doc.calculate_depreciation || doc.is_existing_asset",
|
||||||
@@ -546,6 +540,12 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:(doc.is_existing_asset)",
|
||||||
|
"fieldname": "opening_number_of_booked_depreciations",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Opening Number of Booked Depreciations"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"idx": 72,
|
"idx": 72,
|
||||||
@@ -589,7 +589,7 @@
|
|||||||
"link_fieldname": "target_asset"
|
"link_fieldname": "target_asset"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2024-04-18 16:45:47.306032",
|
"modified": "2024-05-21 13:46:21.066483",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ class Asset(AccountsController):
|
|||||||
maintenance_required: DF.Check
|
maintenance_required: DF.Check
|
||||||
naming_series: DF.Literal["ACC-ASS-.YYYY.-"]
|
naming_series: DF.Literal["ACC-ASS-.YYYY.-"]
|
||||||
next_depreciation_date: DF.Date | None
|
next_depreciation_date: DF.Date | None
|
||||||
number_of_depreciations_booked: DF.Int
|
|
||||||
opening_accumulated_depreciation: DF.Currency
|
opening_accumulated_depreciation: DF.Currency
|
||||||
|
opening_number_of_booked_depreciations: DF.Int
|
||||||
policy_number: DF.Data | None
|
policy_number: DF.Data | None
|
||||||
purchase_amount: DF.Currency
|
purchase_amount: DF.Currency
|
||||||
purchase_date: DF.Date | None
|
purchase_date: DF.Date | None
|
||||||
@@ -145,7 +145,7 @@ class Asset(AccountsController):
|
|||||||
"Asset Depreciation Schedules created:<br>{0}<br><br>Please check, edit if needed, and submit the Asset."
|
"Asset Depreciation Schedules created:<br>{0}<br><br>Please check, edit if needed, and submit the Asset."
|
||||||
).format(asset_depr_schedules_links)
|
).format(asset_depr_schedules_links)
|
||||||
)
|
)
|
||||||
|
self.set_total_booked_depreciations()
|
||||||
self.total_asset_cost = self.gross_purchase_amount
|
self.total_asset_cost = self.gross_purchase_amount
|
||||||
self.status = self.get_status()
|
self.status = self.get_status()
|
||||||
|
|
||||||
@@ -419,7 +419,7 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
if not self.is_existing_asset:
|
if not self.is_existing_asset:
|
||||||
self.opening_accumulated_depreciation = 0
|
self.opening_accumulated_depreciation = 0
|
||||||
self.number_of_depreciations_booked = 0
|
self.opening_number_of_booked_depreciations = 0
|
||||||
else:
|
else:
|
||||||
depreciable_amount = flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
depreciable_amount = flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
||||||
if flt(self.opening_accumulated_depreciation) > depreciable_amount:
|
if flt(self.opening_accumulated_depreciation) > depreciable_amount:
|
||||||
@@ -430,15 +430,15 @@ class Asset(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.opening_accumulated_depreciation:
|
if self.opening_accumulated_depreciation:
|
||||||
if not self.number_of_depreciations_booked:
|
if not self.opening_number_of_booked_depreciations:
|
||||||
frappe.throw(_("Please set Number of Depreciations Booked"))
|
frappe.throw(_("Please set Opening Number of Booked Depreciations"))
|
||||||
else:
|
else:
|
||||||
self.number_of_depreciations_booked = 0
|
self.opening_number_of_booked_depreciations = 0
|
||||||
|
|
||||||
if flt(row.total_number_of_depreciations) <= cint(self.number_of_depreciations_booked):
|
if flt(row.total_number_of_depreciations) <= cint(self.opening_number_of_booked_depreciations):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"Row {0}: Total Number of Depreciations cannot be less than or equal to Number of Depreciations Booked"
|
"Row {0}: Total Number of Depreciations cannot be less than or equal to Opening Number of Booked Depreciations"
|
||||||
).format(row.idx),
|
).format(row.idx),
|
||||||
title=_("Invalid Schedule"),
|
title=_("Invalid Schedule"),
|
||||||
)
|
)
|
||||||
@@ -459,6 +459,17 @@ class Asset(AccountsController):
|
|||||||
).format(row.idx)
|
).format(row.idx)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_total_booked_depreciations(self):
|
||||||
|
# set value of total number of booked depreciations field
|
||||||
|
for fb_row in self.get("finance_books"):
|
||||||
|
total_number_of_booked_depreciations = self.opening_number_of_booked_depreciations
|
||||||
|
depr_schedule = get_depr_schedule(self.name, "Active", fb_row.finance_book)
|
||||||
|
if depr_schedule:
|
||||||
|
for je in depr_schedule:
|
||||||
|
if je.journal_entry:
|
||||||
|
total_number_of_booked_depreciations += 1
|
||||||
|
fb_row.db_set("total_number_of_booked_depreciations", total_number_of_booked_depreciations)
|
||||||
|
|
||||||
def validate_expected_value_after_useful_life(self):
|
def validate_expected_value_after_useful_life(self):
|
||||||
for row in self.get("finance_books"):
|
for row in self.get("finance_books"):
|
||||||
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)
|
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)
|
||||||
|
|||||||
@@ -323,6 +323,7 @@ def _make_journal_entry_for_depreciation(
|
|||||||
|
|
||||||
if not je.meta.get_workflow():
|
if not je.meta.get_workflow():
|
||||||
je.submit()
|
je.submit()
|
||||||
|
asset.reload()
|
||||||
idx = cint(asset_depr_schedule_doc.finance_book_id)
|
idx = cint(asset_depr_schedule_doc.finance_book_id)
|
||||||
row = asset.get("finance_books")[idx - 1]
|
row = asset.get("finance_books")[idx - 1]
|
||||||
row.value_after_depreciation -= depr_schedule.depreciation_amount
|
row.value_after_depreciation -= depr_schedule.depreciation_amount
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ class TestAsset(AssetSetup):
|
|||||||
purchase_date="2020-04-01",
|
purchase_date="2020-04-01",
|
||||||
expected_value_after_useful_life=0,
|
expected_value_after_useful_life=0,
|
||||||
total_number_of_depreciations=5,
|
total_number_of_depreciations=5,
|
||||||
number_of_depreciations_booked=2,
|
opening_number_of_booked_depreciations=2,
|
||||||
frequency_of_depreciation=12,
|
frequency_of_depreciation=12,
|
||||||
depreciation_start_date="2023-03-31",
|
depreciation_start_date="2023-03-31",
|
||||||
opening_accumulated_depreciation=24000,
|
opening_accumulated_depreciation=24000,
|
||||||
@@ -453,7 +453,7 @@ class TestAsset(AssetSetup):
|
|||||||
purchase_date="2020-01-01",
|
purchase_date="2020-01-01",
|
||||||
expected_value_after_useful_life=0,
|
expected_value_after_useful_life=0,
|
||||||
total_number_of_depreciations=6,
|
total_number_of_depreciations=6,
|
||||||
number_of_depreciations_booked=1,
|
opening_number_of_booked_depreciations=1,
|
||||||
frequency_of_depreciation=10,
|
frequency_of_depreciation=10,
|
||||||
depreciation_start_date="2021-01-01",
|
depreciation_start_date="2021-01-01",
|
||||||
opening_accumulated_depreciation=20000,
|
opening_accumulated_depreciation=20000,
|
||||||
@@ -739,7 +739,7 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
calculate_depreciation=1,
|
calculate_depreciation=1,
|
||||||
available_for_use_date="2030-06-06",
|
available_for_use_date="2030-06-06",
|
||||||
is_existing_asset=1,
|
is_existing_asset=1,
|
||||||
number_of_depreciations_booked=2,
|
opening_number_of_booked_depreciations=2,
|
||||||
opening_accumulated_depreciation=47095.89,
|
opening_accumulated_depreciation=47095.89,
|
||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2032-12-31",
|
depreciation_start_date="2032-12-31",
|
||||||
@@ -789,7 +789,7 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
available_for_use_date="2030-01-01",
|
available_for_use_date="2030-01-01",
|
||||||
is_existing_asset=1,
|
is_existing_asset=1,
|
||||||
depreciation_method="Double Declining Balance",
|
depreciation_method="Double Declining Balance",
|
||||||
number_of_depreciations_booked=1,
|
opening_number_of_booked_depreciations=1,
|
||||||
opening_accumulated_depreciation=50000,
|
opening_accumulated_depreciation=50000,
|
||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2031-12-31",
|
depreciation_start_date="2031-12-31",
|
||||||
@@ -1123,8 +1123,8 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, asset.save)
|
self.assertRaises(frappe.ValidationError, asset.save)
|
||||||
|
|
||||||
def test_number_of_depreciations_booked(self):
|
def test_opening_booked_depreciations(self):
|
||||||
"""Tests if an error is raised when number_of_depreciations_booked is not specified when opening_accumulated_depreciation is."""
|
"""Tests if an error is raised when opening_number_of_booked_depreciations is not specified when opening_accumulated_depreciation is."""
|
||||||
|
|
||||||
asset = create_asset(
|
asset = create_asset(
|
||||||
item_code="Macbook Pro",
|
item_code="Macbook Pro",
|
||||||
@@ -1140,9 +1140,9 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
self.assertRaises(frappe.ValidationError, asset.save)
|
self.assertRaises(frappe.ValidationError, asset.save)
|
||||||
|
|
||||||
def test_number_of_depreciations(self):
|
def test_number_of_depreciations(self):
|
||||||
"""Tests if an error is raised when number_of_depreciations_booked >= total_number_of_depreciations."""
|
"""Tests if an error is raised when opening_number_of_booked_depreciations >= total_number_of_depreciations."""
|
||||||
|
|
||||||
# number_of_depreciations_booked > total_number_of_depreciations
|
# opening_number_of_booked_depreciations > total_number_of_depreciations
|
||||||
asset = create_asset(
|
asset = create_asset(
|
||||||
item_code="Macbook Pro",
|
item_code="Macbook Pro",
|
||||||
calculate_depreciation=1,
|
calculate_depreciation=1,
|
||||||
@@ -1151,13 +1151,13 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2020-07-01",
|
depreciation_start_date="2020-07-01",
|
||||||
opening_accumulated_depreciation=10000,
|
opening_accumulated_depreciation=10000,
|
||||||
number_of_depreciations_booked=5,
|
opening_number_of_booked_depreciations=5,
|
||||||
do_not_save=1,
|
do_not_save=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, asset.save)
|
self.assertRaises(frappe.ValidationError, asset.save)
|
||||||
|
|
||||||
# number_of_depreciations_booked = total_number_of_depreciations
|
# opening_number_of_booked_depreciations = total_number_of_depreciations
|
||||||
asset_2 = create_asset(
|
asset_2 = create_asset(
|
||||||
item_code="Macbook Pro",
|
item_code="Macbook Pro",
|
||||||
calculate_depreciation=1,
|
calculate_depreciation=1,
|
||||||
@@ -1166,7 +1166,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2020-07-01",
|
depreciation_start_date="2020-07-01",
|
||||||
opening_accumulated_depreciation=10000,
|
opening_accumulated_depreciation=10000,
|
||||||
number_of_depreciations_booked=5,
|
opening_number_of_booked_depreciations=5,
|
||||||
do_not_save=1,
|
do_not_save=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1502,7 +1502,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
|
|
||||||
asset = create_asset(calculate_depreciation=1)
|
asset = create_asset(calculate_depreciation=1)
|
||||||
asset.opening_accumulated_depreciation = 2000
|
asset.opening_accumulated_depreciation = 2000
|
||||||
asset.number_of_depreciations_booked = 1
|
asset.opening_number_of_booked_depreciations = 1
|
||||||
|
|
||||||
asset.finance_books[0].expected_value_after_useful_life = 100
|
asset.finance_books[0].expected_value_after_useful_life = 100
|
||||||
asset.save()
|
asset.save()
|
||||||
@@ -1696,7 +1696,7 @@ def create_asset(**args):
|
|||||||
"purchase_date": args.purchase_date or "2015-01-01",
|
"purchase_date": args.purchase_date or "2015-01-01",
|
||||||
"calculate_depreciation": args.calculate_depreciation or 0,
|
"calculate_depreciation": args.calculate_depreciation or 0,
|
||||||
"opening_accumulated_depreciation": args.opening_accumulated_depreciation or 0,
|
"opening_accumulated_depreciation": args.opening_accumulated_depreciation or 0,
|
||||||
"number_of_depreciations_booked": args.number_of_depreciations_booked or 0,
|
"opening_number_of_booked_depreciations": args.opening_number_of_booked_depreciations or 0,
|
||||||
"gross_purchase_amount": args.gross_purchase_amount or 100000,
|
"gross_purchase_amount": args.gross_purchase_amount or 100000,
|
||||||
"purchase_amount": args.purchase_amount or 100000,
|
"purchase_amount": args.purchase_amount or 100000,
|
||||||
"maintenance_required": args.maintenance_required or 0,
|
"maintenance_required": args.maintenance_required or 0,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"column_break_2",
|
"column_break_2",
|
||||||
"gross_purchase_amount",
|
"gross_purchase_amount",
|
||||||
"opening_accumulated_depreciation",
|
"opening_accumulated_depreciation",
|
||||||
"number_of_depreciations_booked",
|
"opening_number_of_booked_depreciations",
|
||||||
"finance_book",
|
"finance_book",
|
||||||
"finance_book_id",
|
"finance_book_id",
|
||||||
"depreciation_details_section",
|
"depreciation_details_section",
|
||||||
@@ -171,10 +171,10 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "number_of_depreciations_booked",
|
"fieldname": "opening_number_of_booked_depreciations",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Number of Depreciations Booked",
|
"label": "Opening Number of Booked Depreciations",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
gross_purchase_amount: DF.Currency
|
gross_purchase_amount: DF.Currency
|
||||||
naming_series: DF.Literal["ACC-ADS-.YYYY.-"]
|
naming_series: DF.Literal["ACC-ADS-.YYYY.-"]
|
||||||
notes: DF.SmallText | None
|
notes: DF.SmallText | None
|
||||||
number_of_depreciations_booked: DF.Int
|
opening_number_of_booked_depreciations: DF.Int
|
||||||
opening_accumulated_depreciation: DF.Currency
|
opening_accumulated_depreciation: DF.Currency
|
||||||
rate_of_depreciation: DF.Percent
|
rate_of_depreciation: DF.Percent
|
||||||
shift_based: DF.Check
|
shift_based: DF.Check
|
||||||
@@ -161,7 +161,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
return (
|
return (
|
||||||
asset_doc.gross_purchase_amount != self.gross_purchase_amount
|
asset_doc.gross_purchase_amount != self.gross_purchase_amount
|
||||||
or asset_doc.opening_accumulated_depreciation != self.opening_accumulated_depreciation
|
or asset_doc.opening_accumulated_depreciation != self.opening_accumulated_depreciation
|
||||||
or asset_doc.number_of_depreciations_booked != self.number_of_depreciations_booked
|
or asset_doc.opening_number_of_booked_depreciations != self.opening_number_of_booked_depreciations
|
||||||
)
|
)
|
||||||
|
|
||||||
def not_manual_depr_or_have_manual_depr_details_been_modified(self, row):
|
def not_manual_depr_or_have_manual_depr_details_been_modified(self, row):
|
||||||
@@ -194,7 +194,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
self.finance_book = row.finance_book
|
self.finance_book = row.finance_book
|
||||||
self.finance_book_id = row.idx
|
self.finance_book_id = row.idx
|
||||||
self.opening_accumulated_depreciation = asset_doc.opening_accumulated_depreciation or 0
|
self.opening_accumulated_depreciation = asset_doc.opening_accumulated_depreciation or 0
|
||||||
self.number_of_depreciations_booked = asset_doc.number_of_depreciations_booked or 0
|
self.opening_number_of_booked_depreciations = asset_doc.opening_number_of_booked_depreciations or 0
|
||||||
self.gross_purchase_amount = asset_doc.gross_purchase_amount
|
self.gross_purchase_amount = asset_doc.gross_purchase_amount
|
||||||
self.depreciation_method = row.depreciation_method
|
self.depreciation_method = row.depreciation_method
|
||||||
self.total_number_of_depreciations = row.total_number_of_depreciations
|
self.total_number_of_depreciations = row.total_number_of_depreciations
|
||||||
@@ -263,7 +263,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
row.db_update()
|
row.db_update()
|
||||||
|
|
||||||
final_number_of_depreciations = cint(row.total_number_of_depreciations) - cint(
|
final_number_of_depreciations = cint(row.total_number_of_depreciations) - cint(
|
||||||
self.number_of_depreciations_booked
|
self.opening_number_of_booked_depreciations
|
||||||
)
|
)
|
||||||
|
|
||||||
has_pro_rata = _check_is_pro_rata(asset_doc, row)
|
has_pro_rata = _check_is_pro_rata(asset_doc, row)
|
||||||
@@ -328,7 +328,7 @@ class AssetDepreciationSchedule(Document):
|
|||||||
if date_of_disposal and getdate(schedule_date) >= getdate(date_of_disposal):
|
if date_of_disposal and getdate(schedule_date) >= getdate(date_of_disposal):
|
||||||
from_date = add_months(
|
from_date = add_months(
|
||||||
getdate(asset_doc.available_for_use_date),
|
getdate(asset_doc.available_for_use_date),
|
||||||
(asset_doc.number_of_depreciations_booked * row.frequency_of_depreciation),
|
(asset_doc.opening_number_of_booked_depreciations * row.frequency_of_depreciation),
|
||||||
)
|
)
|
||||||
if self.depreciation_schedule:
|
if self.depreciation_schedule:
|
||||||
from_date = self.depreciation_schedule[-1].schedule_date
|
from_date = self.depreciation_schedule[-1].schedule_date
|
||||||
@@ -378,13 +378,16 @@ class AssetDepreciationSchedule(Document):
|
|||||||
from_date = get_last_day(
|
from_date = get_last_day(
|
||||||
add_months(
|
add_months(
|
||||||
getdate(asset_doc.available_for_use_date),
|
getdate(asset_doc.available_for_use_date),
|
||||||
((self.number_of_depreciations_booked - 1) * row.frequency_of_depreciation),
|
(
|
||||||
|
(self.opening_number_of_booked_depreciations - 1)
|
||||||
|
* row.frequency_of_depreciation
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
from_date = add_months(
|
from_date = add_months(
|
||||||
getdate(add_days(asset_doc.available_for_use_date, -1)),
|
getdate(add_days(asset_doc.available_for_use_date, -1)),
|
||||||
(self.number_of_depreciations_booked * row.frequency_of_depreciation),
|
(self.opening_number_of_booked_depreciations * row.frequency_of_depreciation),
|
||||||
)
|
)
|
||||||
depreciation_amount, days, months = _get_pro_rata_amt(
|
depreciation_amount, days, months = _get_pro_rata_amt(
|
||||||
row,
|
row,
|
||||||
@@ -400,7 +403,8 @@ class AssetDepreciationSchedule(Document):
|
|||||||
# In case of increase_in_asset_life, the asset.to_date is already set on asset_repair submission
|
# In case of increase_in_asset_life, the asset.to_date is already set on asset_repair submission
|
||||||
asset_doc.to_date = add_months(
|
asset_doc.to_date = add_months(
|
||||||
asset_doc.available_for_use_date,
|
asset_doc.available_for_use_date,
|
||||||
(n + self.number_of_depreciations_booked) * cint(row.frequency_of_depreciation),
|
(n + self.opening_number_of_booked_depreciations)
|
||||||
|
* cint(row.frequency_of_depreciation),
|
||||||
)
|
)
|
||||||
|
|
||||||
depreciation_amount_without_pro_rata = depreciation_amount
|
depreciation_amount_without_pro_rata = depreciation_amount
|
||||||
@@ -546,7 +550,7 @@ def _check_is_pro_rata(asset_doc, row, wdv_or_dd_non_yearly=False):
|
|||||||
has_pro_rata = False
|
has_pro_rata = False
|
||||||
|
|
||||||
# if not existing asset, from_date = available_for_use_date
|
# if not existing asset, from_date = available_for_use_date
|
||||||
# otherwise, if number_of_depreciations_booked = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12
|
# otherwise, if opening_number_of_booked_depreciations = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12
|
||||||
# from_date = 01/01/2022
|
# from_date = 01/01/2022
|
||||||
from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly)
|
from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly)
|
||||||
days = date_diff(row.depreciation_start_date, from_date) + 1
|
days = date_diff(row.depreciation_start_date, from_date) + 1
|
||||||
@@ -567,12 +571,12 @@ def _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly=Fa
|
|||||||
if wdv_or_dd_non_yearly:
|
if wdv_or_dd_non_yearly:
|
||||||
return add_months(
|
return add_months(
|
||||||
asset_doc.available_for_use_date,
|
asset_doc.available_for_use_date,
|
||||||
(asset_doc.number_of_depreciations_booked * 12),
|
(asset_doc.opening_number_of_booked_depreciations * 12),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return add_months(
|
return add_months(
|
||||||
asset_doc.available_for_use_date,
|
asset_doc.available_for_use_date,
|
||||||
(asset_doc.number_of_depreciations_booked * row.frequency_of_depreciation),
|
(asset_doc.opening_number_of_booked_depreciations * row.frequency_of_depreciation),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -678,7 +682,7 @@ def get_straight_line_or_manual_depr_amount(
|
|||||||
flt(asset.gross_purchase_amount)
|
flt(asset.gross_purchase_amount)
|
||||||
- flt(asset.opening_accumulated_depreciation)
|
- flt(asset.opening_accumulated_depreciation)
|
||||||
- flt(row.expected_value_after_useful_life)
|
- flt(row.expected_value_after_useful_life)
|
||||||
) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
|
) / flt(row.total_number_of_depreciations - asset.opening_number_of_booked_depreciations)
|
||||||
|
|
||||||
|
|
||||||
def get_daily_prorata_based_straight_line_depr(
|
def get_daily_prorata_based_straight_line_depr(
|
||||||
@@ -704,7 +708,7 @@ def get_shift_depr_amount(asset_depr_schedule, asset, row, schedule_idx):
|
|||||||
flt(asset.gross_purchase_amount)
|
flt(asset.gross_purchase_amount)
|
||||||
- flt(asset.opening_accumulated_depreciation)
|
- flt(asset.opening_accumulated_depreciation)
|
||||||
- flt(row.expected_value_after_useful_life)
|
- flt(row.expected_value_after_useful_life)
|
||||||
) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
|
) / flt(row.total_number_of_depreciations - asset.opening_number_of_booked_depreciations)
|
||||||
|
|
||||||
asset_shift_factors_map = get_asset_shift_factors_map()
|
asset_shift_factors_map = get_asset_shift_factors_map()
|
||||||
shift = (
|
shift = (
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import frappe
|
|||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import cstr
|
from frappe.utils import cstr
|
||||||
|
|
||||||
|
from erpnext.assets.doctype.asset.depreciation import (
|
||||||
|
post_depreciation_entries,
|
||||||
|
)
|
||||||
from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data
|
from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data
|
||||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||||
get_asset_depr_schedule_doc,
|
get_asset_depr_schedule_doc,
|
||||||
@@ -28,7 +31,7 @@ class TestAssetDepreciationSchedule(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, second_asset_depr_schedule.insert)
|
self.assertRaises(frappe.ValidationError, second_asset_depr_schedule.insert)
|
||||||
|
|
||||||
def test_daily_prorata_based_depr_on_sl_methond(self):
|
def test_daily_prorata_based_depr_on_sl_method(self):
|
||||||
asset = create_asset(
|
asset = create_asset(
|
||||||
calculate_depreciation=1,
|
calculate_depreciation=1,
|
||||||
depreciation_method="Straight Line",
|
depreciation_method="Straight Line",
|
||||||
@@ -160,3 +163,35 @@ class TestAssetDepreciationSchedule(FrappeTestCase):
|
|||||||
for d in get_depr_schedule(asset.name, "Draft")
|
for d in get_depr_schedule(asset.name, "Draft")
|
||||||
]
|
]
|
||||||
self.assertEqual(schedules, expected_schedules)
|
self.assertEqual(schedules, expected_schedules)
|
||||||
|
|
||||||
|
def test_update_total_number_of_booked_depreciations(self):
|
||||||
|
# check if updates total number of booked depreciations when depreciation gets booked
|
||||||
|
asset = create_asset(
|
||||||
|
item_code="Macbook Pro",
|
||||||
|
calculate_depreciation=1,
|
||||||
|
opening_accumulated_depreciation=2000,
|
||||||
|
opening_number_of_booked_depreciations=2,
|
||||||
|
depreciation_method="Straight Line",
|
||||||
|
available_for_use_date="2020-03-01",
|
||||||
|
depreciation_start_date="2020-03-31",
|
||||||
|
frequency_of_depreciation=1,
|
||||||
|
total_number_of_depreciations=24,
|
||||||
|
submit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
post_depreciation_entries(date="2021-03-31")
|
||||||
|
asset.reload()
|
||||||
|
"""
|
||||||
|
opening_number_of_booked_depreciations = 2
|
||||||
|
number_of_booked_depreciations till 2021-03-31 = 13
|
||||||
|
total_number_of_booked_depreciations = 15
|
||||||
|
"""
|
||||||
|
self.assertEqual(asset.finance_books[0].total_number_of_booked_depreciations, 15)
|
||||||
|
|
||||||
|
# cancel depreciation entry
|
||||||
|
depr_entry = get_depr_schedule(asset.name, "Active")[0].journal_entry
|
||||||
|
|
||||||
|
frappe.get_doc("Journal Entry", depr_entry).cancel()
|
||||||
|
asset.reload()
|
||||||
|
|
||||||
|
self.assertEqual(asset.finance_books[0].total_number_of_booked_depreciations, 14)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"finance_book",
|
"finance_book",
|
||||||
"depreciation_method",
|
"depreciation_method",
|
||||||
"total_number_of_depreciations",
|
"total_number_of_depreciations",
|
||||||
|
"total_number_of_booked_depreciations",
|
||||||
"daily_prorata_based",
|
"daily_prorata_based",
|
||||||
"shift_based",
|
"shift_based",
|
||||||
"column_break_5",
|
"column_break_5",
|
||||||
@@ -104,12 +105,19 @@
|
|||||||
"fieldname": "shift_based",
|
"fieldname": "shift_based",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Depreciate based on shifts"
|
"label": "Depreciate based on shifts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "total_number_of_booked_depreciations",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Total Number of Booked Depreciations ",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-03-27 13:06:34.342264",
|
"modified": "2024-05-21 15:48:20.907250",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset Finance Book",
|
"name": "Asset Finance Book",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class AssetFinanceBook(Document):
|
|||||||
rate_of_depreciation: DF.Percent
|
rate_of_depreciation: DF.Percent
|
||||||
salvage_value_percentage: DF.Percent
|
salvage_value_percentage: DF.Percent
|
||||||
shift_based: DF.Check
|
shift_based: DF.Check
|
||||||
|
total_number_of_booked_depreciations: DF.Int
|
||||||
total_number_of_depreciations: DF.Int
|
total_number_of_depreciations: DF.Int
|
||||||
value_after_depreciation: DF.Currency
|
value_after_depreciation: DF.Currency
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ class AssetRepair(AccountsController):
|
|||||||
def calculate_last_schedule_date(self, asset, row, extra_months):
|
def calculate_last_schedule_date(self, asset, row, extra_months):
|
||||||
asset.flags.increase_in_asset_life = True
|
asset.flags.increase_in_asset_life = True
|
||||||
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
||||||
asset.number_of_depreciations_booked
|
asset.opening_number_of_booked_depreciations
|
||||||
)
|
)
|
||||||
|
|
||||||
depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book)
|
depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book)
|
||||||
@@ -410,7 +410,7 @@ class AssetRepair(AccountsController):
|
|||||||
def calculate_last_schedule_date_before_modification(self, asset, row, extra_months):
|
def calculate_last_schedule_date_before_modification(self, asset, row, extra_months):
|
||||||
asset.flags.increase_in_asset_life = True
|
asset.flags.increase_in_asset_life = True
|
||||||
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
||||||
asset.number_of_depreciations_booked
|
asset.opening_number_of_booked_depreciations
|
||||||
)
|
)
|
||||||
|
|
||||||
depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book)
|
depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book)
|
||||||
|
|||||||
@@ -367,3 +367,4 @@ erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset
|
|||||||
erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency
|
erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency
|
||||||
erpnext.patches.v15_0.rename_purchase_receipt_amount_to_purchase_amount
|
erpnext.patches.v15_0.rename_purchase_receipt_amount_to_purchase_amount
|
||||||
erpnext.patches.v14_0.enable_set_priority_for_pricing_rules #1
|
erpnext.patches.v14_0.enable_set_priority_for_pricing_rules #1
|
||||||
|
erpnext.patches.v15_0.rename_number_of_depreciations_booked_to_opening_booked_depreciations
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def get_details_of_draft_or_submitted_depreciable_assets():
|
|||||||
asset.name,
|
asset.name,
|
||||||
asset.opening_accumulated_depreciation,
|
asset.opening_accumulated_depreciation,
|
||||||
asset.gross_purchase_amount,
|
asset.gross_purchase_amount,
|
||||||
asset.number_of_depreciations_booked,
|
asset.opening_number_of_booked_depreciations,
|
||||||
asset.docstatus,
|
asset.docstatus,
|
||||||
)
|
)
|
||||||
.where(asset.calculate_depreciation == 1)
|
.where(asset.calculate_depreciation == 1)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import frappe
|
||||||
|
from frappe.model.utils.rename_field import rename_field
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
if frappe.db.has_column("Asset", "number_of_depreciations_booked"):
|
||||||
|
rename_field("Asset", "number_of_depreciations_booked", "opening_number_of_booked_depreciations")
|
||||||
@@ -9,12 +9,12 @@ def execute():
|
|||||||
ON `tabAsset Depreciation Schedule`.`asset`=`tabAsset`.`name`
|
ON `tabAsset Depreciation Schedule`.`asset`=`tabAsset`.`name`
|
||||||
SET
|
SET
|
||||||
`tabAsset Depreciation Schedule`.`gross_purchase_amount`=`tabAsset`.`gross_purchase_amount`,
|
`tabAsset Depreciation Schedule`.`gross_purchase_amount`=`tabAsset`.`gross_purchase_amount`,
|
||||||
`tabAsset Depreciation Schedule`.`number_of_depreciations_booked`=`tabAsset`.`number_of_depreciations_booked`
|
`tabAsset Depreciation Schedule`.`opening_number_of_booked_depreciations`=`tabAsset`.`opening_number_of_booked_depreciations`
|
||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
`tabAsset Depreciation Schedule`.`gross_purchase_amount`<>`tabAsset`.`gross_purchase_amount`
|
`tabAsset Depreciation Schedule`.`gross_purchase_amount`<>`tabAsset`.`gross_purchase_amount`
|
||||||
OR
|
OR
|
||||||
`tabAsset Depreciation Schedule`.`number_of_depreciations_booked`<>`tabAsset`.`number_of_depreciations_booked`
|
`tabAsset Depreciation Schedule`.`opening_number_of_booked_depreciations`<>`tabAsset`.`opening_number_of_booked_depreciations`
|
||||||
)
|
)
|
||||||
AND `tabAsset Depreciation Schedule`.`docstatus`<2"""
|
AND `tabAsset Depreciation Schedule`.`docstatus`<2"""
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user