Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite Item Price Stock Report queries in QB #32346

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions erpnext/stock/report/item_price_stock/item_price_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,28 @@ def get_data(filters, columns):


def get_item_price_qty_data(filters):
conditions = ""
if filters.get("item_code"):
conditions += "where a.item_code=%(item_code)s"

item_results = frappe.db.sql(
"""select a.item_code, a.item_name, a.name as price_list_name,
a.brand as brand, b.warehouse as warehouse, b.actual_qty as actual_qty
from `tabItem Price` a left join `tabBin` b
ON a.item_code = b.item_code
{conditions}""".format(
conditions=conditions
),
filters,
as_dict=1,
item_price = frappe.qb.DocType("Item Price")
bin = frappe.qb.DocType("Bin")

query = (
frappe.qb.from_(item_price)
.left_join(bin)
.on(item_price.item_code == bin.item_code)
.select(
item_price.item_code,
item_price.item_name,
item_price.name.as_("price_list_name"),
item_price.brand.as_("brand"),
bin.warehouse.as_("warehouse"),
bin.actual_qty.as_("actual_qty"),
)
)

if filters.get("item_code"):
query = query.where(item_price.item_code == filters.get("item_code"))

item_results = query.run(as_dict=True)

price_list_names = list(set(item.price_list_name for item in item_results))

buying_price_map = get_price_map(price_list_names, buying=1)
Expand Down