mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-21 02:16:28 +00:00
fix: pos item price in get_item and item search (#47925)
* fix: pos get item and item search
* refactor: resolved linter issue and renamed variables
* fix: uom on get_item
* fix: incorrect item quantity on pos selector
* refactor: remove unused import
(cherry picked from commit 919684a787)
Co-authored-by: Diptanil Saha <diptanil@frappe.io>
This commit is contained in:
@@ -10,6 +10,7 @@ from frappe.utils.nestedset import get_root_of
|
|||||||
|
|
||||||
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability
|
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability
|
||||||
from erpnext.accounts.doctype.pos_profile.pos_profile import get_child_nodes, get_item_groups
|
from erpnext.accounts.doctype.pos_profile.pos_profile import get_child_nodes, get_item_groups
|
||||||
|
from erpnext.stock.get_item_details import get_conversion_factor
|
||||||
from erpnext.stock.utils import scan_barcode
|
from erpnext.stock.utils import scan_barcode
|
||||||
|
|
||||||
|
|
||||||
@@ -66,6 +67,9 @@ def search_by_term(search_term, warehouse, price_list):
|
|||||||
if batch_no:
|
if batch_no:
|
||||||
price_filters["batch_no"] = ["in", [batch_no, ""]]
|
price_filters["batch_no"] = ["in", [batch_no, ""]]
|
||||||
|
|
||||||
|
if serial_no:
|
||||||
|
price_filters["uom"] = item_doc.stock_uom
|
||||||
|
|
||||||
price = frappe.get_list(
|
price = frappe.get_list(
|
||||||
doctype="Item Price",
|
doctype="Item Price",
|
||||||
filters=price_filters,
|
filters=price_filters,
|
||||||
@@ -158,7 +162,8 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
|||||||
item.description,
|
item.description,
|
||||||
item.stock_uom,
|
item.stock_uom,
|
||||||
item.image AS item_image,
|
item.image AS item_image,
|
||||||
item.is_stock_item
|
item.is_stock_item,
|
||||||
|
item.sales_uom
|
||||||
FROM
|
FROM
|
||||||
`tabItem` item {bin_join_selection}
|
`tabItem` item {bin_join_selection}
|
||||||
WHERE
|
WHERE
|
||||||
@@ -192,12 +197,9 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
|||||||
current_date = frappe.utils.today()
|
current_date = frappe.utils.today()
|
||||||
|
|
||||||
for item in items_data:
|
for item in items_data:
|
||||||
uoms = frappe.get_doc("Item", item.item_code).get("uoms", [])
|
|
||||||
|
|
||||||
item.actual_qty, _ = get_stock_availability(item.item_code, warehouse)
|
item.actual_qty, _ = get_stock_availability(item.item_code, warehouse)
|
||||||
item.uom = item.stock_uom
|
|
||||||
|
|
||||||
item_price = frappe.get_all(
|
item_prices = frappe.get_all(
|
||||||
"Item Price",
|
"Item Price",
|
||||||
fields=["price_list_rate", "currency", "uom", "batch_no", "valid_from", "valid_upto"],
|
fields=["price_list_rate", "currency", "uom", "batch_no", "valid_from", "valid_upto"],
|
||||||
filters={
|
filters={
|
||||||
@@ -208,27 +210,40 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
|||||||
"valid_upto": ["in", [None, "", current_date]],
|
"valid_upto": ["in", [None, "", current_date]],
|
||||||
},
|
},
|
||||||
order_by="valid_from desc",
|
order_by="valid_from desc",
|
||||||
limit=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not item_price:
|
stock_uom_price = next((d for d in item_prices if d.get("uom") == item.stock_uom), {})
|
||||||
result.append(item)
|
item_uom = item.stock_uom
|
||||||
|
item_uom_price = stock_uom_price
|
||||||
|
|
||||||
for price in item_price:
|
if item.sales_uom and item.sales_uom != item.stock_uom:
|
||||||
uom = next(filter(lambda x: x.uom == price.uom, uoms), {})
|
item_uom = item.sales_uom
|
||||||
|
sales_uom_price = next((d for d in item_prices if d.get("uom") == item.sales_uom), {})
|
||||||
|
if sales_uom_price:
|
||||||
|
item_uom_price = sales_uom_price
|
||||||
|
|
||||||
if price.uom != item.stock_uom and uom and uom.conversion_factor:
|
if item_prices and not item_uom_price:
|
||||||
item.actual_qty = item.actual_qty // uom.conversion_factor
|
item_uom = item_prices[0].get("uom")
|
||||||
|
item_uom_price = item_prices[0]
|
||||||
|
|
||||||
|
item_conversion_factor = get_conversion_factor(item.item_code, item_uom).get("conversion_factor")
|
||||||
|
|
||||||
|
if item.stock_uom != item_uom:
|
||||||
|
item.actual_qty = item.actual_qty // item_conversion_factor
|
||||||
|
|
||||||
|
if item_uom_price and item_uom != item_uom_price.get("uom"):
|
||||||
|
item_uom_price.price_list_rate = item_uom_price.price_list_rate * item_conversion_factor
|
||||||
|
|
||||||
|
result.append(
|
||||||
|
{
|
||||||
|
**item,
|
||||||
|
"price_list_rate": item_uom_price.get("price_list_rate"),
|
||||||
|
"currency": item_uom_price.get("currency"),
|
||||||
|
"uom": item_uom,
|
||||||
|
"batch_no": item_uom_price.get("batch_no"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
result.append(
|
|
||||||
{
|
|
||||||
**item,
|
|
||||||
"price_list_rate": price.get("price_list_rate"),
|
|
||||||
"currency": price.get("currency"),
|
|
||||||
"uom": price.uom or item.uom,
|
|
||||||
"batch_no": price.batch_no,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return {"items": result}
|
return {"items": result}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user