mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-18 01:36:55 +00:00
fix: added date condition
This commit is contained in:
@@ -114,7 +114,11 @@ def get_asset_categories_for_grouped_by_category(filters):
|
|||||||
end), 0) as cost_of_scrapped_asset
|
end), 0) as cost_of_scrapped_asset
|
||||||
from `tabAsset` a
|
from `tabAsset` a
|
||||||
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {condition}
|
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {condition}
|
||||||
and not exists(select name from `tabAsset Capitalization Asset Item` where asset = a.name)
|
and not exists(
|
||||||
|
select 1 from `tabAsset Capitalization Asset Item` acai join `tabAsset Capitalization` ac on acai.parent=ac.name
|
||||||
|
where acai.asset = a.name
|
||||||
|
and ac.posting_date between %(from_date)s AND %(to_date)s
|
||||||
|
)
|
||||||
group by a.asset_category
|
group by a.asset_category
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
@@ -131,53 +135,58 @@ def get_asset_categories_for_grouped_by_category(filters):
|
|||||||
def get_asset_details_for_grouped_by_category(filters):
|
def get_asset_details_for_grouped_by_category(filters):
|
||||||
condition = ""
|
condition = ""
|
||||||
if filters.get("asset"):
|
if filters.get("asset"):
|
||||||
condition += " and name = %(asset)s"
|
condition += " and a.name = %(asset)s"
|
||||||
if filters.get("finance_book"):
|
if filters.get("finance_book"):
|
||||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = `tabAsset`.name and ads.finance_book = %(finance_book)s)"
|
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = a.name and ads.finance_book = %(finance_book)s)"
|
||||||
|
|
||||||
# nosemgrep
|
# nosemgrep
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
f"""
|
f"""
|
||||||
SELECT name,
|
SELECT a.name,
|
||||||
ifnull(sum(case when purchase_date < %(from_date)s then
|
ifnull(sum(case when a.purchase_date < %(from_date)s then
|
||||||
case when ifnull(disposal_date, 0) = 0 or disposal_date >= %(from_date)s then
|
case when ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s then
|
||||||
gross_purchase_amount
|
a.gross_purchase_amount
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end), 0) as cost_as_on_from_date,
|
end), 0) as cost_as_on_from_date,
|
||||||
ifnull(sum(case when purchase_date >= %(from_date)s then
|
ifnull(sum(case when a.purchase_date >= %(from_date)s then
|
||||||
gross_purchase_amount
|
a.gross_purchase_amount
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end), 0) as cost_of_new_purchase,
|
end), 0) as cost_of_new_purchase,
|
||||||
ifnull(sum(case when ifnull(disposal_date, 0) != 0
|
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||||
and disposal_date >= %(from_date)s
|
and a.disposal_date >= %(from_date)s
|
||||||
and disposal_date <= %(to_date)s then
|
and a.disposal_date <= %(to_date)s then
|
||||||
case when status = "Sold" then
|
case when a.status = "Sold" then
|
||||||
gross_purchase_amount
|
a.gross_purchase_amount
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end), 0) as cost_of_sold_asset,
|
end), 0) as cost_of_sold_asset,
|
||||||
ifnull(sum(case when ifnull(disposal_date, 0) != 0
|
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||||
and disposal_date >= %(from_date)s
|
and a.disposal_date >= %(from_date)s
|
||||||
and disposal_date <= %(to_date)s then
|
and a.disposal_date <= %(to_date)s then
|
||||||
case when status = "Scrapped" then
|
case when a.status = "Scrapped" then
|
||||||
gross_purchase_amount
|
a.gross_purchase_amount
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end), 0) as cost_of_scrapped_asset
|
end), 0) as cost_of_scrapped_asset
|
||||||
from `tabAsset`
|
from `tabAsset` a
|
||||||
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {condition}
|
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {condition}
|
||||||
group by name
|
and not exists(
|
||||||
|
select 1 from `tabAsset Capitalization Asset Item` acai join `tabAsset Capitalization` ac on acai.parent=ac.name
|
||||||
|
where acai.asset = a.name
|
||||||
|
and ac.posting_date between %(from_date)s AND %(to_date)s
|
||||||
|
)
|
||||||
|
group by a.name
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"to_date": filters.to_date,
|
"to_date": filters.to_date,
|
||||||
|
|||||||
Reference in New Issue
Block a user