From 67b53ba53dc38fdf2a4bdc9e12b7cb3a7809af82 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 | 17 +++++++++- .../doctype/stock_settings/stock_settings.py | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 3648d6edd7..7a848891c0 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -624,6 +624,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 91439cb3aa..eb196772fb 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -1177,3 +1177,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 95ab885ba1..e7abe29027 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", @@ -437,6 +438,20 @@ "fieldname": "do_not_update_serial_batch_on_creation_of_auto_bundle", "fieldtype": "Check", "label": "Do Not Update Serial / Batch on Creation of Auto Bundle" + }, + { + "default": "0", + "depends_on": "eval:doc.valuation_method === \"Moving Average\"", + "description": "If enabled, the system will use the moving average valuation method to calculate the valuation rate for the batched items and will not consider the individual batch-wise incoming rate.", + "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", @@ -444,7 +459,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-02-25 16:32:01.084453", + "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 1572ad5bba..7a19d24f87 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/stock_settings.py @@ -45,6 +45,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