'find difference between current and expected entries
and create stock ledger entries based on the difference'

def update_stock_ledger(self):

    from erpnext.stock.stock_ledger import get_previous_sle
    for row in self.items:
        previous_sle = get_previous_sle({u'item_code': row.item_code, u'warehouse': row.warehouse, u'posting_date': self.posting_date, u'posting_time': self.posting_time})
        if previous_sle:
            if (row.qty in (u'', None)):
                row.qty = previous_sle.get(u'qty_after_transaction', 0)
            if (row.valuation_rate in (u'', None)):
                row.valuation_rate = previous_sle.get(u'valuation_rate', 0)
        if (row.qty and (not row.valuation_rate)):
            frappe.throw(_(u'Valuation    Rate    required    for    Item    in    row    {0}').format(row.idx))
        if ((previous_sle and (row.qty == previous_sle.get(u'qty_after_transaction')) and (row.valuation_rate == previous_sle.get(u'valuation_rate'))) or ((not previous_sle) and (not row.qty))):
            continue
        self.insert_entries(row)
