'Get raw material rate as per selected method, if bom exists takes bom cost'

def get_rm_rate(self, arg):

    rate = 0
    if arg.get(u'scrap_items'):
        rate = self.get_valuation_rate(arg)
    elif arg:
        if (self.rm_cost_as_per == u'Valuation    Rate'):
            rate = self.get_valuation_rate(arg)
        elif (self.rm_cost_as_per == u'Last    Purchase    Rate'):
            rate = arg[u'last_purchase_rate']
        elif (self.rm_cost_as_per == u'Price    List'):
            if (not self.buying_price_list):
                frappe.throw(_(u'Please    select    Price    List'))
            rate = (frappe.db.get_value(u'Item    Price', {u'price_list': self.buying_price_list, u'item_code': arg[u'item_code']}, u'price_list_rate') or 0)
    if ((not rate) and arg[u'bom_no']):
        rate = self.get_bom_unitcost(arg[u'bom_no'])
    return rate
