@@ -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,24 @@ 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 not row .picked_qty :
93
+ continue
94
+
95
+ if row .batch_no and row .picked_qty :
94
96
batch_qty = get_batch_qty (row .batch_no , row .warehouse , row .item_code )
95
97
96
- if row .qty > batch_qty :
98
+ if row .picked_qty > batch_qty :
97
99
frappe .throw (
98
100
_ (
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 )),
101
+ "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."
102
+ ).format (
103
+ row .idx ,
104
+ row .picked_qty ,
105
+ row .item_code ,
106
+ batch_qty ,
107
+ row .batch_no ,
108
+ bold (row .warehouse ),
109
+ ),
101
110
title = _ ("Insufficient Stock" ),
102
111
)
103
112
@@ -109,11 +118,11 @@ def validate_stock_qty(self):
109
118
"actual_qty" ,
110
119
)
111
120
112
- if row .qty > flt (bin_qty ):
121
+ if row .picked_qty > flt (bin_qty ):
113
122
frappe .throw (
114
123
_ (
115
124
"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 )),
125
+ ).format (row .idx , row .picked_qty , bold (row .item_code ), bin_qty , bold (row .warehouse )),
117
126
title = _ ("Insufficient Stock" ),
118
127
)
119
128
@@ -429,7 +438,14 @@ def set_item_locations(self, save=False):
429
438
locations_replica = self .get ("locations" )
430
439
431
440
# reset
432
- self .delete_key ("locations" )
441
+ reset_rows = []
442
+ for row in self .get ("locations" ):
443
+ if not row .picked_qty :
444
+ reset_rows .append (row )
445
+
446
+ for row in reset_rows :
447
+ self .remove (row )
448
+
433
449
updated_locations = frappe ._dict ()
434
450
for item_doc in items :
435
451
item_code = item_doc .item_code
@@ -499,6 +515,9 @@ def aggregate_item_qty(self):
499
515
# aggregate qty for same item
500
516
item_map = OrderedDict ()
501
517
for item in locations :
518
+ if item .picked_qty :
519
+ continue
520
+
502
521
if not item .item_code :
503
522
frappe .throw (f"Row #{ item .idx } : Item Code is Mandatory" )
504
523
if not cint (
0 commit comments