fix: compare against stock qty while validating

Other changes:

- only allow whole number of bundles to get picked
This commit is contained in:
Ankush Menat 2022-04-27 12:15:26 +05:30
parent 9e60acdf56
commit 8207697e43
3 changed files with 24 additions and 6 deletions

View File

@ -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",

View File

@ -85,9 +85,12 @@ class PickList(Document):
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 @@ class PickList(Document):
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 @@ class PickList(Document):
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):

View File

@ -582,8 +582,23 @@ class TestPickList(FrappeTestCase):
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]