@frappe.whitelist()
def get_incoming_rate(args):
 from erpnext.stock.stock_ledger import get_previous_sle
 if isinstance(args, basestring):
  args = json.loads(args)
 in_rate = 0
 if (args.get(u'serial_no') or u'').strip():
  in_rate = get_avg_purchase_rate(args.get(u'serial_no'))
 else:
  valuation_method = get_valuation_method(args.get(u'item_code'))
  previous_sle = get_previous_sle(args)
  if (valuation_method == u'FIFO'):
   if (not previous_sle):
    return 0.0
   previous_stock_queue = json.loads((previous_sle.get(u'stock_queue', u'[]') or u'[]'))
   in_rate = (get_fifo_rate(previous_stock_queue, (args.get(u'qty') or 0)) if previous_stock_queue else 0)
  elif (valuation_method == u'Moving Average'):
   in_rate = (previous_sle.get(u'valuation_rate') or 0)
 return in_rate

@ frappe . whitelist ( ) def get_incoming_rate ( args ) : from erpnext . stock . stock_ledger import get_previous_sle if isinstance ( args , basestring ) : args = json . loads ( args ) in_rate = 0 if ( args . get ( u'serial_no' ) or u'' ) . strip ( ) : in_rate = get_avg_purchase_rate ( args . get ( u'serial_no' ) ) else : valuation_method = get_valuation_method ( args . get ( u'item_code' ) ) previous_sle = get_previous_sle ( args ) if ( valuation_method == u'FIFO' ) : if ( not previous_sle ) : return 0.0 previous_stock_queue = json . loads ( ( previous_sle . get ( u'stock_queue' , u'[]' ) or u'[]' ) ) in_rate = ( get_fifo_rate ( previous_stock_queue , ( args . get ( u'qty' ) or 0 ) ) if previous_stock_queue else 0 ) elif ( valuation_method == u'Moving Average' ) : in_rate = ( previous_sle . get ( u'valuation_rate' ) or 0 ) return in_rate
get incoming rate based on valuation method .