Skip to content

Commit

Permalink
fix: compare against stock qty while validating
Browse files Browse the repository at this point in the history
Other changes:

- only allow whole number of bundles to get picked
  • Loading branch information
ankush committed Apr 27, 2022
1 parent 9e60acd commit 8207697
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,15 @@
{
"fieldname": "picked_qty",
"fieldtype": "Float",
"label": "Picked Qty",
"label": "Picked Qty (in Stock UOM)",
"no_copy": 1,
"read_only": 1
}
],
"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",
Expand Down
9 changes: 6 additions & 3 deletions erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand All @@ -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):
Expand Down
17 changes: 16 additions & 1 deletion erpnext/stock/doctype/pick_list/test_pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8207697

Please sign in to comment.