@@ -272,6 +272,12 @@ def validate_qty(self):
272272 continue
273273
274274 items_to_validate = []
275+ selling_negative_rate_allowed = frappe .get_single_value (
276+ "Selling Settings" , "allow_negative_rates_for_items"
277+ )
278+ buying_negative_rate_allowed = frappe .get_single_value (
279+ "Buying Settings" , "allow_negative_rates_for_items"
280+ )
275281
276282 # get unique transactions to update
277283 for d in self .get_all_children ():
@@ -281,15 +287,24 @@ def validate_qty(self):
281287 if hasattr (d , "qty" ) and d .qty > 0 and self .get ("is_return" ):
282288 frappe .throw (_ ("For an item {0}, quantity must be negative number" ).format (d .item_code ))
283289
284- if not frappe .get_single_value ("Selling Settings" , "allow_negative_rates_for_items" ):
290+ if (
291+ not selling_negative_rate_allowed and self .doctype in ["Sales Invoice" , "Delivery Note" ]
292+ ) or (
293+ not buying_negative_rate_allowed
294+ and self .doctype in ["Purchase Invoice" , "Purchase Receipt" ]
295+ ):
285296 if hasattr (d , "item_code" ) and hasattr (d , "rate" ) and flt (d .rate ) < 0 :
286297 frappe .throw (
287298 _ (
288299 "For item {0}, rate must be a positive number. To Allow negative rates, enable {1} in {2}"
289300 ).format (
290301 frappe .bold (d .item_code ),
291302 frappe .bold (_ ("`Allow Negative rates for Items`" )),
292- get_link_to_form ("Selling Settings" , "Selling Settings" ),
303+ get_link_to_form (
304+ "Selling Settings"
305+ if self .doctype in ["Sales Invoice" , "Delivery Note" ]
306+ else "Buying Settings"
307+ ),
293308 ),
294309 )
295310
0 commit comments