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
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_item_group, get_stock_availability
|
||||
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
|
||||
|
||||
|
||||
@@ -66,6 +67,9 @@ def search_by_term(search_term, warehouse, price_list):
|
||||
if batch_no:
|
||||
price_filters["batch_no"] = ["in", [batch_no, ""]]
|
||||
|
||||
if serial_no:
|
||||
price_filters["uom"] = item_doc.stock_uom
|
||||
|
||||
price = frappe.get_list(
|
||||
doctype="Item Price",
|
||||
filters=price_filters,
|
||||
@@ -159,7 +163,8 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
||||
item.description,
|
||||
item.stock_uom,
|
||||
item.image AS item_image,
|
||||
item.is_stock_item
|
||||
item.is_stock_item,
|
||||
item.sales_uom
|
||||
FROM
|
||||
`tabItem` item {bin_join_selection}
|
||||
WHERE
|
||||
@@ -193,12 +198,9 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
||||
current_date = frappe.utils.today()
|
||||
|
||||
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.uom = item.stock_uom
|
||||
|
||||
item_price = frappe.get_all(
|
||||
item_prices = frappe.get_all(
|
||||
"Item Price",
|
||||
fields=["price_list_rate", "currency", "uom", "batch_no", "valid_from", "valid_upto"],
|
||||
filters={
|
||||
@@ -209,27 +211,40 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
|
||||
"valid_upto": ["in", [None, "", current_date]],
|
||||
},
|
||||
order_by="valid_from desc",
|
||||
limit=1,
|
||||
)
|
||||
|
||||
if not item_price:
|
||||
result.append(item)
|
||||
stock_uom_price = next((d for d in item_prices if d.get("uom") == item.stock_uom), {})
|
||||
item_uom = item.stock_uom
|
||||
item_uom_price = stock_uom_price
|
||||
|
||||
for price in item_price:
|
||||
uom = next(filter(lambda x: x.uom == price.uom, uoms), {})
|
||||
if item.sales_uom and item.sales_uom != item.stock_uom:
|
||||
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:
|
||||
item.actual_qty = item.actual_qty // uom.conversion_factor
|
||||
if item_prices and not item_uom_price:
|
||||
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}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user