mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 15:25:19 +00:00
* fix: billed qty and received amount in PO analysis report (#44349)
(cherry picked from commit 2ab7ec5437)
# Conflicts:
# erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ def execute(filters=None):
|
|||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
data = get_data(filters)
|
data = get_data(filters)
|
||||||
|
update_received_amount(data)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return [], [], None, []
|
return [], [], None, []
|
||||||
@@ -60,7 +61,6 @@ def get_data(filters):
|
|||||||
(po_item.qty - po_item.received_qty).as_("pending_qty"),
|
(po_item.qty - po_item.received_qty).as_("pending_qty"),
|
||||||
Sum(IfNull(pi_item.qty, 0)).as_("billed_qty"),
|
Sum(IfNull(pi_item.qty, 0)).as_("billed_qty"),
|
||||||
po_item.base_amount.as_("amount"),
|
po_item.base_amount.as_("amount"),
|
||||||
(po_item.received_qty * po_item.base_rate).as_("received_qty_amount"),
|
|
||||||
(po_item.billed_amt * IfNull(po.conversion_rate, 1)).as_("billed_amount"),
|
(po_item.billed_amt * IfNull(po.conversion_rate, 1)).as_("billed_amount"),
|
||||||
(po_item.base_amount - (po_item.billed_amt * IfNull(po.conversion_rate, 1))).as_(
|
(po_item.base_amount - (po_item.billed_amt * IfNull(po.conversion_rate, 1))).as_(
|
||||||
"pending_amount"
|
"pending_amount"
|
||||||
@@ -92,6 +92,39 @@ def get_data(filters):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def update_received_amount(data):
|
||||||
|
pr_data = get_received_amount_data(data)
|
||||||
|
|
||||||
|
for row in data:
|
||||||
|
row.received_qty_amount = flt(pr_data.get(row.name))
|
||||||
|
|
||||||
|
|
||||||
|
def get_received_amount_data(data):
|
||||||
|
pr = frappe.qb.DocType("Purchase Receipt")
|
||||||
|
pr_item = frappe.qb.DocType("Purchase Receipt Item")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(pr)
|
||||||
|
.inner_join(pr_item)
|
||||||
|
.on(pr_item.parent == pr.name)
|
||||||
|
.select(
|
||||||
|
pr_item.purchase_order_item,
|
||||||
|
Sum(pr_item.base_amount).as_("received_qty_amount"),
|
||||||
|
)
|
||||||
|
.where((pr_item.parent == pr.name) & (pr.docstatus == 1))
|
||||||
|
.groupby(pr_item.purchase_order_item)
|
||||||
|
)
|
||||||
|
|
||||||
|
query = query.where(pr_item.purchase_order_item.isin([row.name for row in data]))
|
||||||
|
|
||||||
|
data = query.run()
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return frappe._dict()
|
||||||
|
|
||||||
|
return frappe._dict(data)
|
||||||
|
|
||||||
|
|
||||||
def prepare_data(data, filters):
|
def prepare_data(data, filters):
|
||||||
completed, pending = 0, 0
|
completed, pending = 0, 0
|
||||||
pending_field = "pending_amount"
|
pending_field = "pending_amount"
|
||||||
|
|||||||
Reference in New Issue
Block a user