From 762859693335e3def08bb34468d594ff0768e889 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 15 Jul 2024 23:00:12 +0530 Subject: [PATCH] fix: extra qty pick in pick list (#42345) --- .../doctype/sales_order/sales_order.py | 11 +++++++ .../stock/doctype/pick_list/test_pick_list.py | 31 +++++++++++++++++++ .../stock_settings/stock_settings.json | 9 +++++- .../doctype/stock_settings/stock_settings.py | 1 + 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index f746aaf929..bd0f6359d9 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -632,6 +632,17 @@ class SalesOrder(SellingController): if total_picked_qty and total_qty: per_picked = total_picked_qty / total_qty * 100 + pick_percentage = frappe.db.get_single_value("Stock Settings", "over_picking_allowance") + if pick_percentage: + total_qty += flt(total_qty) * (pick_percentage / 100) + + if total_picked_qty > total_qty: + frappe.throw( + _( + "Total Picked Quantity {0} is more than ordered qty {1}. You can set the Over Picking Allowance in Stock Settings." + ).format(total_picked_qty, total_qty) + ) + self.db_set("per_picked", flt(per_picked), update_modified=False) def set_indicator(self): diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index b1c03bf845..9fc304e4e2 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -1174,3 +1174,34 @@ class TestPickList(FrappeTestCase): row.qty = row.qty + 10 self.assertRaises(frappe.ValidationError, pl.save) + + def test_over_allowance_picking(self): + warehouse = "_Test Warehouse - _TC" + item = make_item( + "Test Over Allowance Picking Item", + properties={ + "is_stock_item": 1, + }, + ).name + + make_stock_entry(item=item, to_warehouse=warehouse, qty=100) + + so = make_sales_order(item_code=item, qty=10, rate=100) + + pl_doc = create_pick_list(so.name) + pl_doc.save() + self.assertEqual(pl_doc.locations[0].qty, 10) + + pl_doc.locations[0].qty = 15 + pl_doc.locations[0].stock_qty = 15 + pl_doc.save() + + self.assertEqual(pl_doc.locations[0].qty, 15) + self.assertRaises(frappe.ValidationError, pl_doc.submit) + + frappe.db.set_single_value("Stock Settings", "over_picking_allowance", 50) + + pl_doc.reload() + pl_doc.submit() + + frappe.db.set_single_value("Stock Settings", "over_picking_allowance", 0) diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index c821c01e0e..d08055a3cc 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -26,6 +26,7 @@ "section_break_9", "over_delivery_receipt_allowance", "mr_qty_allowance", + "over_picking_allowance", "column_break_121", "role_allowed_to_over_deliver_receive", "allow_negative_stock", @@ -446,6 +447,12 @@ "fieldname": "do_not_use_batchwise_valuation", "fieldtype": "Check", "label": "Do Not Use Batch-wise Valuation" + }, + { + "description": "The percentage you are allowed to pick more items in the pick list than the ordered quantity.", + "fieldname": "over_picking_allowance", + "fieldtype": "Percent", + "label": "Over Picking Allowance" } ], "icon": "uil uil-setting", @@ -453,7 +460,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-07-04 12:45:09.811280", + "modified": "2024-07-15 17:18:23.872161", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py index bd82621c29..cea73e7706 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/stock_settings.py @@ -46,6 +46,7 @@ class StockSettings(Document): mr_qty_allowance: DF.Float naming_series_prefix: DF.Data | None over_delivery_receipt_allowance: DF.Float + over_picking_allowance: DF.Percent pick_serial_and_batch_based_on: DF.Literal["FIFO", "LIFO", "Expiry"] reorder_email_notify: DF.Check role_allowed_to_create_edit_back_dated_transactions: DF.Link | None -- GitLab