Skip to content

Commit

Permalink
fix: default pos conversion factor set to 1 (frappe#34437)
Browse files Browse the repository at this point in the history
* fix: default pos conversion factor set to 1 (frappe#34437)

(cherry picked from commit 08fc686)

# 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>
  • Loading branch information
3 people committed Mar 24, 2023
1 parent 67576ad commit 18d813a
Showing 1 changed file with 61 additions and 35 deletions.
96 changes: 61 additions & 35 deletions erpnext/selling/page/point_of_sale/point_of_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,72 @@

def search_by_term(search_term, warehouse, price_list):
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
serial_no = result.get("serial_no") or ""
batch_no = result.get("batch_no") or ""
barcode = result.get("barcode") or ""

if result:
item_info = frappe.db.get_value(
"Item",
item_code,
[
"name as item_code",
"item_name",
"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)
price_list_rate, currency = frappe.db.get_value(
"Item Price",
{"price_list": price_list, "item_code": item_code},
["price_list_rate", "currency"],
) or [None, None]
item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse)
item_stock_qty = item_stock_qty // item.get("conversion_factor")
item_stock_qty = item_stock_qty // item.get("conversion_factor", 1)
item.update({"actual_qty": item_stock_qty})

price = frappe.get_list(
doctype="Item Price",
filters={
"price_list": price_list,
"item_code": item_code,
},
fields=["uom", "stock_uom", "currency", "price_list_rate"],
)

item_info.update(
def __sort(p):
p_uom = p.get("uom")
if p_uom == item.get("uom"):
return 0
elif p_uom == item.get("stock_uom"):
return 1
else:
return 2

# 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,
"batch_no": batch_no,
"barcode": barcode,
"price_list_rate": price_list_rate,
"currency": currency,
"actual_qty": item_stock_qty,
"currency": p.get("currency"),
"price_list_rate": p.get("price_list_rate"),
}
)

return {"items": [item_info]}
return {"items": [item]}


@frappe.whitelist()
Expand Down

0 comments on commit 18d813a

Please sign in to comment.