From 8207697e43a8baa3353c0c984e8e99b14fcb5b55 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 27 Apr 2022 12:15:26 +0530 Subject: [PATCH] fix: compare against stock qty while validating Other changes: - only allow whole number of bundles to get picked --- .../sales_order_item/sales_order_item.json | 4 ++-- erpnext/stock/doctype/pick_list/pick_list.py | 9 ++++++--- .../stock/doctype/pick_list/test_pick_list.py | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 8a6a0bae5483..3797856db2f1 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -803,7 +803,7 @@ { "fieldname": "picked_qty", "fieldtype": "Float", - "label": "Picked Qty", + "label": "Picked Qty (in Stock UOM)", "no_copy": 1, "read_only": 1 } @@ -811,7 +811,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2022-04-21 08:15:14.010319", + "modified": "2022-04-27 03:15:34.366563", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 53584f5079e5..70d2f23070c1 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -85,9 +85,12 @@ def before_cancel(self): def update_sales_order_item(self, item, picked_qty, item_code): item_table = "Sales Order Item" if not item.product_bundle_item else "Packed Item" + stock_qty_field = "stock_qty" if not item.product_bundle_item else "qty" already_picked, actual_qty = frappe.db.get_value( - item_table, item.sales_order_item, ["picked_qty", "qty"] + item_table, + item.sales_order_item, + ["picked_qty", stock_qty_field], ) if self.docstatus == 1: @@ -259,7 +262,7 @@ def _get_product_bundle_qty_map(self, bundles: List[str]) -> Dict[str, Dict[str, product_bundle_qty_map[bundle_item_code] = {item.item_code: item.qty for item in bundle.items} return product_bundle_qty_map - def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> float: + def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> int: """Compute how many full bundles can be created from picked items.""" precision = frappe.get_precision("Stock Ledger Entry", "qty_after_transaction") @@ -272,7 +275,7 @@ def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> float: possible_bundles.append(item.picked_qty / qty_in_bundle) else: possible_bundles.append(0) - return flt(min(possible_bundles), precision or 6) + return int(flt(min(possible_bundles), precision or 6)) def validate_item_locations(pick_list): diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 8ce05f15f7d6..f552299806c3 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -582,8 +582,23 @@ def test_multiple_dn_creation(self): if dn_item.item_code == "_Test Item 2": self.assertEqual(dn_item.qty, 2) + def test_picklist_with_multi_uom(self): + warehouse = "_Test Warehouse - _TC" + item = make_item(properties={"uoms": [dict(uom="Box", conversion_factor=24)]}).name + make_stock_entry(item=item, to_warehouse=warehouse, qty=1000) + + so = make_sales_order(item_code=item, qty=10, rate=42, uom="Box") + pl = create_pick_list(so.name) + # pick half the qty + for loc in pl.locations: + loc.picked_qty = loc.stock_qty / 2 + pl.save() + pl.submit() + + so.reload() + self.assertEqual(so.per_picked, 50) + def test_picklist_with_bundles(self): - # from test_records.json warehouse = "_Test Warehouse - _TC" quantities = [5, 2]