mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
Merge pull request #34058 from AnandBaburajan/more_asset_bug_fixes_v14
fix: manual depr entries in asset_depreciations_and_balances report and some misc bugs [v14]
This commit is contained in:
@@ -336,6 +336,8 @@ class JournalEntry(AccountsController):
|
|||||||
finance_books.db_update()
|
finance_books.db_update()
|
||||||
|
|
||||||
asset.set_status()
|
asset.set_status()
|
||||||
|
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
depr_value = d.debit or d.credit
|
depr_value = d.debit or d.credit
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,34 @@ def get_assets(filters):
|
|||||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and a.name = ds.parent and ifnull(ds.journal_entry, '') != ''
|
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and a.name = ds.parent and ifnull(ds.journal_entry, '') != ''
|
||||||
group by a.asset_category
|
group by a.asset_category
|
||||||
union
|
union
|
||||||
|
SELECT a.asset_category,
|
||||||
|
ifnull(sum(case when gle.posting_date < %(from_date)s and (ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s) then
|
||||||
|
gle.debit
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end), 0) as accumulated_depreciation_as_on_from_date,
|
||||||
|
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0 and a.disposal_date >= %(from_date)s
|
||||||
|
and a.disposal_date <= %(to_date)s and gle.posting_date <= a.disposal_date then
|
||||||
|
gle.debit
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end), 0) as depreciation_eliminated_during_the_period,
|
||||||
|
ifnull(sum(case when gle.posting_date >= %(from_date)s and gle.posting_date <= %(to_date)s
|
||||||
|
and (ifnull(a.disposal_date, 0) = 0 or gle.posting_date <= a.disposal_date) then
|
||||||
|
gle.debit
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end), 0) as depreciation_amount_during_the_period
|
||||||
|
from `tabGL Entry` gle
|
||||||
|
join `tabAsset` a on
|
||||||
|
gle.against_voucher = a.name
|
||||||
|
join `tabAsset Category Account` aca on
|
||||||
|
aca.parent = a.asset_category and aca.company_name = %(company)s
|
||||||
|
join `tabCompany` company on
|
||||||
|
company.name = %(company)s
|
||||||
|
where a.docstatus=1 and a.company=%(company)s and a.calculate_depreciation=0 and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account)
|
||||||
|
group by a.asset_category
|
||||||
|
union
|
||||||
SELECT a.asset_category,
|
SELECT a.asset_category,
|
||||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0 and (a.disposal_date < %(from_date)s or a.disposal_date > %(to_date)s) then
|
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0 and (a.disposal_date < %(from_date)s or a.disposal_date > %(to_date)s) then
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -210,52 +210,53 @@ frappe.ui.form.on('Asset', {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var x_intervals = [frm.doc.purchase_date];
|
var x_intervals = [frappe.format(frm.doc.purchase_date, { fieldtype: 'Date' })];
|
||||||
var asset_values = [frm.doc.gross_purchase_amount];
|
var asset_values = [frm.doc.gross_purchase_amount];
|
||||||
var last_depreciation_date = frm.doc.purchase_date;
|
|
||||||
|
|
||||||
if(frm.doc.opening_accumulated_depreciation) {
|
|
||||||
last_depreciation_date = frappe.datetime.add_months(frm.doc.next_depreciation_date,
|
|
||||||
-1*frm.doc.frequency_of_depreciation);
|
|
||||||
|
|
||||||
x_intervals.push(last_depreciation_date);
|
|
||||||
asset_values.push(flt(frm.doc.gross_purchase_amount) -
|
|
||||||
flt(frm.doc.opening_accumulated_depreciation));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(frm.doc.calculate_depreciation) {
|
if(frm.doc.calculate_depreciation) {
|
||||||
|
if(frm.doc.opening_accumulated_depreciation) {
|
||||||
|
var depreciation_date = frappe.datetime.add_months(
|
||||||
|
frm.doc.finance_books[0].depreciation_start_date,
|
||||||
|
-1 * frm.doc.finance_books[0].frequency_of_depreciation
|
||||||
|
);
|
||||||
|
x_intervals.push(frappe.format(depreciation_date, { fieldtype: 'Date' }));
|
||||||
|
asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount')));
|
||||||
|
}
|
||||||
|
|
||||||
$.each(frm.doc.schedules || [], function(i, v) {
|
$.each(frm.doc.schedules || [], function(i, v) {
|
||||||
x_intervals.push(v.schedule_date);
|
x_intervals.push(frappe.format(v.schedule_date, { fieldtype: 'Date' }));
|
||||||
var asset_value = flt(frm.doc.gross_purchase_amount) - flt(v.accumulated_depreciation_amount);
|
var asset_value = flt(frm.doc.gross_purchase_amount - v.accumulated_depreciation_amount, precision('gross_purchase_amount'));
|
||||||
if(v.journal_entry) {
|
if(v.journal_entry) {
|
||||||
last_depreciation_date = v.schedule_date;
|
|
||||||
asset_values.push(asset_value);
|
asset_values.push(asset_value);
|
||||||
} else {
|
} else {
|
||||||
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||||
asset_values.push(null);
|
asset_values.push(null);
|
||||||
} else {
|
} else {
|
||||||
asset_values.push(asset_value)
|
asset_values.push(asset_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
if(frm.doc.opening_accumulated_depreciation) {
|
||||||
|
x_intervals.push(frappe.format(frm.doc.creation.split(" ")[0], { fieldtype: 'Date' }));
|
||||||
|
asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount')));
|
||||||
|
}
|
||||||
|
|
||||||
let depr_entries = (await frappe.call({
|
let depr_entries = (await frappe.call({
|
||||||
method: "get_manual_depreciation_entries",
|
method: "get_manual_depreciation_entries",
|
||||||
doc: frm.doc,
|
doc: frm.doc,
|
||||||
})).message;
|
})).message;
|
||||||
|
|
||||||
$.each(depr_entries || [], function(i, v) {
|
$.each(depr_entries || [], function(i, v) {
|
||||||
x_intervals.push(v.posting_date);
|
x_intervals.push(frappe.format(v.posting_date, { fieldtype: 'Date' }));
|
||||||
last_depreciation_date = v.posting_date;
|
|
||||||
let last_asset_value = asset_values[asset_values.length - 1]
|
let last_asset_value = asset_values[asset_values.length - 1]
|
||||||
asset_values.push(last_asset_value - v.value);
|
asset_values.push(last_asset_value - v.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
if(in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||||
x_intervals.push(frm.doc.disposal_date);
|
x_intervals.push(frappe.format(frm.doc.disposal_date, { fieldtype: 'Date' }));
|
||||||
asset_values.push(0);
|
asset_values.push(0);
|
||||||
last_depreciation_date = frm.doc.disposal_date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frm.dashboard.render_graph({
|
frm.dashboard.render_graph({
|
||||||
|
|||||||
@@ -693,14 +693,16 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
def get_value_after_depreciation(self, finance_book=None):
|
def get_value_after_depreciation(self, finance_book=None):
|
||||||
if not self.calculate_depreciation:
|
if not self.calculate_depreciation:
|
||||||
return self.value_after_depreciation
|
return flt(self.value_after_depreciation, self.precision("gross_purchase_amount"))
|
||||||
|
|
||||||
if not finance_book:
|
if not finance_book:
|
||||||
return self.get("finance_books")[0].value_after_depreciation
|
return flt(
|
||||||
|
self.get("finance_books")[0].value_after_depreciation, self.precision("gross_purchase_amount")
|
||||||
|
)
|
||||||
|
|
||||||
for row in self.get("finance_books"):
|
for row in self.get("finance_books"):
|
||||||
if finance_book == row.finance_book:
|
if finance_book == row.finance_book:
|
||||||
return row.value_after_depreciation
|
return flt(row.value_after_depreciation, self.precision("gross_purchase_amount"))
|
||||||
|
|
||||||
def get_default_finance_book_idx(self):
|
def get_default_finance_book_idx(self):
|
||||||
if not self.get("default_finance_book") and self.company:
|
if not self.get("default_finance_book") and self.company:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Sum
|
||||||
from frappe.utils import cstr, formatdate, getdate
|
from frappe.utils import cstr, flt, formatdate, getdate
|
||||||
|
|
||||||
from erpnext.accounts.report.financial_statements import (
|
from erpnext.accounts.report.financial_statements import (
|
||||||
get_fiscal_year_data,
|
get_fiscal_year_data,
|
||||||
@@ -102,13 +102,9 @@ def get_data(filters):
|
|||||||
]
|
]
|
||||||
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
assets_record = frappe.db.get_all("Asset", filters=conditions, fields=fields)
|
||||||
|
|
||||||
finance_book_filter = ("is", "not set")
|
|
||||||
if filters.finance_book:
|
|
||||||
finance_book_filter = ("=", filters.finance_book)
|
|
||||||
|
|
||||||
assets_linked_to_fb = frappe.db.get_all(
|
assets_linked_to_fb = frappe.db.get_all(
|
||||||
doctype="Asset Finance Book",
|
doctype="Asset Finance Book",
|
||||||
filters={"finance_book": finance_book_filter},
|
filters={"finance_book": filters.finance_book or ("is", "not set")},
|
||||||
pluck="parent",
|
pluck="parent",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -194,7 +190,7 @@ def get_depreciation_amount_of_asset(asset, depreciation_amount_map, filters):
|
|||||||
else:
|
else:
|
||||||
depr_amount = get_manual_depreciation_amount_of_asset(asset, filters)
|
depr_amount = get_manual_depreciation_amount_of_asset(asset, filters)
|
||||||
|
|
||||||
return depr_amount
|
return flt(depr_amount, 2)
|
||||||
|
|
||||||
|
|
||||||
def get_finance_book_value_map(filters):
|
def get_finance_book_value_map(filters):
|
||||||
|
|||||||
Reference in New Issue
Block a user