'get stock and incoming rate on posting date'

def set_basic_rate(self, force=False, update_finished_item_rate=True):

    raw_material_cost = 0.0
    scrap_material_cost = 0.0
    fg_basic_rate = 0.0
    for d in self.get(u'items'):
        if d.t_warehouse:
            fg_basic_rate = flt(d.basic_rate)
        args = frappe._dict({u'item_code': d.item_code, u'warehouse': (d.s_warehouse or d.t_warehouse), u'posting_date': self.posting_date, u'posting_time': self.posting_time, u'qty': ((d.s_warehouse and ((-1) * flt(d.transfer_qty))) or flt(d.transfer_qty)), u'serial_no': d.serial_no})
        if (not d.bom_no):
            if ((not flt(d.basic_rate)) or d.s_warehouse or force):
                basic_rate = flt(get_incoming_rate(args), self.precision(u'basic_rate', d))
                if (basic_rate > 0):
                    d.basic_rate = basic_rate
            d.basic_amount = flt((flt(d.transfer_qty) * flt(d.basic_rate)), d.precision(u'basic_amount'))
            if (not d.t_warehouse):
                raw_material_cost += flt(d.basic_amount)
        if d.bom_no:
            if ((not flt(d.basic_rate)) and (getattr(self, u'pro_doc', frappe._dict()).scrap_warehouse == d.t_warehouse)):
                basic_rate = flt(get_incoming_rate(args), self.precision(u'basic_rate', d))
                if (basic_rate > 0):
                    d.basic_rate = basic_rate
                d.basic_amount = flt((flt(d.transfer_qty) * flt(d.basic_rate)), d.precision(u'basic_amount'))
            if (getattr(self, u'pro_doc', frappe._dict()).scrap_warehouse == d.t_warehouse):
                scrap_material_cost += flt(d.basic_amount)
    number_of_fg_items = len([t.t_warehouse for t in self.get(u'items') if t.t_warehouse])
    if (((fg_basic_rate == 0.0) and (number_of_fg_items == 1)) or update_finished_item_rate):
        self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost)
