@@ -74,9 +74,8 @@ def onload(self) -> None:
74
74
75
75
def validate (self ):
76
76
self .validate_for_qty ()
77
- if self .pick_manually and self .get ("locations" ):
78
- self .validate_stock_qty ()
79
- self .check_serial_no_status ()
77
+ self .validate_stock_qty ()
78
+ self .check_serial_no_status ()
80
79
81
80
def before_save (self ):
82
81
self .update_status ()
@@ -90,14 +89,21 @@ def validate_stock_qty(self):
90
89
from erpnext .stock .doctype .batch .batch import get_batch_qty
91
90
92
91
for row in self .get ("locations" ):
93
- if row .batch_no and not row .qty :
92
+ if row .batch_no and row .picked_qty :
94
93
batch_qty = get_batch_qty (row .batch_no , row .warehouse , row .item_code )
95
94
96
- if row .qty > batch_qty :
95
+ if row .picked_qty > batch_qty :
97
96
frappe .throw (
98
97
_ (
99
- "At Row #{0}: The picked quantity {1} for the item {2} is greater than available stock {3} for the batch {4} in the warehouse {5}."
100
- ).format (row .idx , row .item_code , batch_qty , row .batch_no , bold (row .warehouse )),
98
+ "At Row #{0}: The picked quantity {1} for the item {2} is greater than available stock {3} for the batch {4} in the warehouse {5}. Please restock the item."
99
+ ).format (
100
+ row .idx ,
101
+ row .picked_qty ,
102
+ row .item_code ,
103
+ batch_qty ,
104
+ row .batch_no ,
105
+ bold (row .warehouse ),
106
+ ),
101
107
title = _ ("Insufficient Stock" ),
102
108
)
103
109
@@ -109,11 +115,11 @@ def validate_stock_qty(self):
109
115
"actual_qty" ,
110
116
)
111
117
112
- if row .qty > flt (bin_qty ):
118
+ if row .picked_qty > flt (bin_qty ):
113
119
frappe .throw (
114
120
_ (
115
121
"At Row #{0}: The picked quantity {1} for the item {2} is greater than available stock {3} in the warehouse {4}."
116
- ).format (row .idx , row .qty , bold (row .item_code ), bin_qty , bold (row .warehouse )),
122
+ ).format (row .idx , row .picked_qty , bold (row .item_code ), bin_qty , bold (row .warehouse )),
117
123
title = _ ("Insufficient Stock" ),
118
124
)
119
125
@@ -429,7 +435,14 @@ def set_item_locations(self, save=False):
429
435
locations_replica = self .get ("locations" )
430
436
431
437
# reset
432
- self .delete_key ("locations" )
438
+ reset_rows = []
439
+ for row in self .get ("locations" ):
440
+ if not row .picked_qty :
441
+ reset_rows .append (row )
442
+
443
+ for row in reset_rows :
444
+ self .remove (row )
445
+
433
446
updated_locations = frappe ._dict ()
434
447
for item_doc in items :
435
448
item_code = item_doc .item_code
@@ -499,6 +512,9 @@ def aggregate_item_qty(self):
499
512
# aggregate qty for same item
500
513
item_map = OrderedDict ()
501
514
for item in locations :
515
+ if item .picked_qty :
516
+ continue
517
+
502
518
if not item .item_code :
503
519
frappe .throw (f"Row #{ item .idx } : Item Code is Mandatory" )
504
520
if not cint (
0 commit comments