chore: remove some unwanted functions in asset
This commit is contained in:
parent
710d2452b7
commit
97ab7bd36b
@ -89,7 +89,7 @@ class Asset(AccountsController):
|
|||||||
_("Purchase Invoice cannot be made against an existing asset {0}").format(self.name)
|
_("Purchase Invoice cannot be made against an existing asset {0}").format(self.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare_depreciation_data(self, date_of_disposal=None, date_of_return=None):
|
def prepare_depreciation_data(self):
|
||||||
if self.calculate_depreciation:
|
if self.calculate_depreciation:
|
||||||
self.value_after_depreciation = 0
|
self.value_after_depreciation = 0
|
||||||
self.set_depreciation_rate()
|
self.set_depreciation_rate()
|
||||||
@ -231,148 +231,6 @@ class Asset(AccountsController):
|
|||||||
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
|
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_depreciation_schedule(self, date_of_disposal):
|
|
||||||
if "Manual" not in [d.depreciation_method for d in self.finance_books] and not self.get(
|
|
||||||
"schedules"
|
|
||||||
):
|
|
||||||
self.schedules = []
|
|
||||||
|
|
||||||
if not self.available_for_use_date:
|
|
||||||
return
|
|
||||||
|
|
||||||
start = self.clear_depreciation_schedule()
|
|
||||||
|
|
||||||
for finance_book in self.get("finance_books"):
|
|
||||||
self._make_depreciation_schedule(finance_book, start, date_of_disposal)
|
|
||||||
|
|
||||||
def _make_depreciation_schedule(self, finance_book, start, date_of_disposal):
|
|
||||||
self.validate_asset_finance_books(finance_book)
|
|
||||||
|
|
||||||
value_after_depreciation = self._get_value_after_depreciation(finance_book)
|
|
||||||
finance_book.value_after_depreciation = value_after_depreciation
|
|
||||||
|
|
||||||
number_of_pending_depreciations = cint(finance_book.total_number_of_depreciations) - cint(
|
|
||||||
self.number_of_depreciations_booked
|
|
||||||
)
|
|
||||||
|
|
||||||
has_pro_rata = self.check_is_pro_rata(finance_book)
|
|
||||||
if has_pro_rata:
|
|
||||||
number_of_pending_depreciations += 1
|
|
||||||
|
|
||||||
skip_row = False
|
|
||||||
should_get_last_day = is_last_day_of_the_month(finance_book.depreciation_start_date)
|
|
||||||
|
|
||||||
for n in range(start[finance_book.idx - 1], number_of_pending_depreciations):
|
|
||||||
# If depreciation is already completed (for double declining balance)
|
|
||||||
if skip_row:
|
|
||||||
continue
|
|
||||||
|
|
||||||
depreciation_amount = get_depreciation_amount(self, value_after_depreciation, finance_book)
|
|
||||||
|
|
||||||
if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1:
|
|
||||||
schedule_date = add_months(
|
|
||||||
finance_book.depreciation_start_date, n * cint(finance_book.frequency_of_depreciation)
|
|
||||||
)
|
|
||||||
|
|
||||||
if should_get_last_day:
|
|
||||||
schedule_date = get_last_day(schedule_date)
|
|
||||||
|
|
||||||
# schedule date will be a year later from start date
|
|
||||||
# so monthly schedule date is calculated by removing 11 months from it
|
|
||||||
monthly_schedule_date = add_months(schedule_date, -finance_book.frequency_of_depreciation + 1)
|
|
||||||
|
|
||||||
# if asset is being sold
|
|
||||||
if date_of_disposal:
|
|
||||||
from_date = self.get_from_date(finance_book.finance_book)
|
|
||||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
|
||||||
finance_book, depreciation_amount, from_date, date_of_disposal
|
|
||||||
)
|
|
||||||
|
|
||||||
if depreciation_amount > 0:
|
|
||||||
self._add_depreciation_row(
|
|
||||||
date_of_disposal,
|
|
||||||
depreciation_amount,
|
|
||||||
finance_book.depreciation_method,
|
|
||||||
finance_book.finance_book,
|
|
||||||
finance_book.idx,
|
|
||||||
)
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
# For first row
|
|
||||||
if has_pro_rata and not self.opening_accumulated_depreciation and n == 0:
|
|
||||||
from_date = add_days(
|
|
||||||
self.available_for_use_date, -1
|
|
||||||
) # needed to calc depr amount for available_for_use_date too
|
|
||||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
|
||||||
finance_book, depreciation_amount, from_date, finance_book.depreciation_start_date
|
|
||||||
)
|
|
||||||
|
|
||||||
# For first depr schedule date will be the start date
|
|
||||||
# so monthly schedule date is calculated by removing month difference between use date and start date
|
|
||||||
monthly_schedule_date = add_months(finance_book.depreciation_start_date, -months + 1)
|
|
||||||
|
|
||||||
# For last row
|
|
||||||
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
|
|
||||||
if not self.flags.increase_in_asset_life:
|
|
||||||
# In case of increase_in_asset_life, the self.to_date is already set on asset_repair submission
|
|
||||||
self.to_date = add_months(
|
|
||||||
self.available_for_use_date,
|
|
||||||
(n + self.number_of_depreciations_booked) * cint(finance_book.frequency_of_depreciation),
|
|
||||||
)
|
|
||||||
|
|
||||||
depreciation_amount_without_pro_rata = depreciation_amount
|
|
||||||
|
|
||||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
|
||||||
finance_book, depreciation_amount, schedule_date, self.to_date
|
|
||||||
)
|
|
||||||
|
|
||||||
depreciation_amount = self.get_adjusted_depreciation_amount(
|
|
||||||
depreciation_amount_without_pro_rata, depreciation_amount, finance_book.finance_book
|
|
||||||
)
|
|
||||||
|
|
||||||
monthly_schedule_date = add_months(schedule_date, 1)
|
|
||||||
schedule_date = add_days(schedule_date, days)
|
|
||||||
last_schedule_date = schedule_date
|
|
||||||
|
|
||||||
if not depreciation_amount:
|
|
||||||
continue
|
|
||||||
value_after_depreciation -= flt(depreciation_amount, self.precision("gross_purchase_amount"))
|
|
||||||
|
|
||||||
# Adjust depreciation amount in the last period based on the expected value after useful life
|
|
||||||
if finance_book.expected_value_after_useful_life and (
|
|
||||||
(
|
|
||||||
n == cint(number_of_pending_depreciations) - 1
|
|
||||||
and value_after_depreciation != finance_book.expected_value_after_useful_life
|
|
||||||
)
|
|
||||||
or value_after_depreciation < finance_book.expected_value_after_useful_life
|
|
||||||
):
|
|
||||||
depreciation_amount += value_after_depreciation - finance_book.expected_value_after_useful_life
|
|
||||||
skip_row = True
|
|
||||||
|
|
||||||
if depreciation_amount > 0:
|
|
||||||
self._add_depreciation_row(
|
|
||||||
schedule_date,
|
|
||||||
depreciation_amount,
|
|
||||||
finance_book.depreciation_method,
|
|
||||||
finance_book.finance_book,
|
|
||||||
finance_book.idx,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _add_depreciation_row(
|
|
||||||
self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id
|
|
||||||
):
|
|
||||||
self.append(
|
|
||||||
"schedules",
|
|
||||||
{
|
|
||||||
"schedule_date": schedule_date,
|
|
||||||
"depreciation_amount": depreciation_amount,
|
|
||||||
"depreciation_method": depreciation_method,
|
|
||||||
"finance_book": finance_book,
|
|
||||||
"finance_book_id": finance_book_id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_value_after_depreciation(self, finance_book):
|
def _get_value_after_depreciation(self, finance_book):
|
||||||
# value_after_depreciation - current Asset value
|
# value_after_depreciation - current Asset value
|
||||||
if self.docstatus == 1 and finance_book.value_after_depreciation:
|
if self.docstatus == 1 and finance_book.value_after_depreciation:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user