fix: Pro rata calculation is not working for WDV depreciation method
This commit is contained in:
parent
06c7a7e660
commit
3844a98c42
@ -303,14 +303,17 @@ frappe.ui.form.on('Asset', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
set_depreciation_rate: function(frm, row) {
|
set_depreciation_rate: function(frm, row) {
|
||||||
if (row.total_number_of_depreciations && row.frequency_of_depreciation) {
|
if (row.total_number_of_depreciations && row.frequency_of_depreciation
|
||||||
|
&& row.expected_value_after_useful_life) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "get_depreciation_rate",
|
method: "get_depreciation_rate",
|
||||||
doc: frm.doc,
|
doc: frm.doc,
|
||||||
args: row,
|
args: row,
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
frappe.model.set_value(row.doctype, row.name, "rate_of_depreciation", r.message);
|
frappe.flags.dont_change_rate = true;
|
||||||
|
frappe.model.set_value(row.doctype, row.name,
|
||||||
|
"rate_of_depreciation", flt(r.message, precision("rate_of_depreciation", row)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -338,6 +341,14 @@ frappe.ui.form.on('Asset Finance Book', {
|
|||||||
total_number_of_depreciations: function(frm, cdt, cdn) {
|
total_number_of_depreciations: function(frm, cdt, cdn) {
|
||||||
const row = locals[cdt][cdn];
|
const row = locals[cdt][cdn];
|
||||||
frm.events.set_depreciation_rate(frm, row);
|
frm.events.set_depreciation_rate(frm, row);
|
||||||
|
},
|
||||||
|
|
||||||
|
rate_of_depreciation: function(frm, cdt, cdn) {
|
||||||
|
if(!frappe.flags.dont_change_rate) {
|
||||||
|
frappe.model.set_value(cdt, cdn, "expected_value_after_useful_life", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
frappe.flags.dont_change_rate = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -101,7 +101,8 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
def set_depreciation_rate(self):
|
def set_depreciation_rate(self):
|
||||||
for d in self.get("finance_books"):
|
for d in self.get("finance_books"):
|
||||||
d.rate_of_depreciation = self.get_depreciation_rate(d, on_validate=True)
|
d.rate_of_depreciation = flt(self.get_depreciation_rate(d, on_validate=True),
|
||||||
|
d.precision("rate_of_depreciation"))
|
||||||
|
|
||||||
def make_depreciation_schedule(self):
|
def make_depreciation_schedule(self):
|
||||||
depreciation_method = [d.depreciation_method for d in self.finance_books]
|
depreciation_method = [d.depreciation_method for d in self.finance_books]
|
||||||
@ -110,8 +111,6 @@ class Asset(AccountsController):
|
|||||||
self.schedules = []
|
self.schedules = []
|
||||||
|
|
||||||
if not self.get("schedules") and self.available_for_use_date:
|
if not self.get("schedules") and self.available_for_use_date:
|
||||||
total_depreciations = sum([d.total_number_of_depreciations for d in self.get('finance_books')])
|
|
||||||
|
|
||||||
for d in self.get('finance_books'):
|
for d in self.get('finance_books'):
|
||||||
self.validate_asset_finance_books(d)
|
self.validate_asset_finance_books(d)
|
||||||
|
|
||||||
@ -124,6 +123,7 @@ class Asset(AccountsController):
|
|||||||
end_date = add_months(d.depreciation_start_date,
|
end_date = add_months(d.depreciation_start_date,
|
||||||
no_of_depreciations * cint(d.frequency_of_depreciation))
|
no_of_depreciations * cint(d.frequency_of_depreciation))
|
||||||
|
|
||||||
|
if d.depreciation_method in ("Straight Line", "Manual"):
|
||||||
total_days = date_diff(end_date, self.available_for_use_date)
|
total_days = date_diff(end_date, self.available_for_use_date)
|
||||||
rate_per_day = (value_after_depreciation - d.get("expected_value_after_useful_life")) / total_days
|
rate_per_day = (value_after_depreciation - d.get("expected_value_after_useful_life")) / total_days
|
||||||
|
|
||||||
@ -132,58 +132,38 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
from_date = self.available_for_use_date
|
from_date = self.available_for_use_date
|
||||||
if number_of_pending_depreciations:
|
if number_of_pending_depreciations:
|
||||||
next_depr_date = getdate(add_months(self.available_for_use_date,
|
period_start_date = add_months(d.depreciation_start_date,
|
||||||
number_of_pending_depreciations * 12))
|
cint(d.frequency_of_depreciation) * -1)
|
||||||
if (cint(frappe.db.get_value("Asset Settings", None, "schedule_based_on_fiscal_year")) == 1
|
|
||||||
and getdate(d.depreciation_start_date) < next_depr_date):
|
|
||||||
|
|
||||||
number_of_pending_depreciations += 1
|
|
||||||
for n in range(number_of_pending_depreciations):
|
|
||||||
if n == list(range(number_of_pending_depreciations))[-1]:
|
|
||||||
schedule_date = add_months(self.available_for_use_date, n * 12)
|
|
||||||
previous_scheduled_date = add_months(d.depreciation_start_date, (n-1) * 12)
|
|
||||||
depreciation_amount = \
|
|
||||||
self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
|
|
||||||
d, previous_scheduled_date, schedule_date)
|
|
||||||
|
|
||||||
elif n == list(range(number_of_pending_depreciations))[0]:
|
|
||||||
schedule_date = d.depreciation_start_date
|
|
||||||
depreciation_amount = \
|
|
||||||
self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
|
|
||||||
d, self.available_for_use_date, schedule_date)
|
|
||||||
|
|
||||||
else:
|
|
||||||
schedule_date = add_months(d.depreciation_start_date, n * 12)
|
|
||||||
depreciation_amount = \
|
|
||||||
self.get_depreciation_amount_prorata_temporis(value_after_depreciation, d)
|
|
||||||
|
|
||||||
if value_after_depreciation != 0:
|
|
||||||
value_after_depreciation -= flt(depreciation_amount)
|
|
||||||
|
|
||||||
self.append("schedules", {
|
|
||||||
"schedule_date": schedule_date,
|
|
||||||
"depreciation_amount": depreciation_amount,
|
|
||||||
"depreciation_method": d.depreciation_method,
|
|
||||||
"finance_book": d.finance_book,
|
|
||||||
"finance_book_id": d.idx
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
for n in range(number_of_pending_depreciations):
|
for n in range(number_of_pending_depreciations):
|
||||||
schedule_date = add_months(d.depreciation_start_date,
|
schedule_date = add_months(d.depreciation_start_date,
|
||||||
n * cint(d.frequency_of_depreciation))
|
n * cint(d.frequency_of_depreciation))
|
||||||
|
|
||||||
if d.depreciation_method in ("Straight Line", "Manual"):
|
|
||||||
days = date_diff(schedule_date, from_date)
|
days = date_diff(schedule_date, from_date)
|
||||||
|
|
||||||
if n == 0: days += 1
|
if n == 0: days += 1
|
||||||
|
|
||||||
|
if d.depreciation_method in ("Straight Line", "Manual"):
|
||||||
depreciation_amount = days * rate_per_day
|
depreciation_amount = days * rate_per_day
|
||||||
from_date = schedule_date
|
|
||||||
else:
|
else:
|
||||||
|
total_days = date_diff(schedule_date, period_start_date)
|
||||||
|
period_start_date = schedule_date
|
||||||
depreciation_amount = self.get_depreciation_amount(value_after_depreciation,
|
depreciation_amount = self.get_depreciation_amount(value_after_depreciation,
|
||||||
d.total_number_of_depreciations, d)
|
d.total_number_of_depreciations, d)
|
||||||
|
|
||||||
|
depreciation_amount = flt((depreciation_amount * days) / total_days,
|
||||||
|
self.precision("gross_purchase_amount"))
|
||||||
|
|
||||||
|
from_date = schedule_date
|
||||||
|
|
||||||
if depreciation_amount:
|
if depreciation_amount:
|
||||||
value_after_depreciation -= flt(depreciation_amount)
|
value_after_depreciation -= flt(depreciation_amount,
|
||||||
|
self.precision("gross_purchase_amount"))
|
||||||
|
|
||||||
|
if (n == cint(number_of_pending_depreciations) - 1 and
|
||||||
|
d.expected_value_after_useful_life and
|
||||||
|
value_after_depreciation > d.expected_value_after_useful_life):
|
||||||
|
depreciation_amount += (value_after_depreciation - d.expected_value_after_useful_life)
|
||||||
|
|
||||||
self.append("schedules", {
|
self.append("schedules", {
|
||||||
"schedule_date": schedule_date,
|
"schedule_date": schedule_date,
|
||||||
@ -261,16 +241,8 @@ class Asset(AccountsController):
|
|||||||
return flt(self.get('finance_books')[cint(idx)-1].value_after_depreciation)
|
return flt(self.get('finance_books')[cint(idx)-1].value_after_depreciation)
|
||||||
|
|
||||||
def get_depreciation_amount(self, depreciable_value, total_number_of_depreciations, row):
|
def get_depreciation_amount(self, depreciable_value, total_number_of_depreciations, row):
|
||||||
if row.depreciation_method in ["Straight Line", "Manual"]:
|
precision = self.precision("gross_purchase_amount")
|
||||||
amt = (flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life) -
|
depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100), precision)
|
||||||
flt(self.opening_accumulated_depreciation))
|
|
||||||
|
|
||||||
depreciation_amount = amt * row.rate_of_depreciation
|
|
||||||
else:
|
|
||||||
depreciation_amount = flt(depreciable_value) * (flt(row.rate_of_depreciation) / 100)
|
|
||||||
value_after_depreciation = flt(depreciable_value) - depreciation_amount
|
|
||||||
if value_after_depreciation < flt(row.expected_value_after_useful_life):
|
|
||||||
depreciation_amount = flt(depreciable_value) - flt(row.expected_value_after_useful_life)
|
|
||||||
|
|
||||||
return depreciation_amount
|
return depreciation_amount
|
||||||
|
|
||||||
@ -301,9 +273,12 @@ class Asset(AccountsController):
|
|||||||
flt(accumulated_depreciation_after_full_schedule),
|
flt(accumulated_depreciation_after_full_schedule),
|
||||||
self.precision('gross_purchase_amount'))
|
self.precision('gross_purchase_amount'))
|
||||||
|
|
||||||
if row.expected_value_after_useful_life < asset_value_after_full_schedule:
|
if (row.expected_value_after_useful_life and
|
||||||
|
row.expected_value_after_useful_life < asset_value_after_full_schedule):
|
||||||
frappe.throw(_("Depreciation Row {0}: Expected value after useful life must be greater than or equal to {1}")
|
frappe.throw(_("Depreciation Row {0}: Expected value after useful life must be greater than or equal to {1}")
|
||||||
.format(row.idx, asset_value_after_full_schedule))
|
.format(row.idx, asset_value_after_full_schedule))
|
||||||
|
elif not row.expected_value_after_useful_life:
|
||||||
|
row.expected_value_after_useful_life = asset_value_after_full_schedule
|
||||||
|
|
||||||
def validate_cancellation(self):
|
def validate_cancellation(self):
|
||||||
if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"):
|
if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"):
|
||||||
|
@ -46,75 +46,6 @@
|
|||||||
"translatable": 0,
|
"translatable": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fetch_if_empty": 0,
|
|
||||||
"fieldname": "schedule_based_on_fiscal_year",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Calculate Prorated Depreciation Schedule Based on Fiscal Year",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_in_quick_entry": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"default": "360",
|
|
||||||
"depends_on": "eval:doc.schedule_based_on_fiscal_year",
|
|
||||||
"description": "This value is used for pro-rata temporis calculation",
|
|
||||||
"fetch_if_empty": 0,
|
|
||||||
"fieldname": "number_of_days_in_fiscal_year",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "Number of Days in Fiscal Year",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"translatable": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_in_quick_entry": 0,
|
"allow_in_quick_entry": 0,
|
||||||
@ -159,7 +90,7 @@
|
|||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2019-03-08 10:44:41.924547",
|
"modified": "2019-05-26 18:31:19.930563",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset Settings",
|
"name": "Asset Settings",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user