def repost_future_sle_and_gle(doc): args = frappe._dict({ "posting_date": doc.posting_date, "posting_time": doc.posting_time, "voucher_type": doc.doctype, "voucher_no": doc.name, "company": doc.company }) create_repost_item_valuation_entry(args)
def repost_actual_qty(item_code, warehouse, allow_zero_rate=False, allow_negative_stock=False): create_repost_item_valuation_entry({ "item_code": item_code, "warehouse": warehouse, "posting_date": "1900-01-01", "posting_time": "00:01", "allow_negative_stock": allow_negative_stock, "allow_zero_rate": allow_zero_rate, })
def create_repost_item_valuation(stock_entry): from erpnext.controllers.stock_controller import create_repost_item_valuation_entry # turn on recalculate flag so reposting corrects the incoming/outgoing rates. frappe.db.set_value( "Stock Ledger Entry", { "voucher_no": stock_entry.name, "actual_qty": (">", 0) }, "recalculate_rate", 1, update_modified=False, ) create_repost_item_valuation_entry( args=frappe._dict({ "posting_date": stock_entry.posting_date, "posting_time": stock_entry.posting_time, "voucher_type": stock_entry.doctype, "voucher_no": stock_entry.name, "company": stock_entry.company, }))
def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, posting_time=None, fiscal_year=None): if not posting_date: posting_date = nowdate() if not posting_time: posting_time = nowtime() condition = " and item.name='%s'" % item_code.replace( "'", "'") if item_code else "" bin = frappe.db.sql( """select bin.item_code, bin.warehouse, bin.actual_qty, item.stock_uom from `tabBin` bin, tabItem item where bin.item_code = item.name and item.has_serial_no = 1 %s""" % condition) for d in bin: serial_nos = frappe.db.sql( """select count(name) from `tabSerial No` where item_code=%s and warehouse=%s and docstatus < 2""", (d[0], d[1]), ) sle = frappe.db.sql( """select valuation_rate, company from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and is_cancelled = 0 order by posting_date desc limit 1""", (d[0], d[1]), ) sle_dict = { "doctype": "Stock Ledger Entry", "item_code": d[0], "warehouse": d[1], "transaction_date": nowdate(), "posting_date": posting_date, "posting_time": posting_time, "voucher_type": "Stock Reconciliation (Manual)", "voucher_no": "", "voucher_detail_no": "", "actual_qty": flt(serial_nos[0][0]) - flt(d[2]), "stock_uom": d[3], "incoming_rate": sle and flt(serial_nos[0][0]) > flt(d[2]) and flt(sle[0][0]) or 0, "company": sle and cstr(sle[0][1]) or 0, "batch_no": "", "serial_no": "", } sle_doc = frappe.get_doc(sle_dict) sle_doc.flags.ignore_validate = True sle_doc.flags.ignore_links = True sle_doc.insert() args = sle_dict.copy() args.update({"sle_id": sle_doc.name}) create_repost_item_valuation_entry({ "item_code": d[0], "warehouse": d[1], "posting_date": posting_date, "posting_time": posting_time, })