mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-21 15:48:29 +00:00
fix: default pos conversion factor set to 1 (#34437)
* fix: default pos conversion factor set to 1 (#34437)
(cherry picked from commit 08fc686513)
# Conflicts:
# erpnext/selling/page/point_of_sale/point_of_sale.py
* chore: Resolve conflicts
---------
Co-authored-by: Shram Kadia <65490105+Shram007@users.noreply.github.com>
Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
@@ -16,46 +16,72 @@ from erpnext.stock.utils import scan_barcode
|
|||||||
|
|
||||||
def search_by_term(search_term, warehouse, price_list):
|
def search_by_term(search_term, warehouse, price_list):
|
||||||
result = search_for_serial_or_batch_or_barcode_number(search_term) or {}
|
result = search_for_serial_or_batch_or_barcode_number(search_term) or {}
|
||||||
|
item_code = result.get("item_code", search_term)
|
||||||
|
serial_no = result.get("serial_no", "")
|
||||||
|
batch_no = result.get("batch_no", "")
|
||||||
|
barcode = result.get("barcode", "")
|
||||||
|
if not result:
|
||||||
|
return
|
||||||
|
item_doc = frappe.get_doc("Item", item_code)
|
||||||
|
if not item_doc:
|
||||||
|
return
|
||||||
|
item = {
|
||||||
|
"barcode": barcode,
|
||||||
|
"batch_no": batch_no,
|
||||||
|
"description": item_doc.description,
|
||||||
|
"is_stock_item": item_doc.is_stock_item,
|
||||||
|
"item_code": item_doc.name,
|
||||||
|
"item_image": item_doc.image,
|
||||||
|
"item_name": item_doc.item_name,
|
||||||
|
"serial_no": serial_no,
|
||||||
|
"stock_uom": item_doc.stock_uom,
|
||||||
|
"uom": item_doc.stock_uom,
|
||||||
|
}
|
||||||
|
if barcode:
|
||||||
|
barcode_info = next(filter(lambda x: x.barcode == barcode, item_doc.get("barcodes", [])), None)
|
||||||
|
if barcode_info and barcode_info.uom:
|
||||||
|
uom = next(filter(lambda x: x.uom == barcode_info.uom, item_doc.uoms), {})
|
||||||
|
item.update(
|
||||||
|
{
|
||||||
|
"uom": barcode_info.uom,
|
||||||
|
"conversion_factor": uom.get("conversion_factor", 1),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
item_code = result.get("item_code") or search_term
|
item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse)
|
||||||
serial_no = result.get("serial_no") or ""
|
item_stock_qty = item_stock_qty // item.get("conversion_factor")
|
||||||
batch_no = result.get("batch_no") or ""
|
item_stock_qty = item_stock_qty // item.get("conversion_factor", 1)
|
||||||
barcode = result.get("barcode") or ""
|
item.update({"actual_qty": item_stock_qty})
|
||||||
|
|
||||||
if result:
|
price = frappe.get_list(
|
||||||
item_info = frappe.db.get_value(
|
doctype="Item Price",
|
||||||
"Item",
|
filters={
|
||||||
item_code,
|
"price_list": price_list,
|
||||||
[
|
"item_code": item_code,
|
||||||
"name as item_code",
|
},
|
||||||
"item_name",
|
fields=["uom", "stock_uom", "currency", "price_list_rate"],
|
||||||
"description",
|
)
|
||||||
"stock_uom",
|
|
||||||
"image as item_image",
|
|
||||||
"is_stock_item",
|
|
||||||
],
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse)
|
def __sort(p):
|
||||||
price_list_rate, currency = frappe.db.get_value(
|
p_uom = p.get("uom")
|
||||||
"Item Price",
|
if p_uom == item.get("uom"):
|
||||||
{"price_list": price_list, "item_code": item_code},
|
return 0
|
||||||
["price_list_rate", "currency"],
|
elif p_uom == item.get("stock_uom"):
|
||||||
) or [None, None]
|
return 1
|
||||||
|
else:
|
||||||
|
return 2
|
||||||
|
|
||||||
item_info.update(
|
# sort by fallback preference. always pick exact uom match if available
|
||||||
|
price = sorted(price, key=__sort)
|
||||||
|
if len(price) > 0:
|
||||||
|
p = price.pop(0)
|
||||||
|
item.update(
|
||||||
{
|
{
|
||||||
"serial_no": serial_no,
|
"currency": p.get("currency"),
|
||||||
"batch_no": batch_no,
|
"price_list_rate": p.get("price_list_rate"),
|
||||||
"barcode": barcode,
|
|
||||||
"price_list_rate": price_list_rate,
|
|
||||||
"currency": currency,
|
|
||||||
"actual_qty": item_stock_qty,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
return {"items": [item]}
|
||||||
return {"items": [item_info]}
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Reference in New Issue
Block a user