def delete_and_repost_sle(self): """ Delete Stock Ledger Entries related to this voucher and repost future Stock Ledger Entries""" existing_entries = frappe.db.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name), as_dict=1) # delete entries frappe.db.sql( """delete from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name)) sl_entries = [] for row in self.items: if row.serial_no or row.batch_no or row.current_serial_no: self.get_sle_for_serialized_items(row, sl_entries) if sl_entries: sl_entries.reverse() self.make_sl_entries(sl_entries) # repost future entries for selected item_code, warehouse for entries in existing_entries: update_entries_after({ "item_code": entries.item_code, "warehouse": entries.warehouse, "posting_date": self.posting_date, "posting_time": self.posting_time })
def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) if args.get("actual_qty") or args.get( "voucher_type") == "Stock Reconciliation": from erpnext.stock.stock_ledger import update_entries_after if not args.get("posting_date"): args["posting_date"] = nowdate() update_entries_after( { "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time"), "voucher_no": args.get("voucher_no"), "sle_id": args.sle_id }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher)
def execute(): for doctype in ('repost_item_valuation', 'stock_entry_detail', 'purchase_receipt_item', 'purchase_invoice_item', 'delivery_note_item', 'sales_invoice_item', 'packed_item'): frappe.reload_doc('stock', 'doctype', doctype) frappe.reload_doc('buying', 'doctype', 'purchase_receipt_item_supplied') reposting_project_deployed_on = get_creation_time() posting_date = getdate(reposting_project_deployed_on) posting_time = get_time(reposting_project_deployed_on) if posting_date == today(): return frappe.clear_cache() frappe.flags.warehouse_account_map = {} company_list = [] data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time, company FROM `tabStock Ledger Entry` WHERE creation > %s and is_cancelled = 0 ORDER BY timestamp(posting_date, posting_time) asc, creation asc ''', reposting_project_deployed_on, as_dict=1) frappe.db.auto_commit_on_many_writes = 1 print("Reposting Stock Ledger Entries...") total_sle = len(data) i = 0 for d in data: if d.company not in company_list: company_list.append(d.company) update_entries_after({ "item_code": d.item_code, "warehouse": d.warehouse, "posting_date": d.posting_date, "posting_time": d.posting_time, "voucher_type": d.voucher_type, "voucher_no": d.voucher_no, "sle_id": d.name }, allow_negative_stock=True) i += 1 if i%100 == 0: print(i, "/", total_sle) print("Reposting General Ledger Entries...") if data: for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): if row.name in company_list: update_gl_entries_after(posting_date, posting_time, company=row.name) frappe.db.auto_commit_on_many_writes = 0
def update_stock_ledger_entry(item_code, new_stock_uom, conversion_factor): # update stock ledger entry from erpnext.stock.stock_ledger import update_entries_after if flt(conversion_factor) != flt(1): frappe.db.sql("""update `tabStock Ledger Entry` set stock_uom = %s, actual_qty = ifnull(actual_qty,0) * %s, qty_after_transaction = ifnull(qty_after_transaction, 0) * %s where item_code = %s""", (new_stock_uom, conversion_factor, conversion_factor, item_code)) else: frappe.db.sql("""update `tabStock Ledger Entry` set stock_uom=%s where item_code=%s""", (new_stock_uom, item_code)) # acknowledge user frappe.msgprint(_("Stock Ledger entries balances updated")) # update item valuation if flt(conversion_factor) != flt(1): wh = frappe.db.sql("select name from `tabWarehouse`") for w in wh: update_entries_after({"item_code": item_code, "warehouse": w[0]}) # acknowledge user frappe.msgprint(_("Item valuation updated"))
def update_stock(bin_name, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' update_qty(bin_name, args) if args.get("actual_qty") or args.get( "voucher_type") == "Stock Reconciliation": from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle if not args.get("posting_date"): args["posting_date"] = nowdate() if args.get("is_cancelled") and via_landed_cost_voucher: return # Reposts only current voucher SL Entries # Updates valuation rate, stock value, stock queue for current transaction update_entries_after( { "item_code": args.get('item_code'), "warehouse": args.get('warehouse'), "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time"), "voucher_type": args.get("voucher_type"), "voucher_no": args.get("voucher_no"), "sle_id": args.get('name'), "creation": args.get('creation') }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) # update qty in future sle and Validate negative qty update_qty_in_future_sle(args, allow_negative_stock)
def update_stock_ledger_entry(self): # update stock ledger entry from erpnext.stock.stock_ledger import update_entries_after if flt(self.doc.conversion_factor) != flt(1): frappe.db.sql( "update `tabStock Ledger Entry` set stock_uom = '%s', actual_qty = ifnull(actual_qty,0) * '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.item_code)) else: frappe.db.sql( "update `tabStock Ledger Entry` set stock_uom = '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.item_code)) # acknowledge user msgprint("Stock Ledger Entries Updated Successfully.") # update item valuation if flt(self.doc.conversion_factor) != flt(1): wh = frappe.db.sql("select name from `tabWarehouse`") for w in wh: update_entries_after({ "item_code": self.doc.item_code, "warehouse": w[0] }) # acknowledge user msgprint("Item Valuation Updated Successfully.")
def delete_and_repost_sle(self): """ Delete Stock Ledger Entries related to this voucher and repost future Stock Ledger Entries""" existing_entries = frappe.db.sql( """select distinct item_code, warehouse from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name), as_dict=1, ) # delete entries frappe.db.sql( """delete from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name), ) # repost future entries for selected item_code, warehouse for entries in existing_entries: update_entries_after( { "item_code": entries.item_code, "warehouse": entries.warehouse, "posting_date": self.posting_date, "posting_time": self.posting_time, } )
def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) if args.get("actual_qty") or args.get( "voucher_type") == "Stock Reconciliation": from erpnext.stock.stock_ledger import update_entries_after if not args.get("posting_date"): args["posting_date"] = nowdate() # update valuation and qty after transaction for post dated entry if args.get("is_cancelled") == "Yes" and via_landed_cost_voucher: return update_entries_after( { "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time"), "voucher_no": args.get("voucher_no") }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher)
def delete_and_repost_sle(self): """ Delete Stock Ledger Entries related to this voucher and repost future Stock Ledger Entries""" existing_entries = frappe.db.sql( """select distinct item_code, warehouse from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name), as_dict=1) # delete entries frappe.db.sql( """delete from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name)) sl_entries = [] self.get_sle_for_serialized_items(sl_entries) if sl_entries: sl_entries.reverse() allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock") self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock) # repost future entries for selected item_code, warehouse for entries in existing_entries: update_entries_after({ "item_code": entries.item_code, "warehouse": entries.warehouse, "posting_date": self.posting_date, "posting_time": self.posting_time })
def update_stock_ledger_entry(item_code, new_stock_uom, conversion_factor): # update stock ledger entry from erpnext.stock.stock_ledger import update_entries_after if flt(conversion_factor) != flt(1): frappe.db.sql( """update `tabStock Ledger Entry` set stock_uom = %s, actual_qty = ifnull(actual_qty,0) * %s where item_code = %s""", (new_stock_uom, conversion_factor, item_code)) else: frappe.db.sql( """update `tabStock Ledger Entry` set stock_uom=%s where item_code=%s""", (new_stock_uom, item_code)) # acknowledge user frappe.msgprint(_("Stock Ledger entries balances updated")) # update item valuation if flt(conversion_factor) != flt(1): wh = frappe.db.sql("select name from `tabWarehouse`") for w in wh: update_entries_after({"item_code": item_code, "warehouse": w[0]}) # acknowledge user frappe.msgprint(_("Item valuation updated"))
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])) if serial_nos and flt(serial_nos[0][0]) != flt(d[2]): print(d[0], d[1], d[2], serial_nos[0][0]) sle = frappe.db.sql("""select valuation_rate, company from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and ifnull(is_cancelled, 'No') = 'No' 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, 'is_cancelled' : 'No', '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, "is_amended": 'No' }) update_bin(args) update_entries_after({ "item_code": d[0], "warehouse": d[1], "posting_date": posting_date, "posting_time": posting_time })
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])) if serial_nos and flt(serial_nos[0][0]) != flt(d[2]): print d[0], d[1], d[2], serial_nos[0][0] sle = frappe.db.sql("""select valuation_rate, company from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and ifnull(is_cancelled, 'No') = 'No' 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, 'is_cancelled' : 'No', '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, "is_amended": 'No' }) update_bin(args) update_entries_after({ "item_code": d[0], "warehouse": d[1], "posting_date": posting_date, "posting_time": posting_time })
def repost_actual_qty(item_code, warehouse, allow_zero_rate=False): try: update_entries_after({ "item_code": item_code, "warehouse": warehouse }, allow_zero_rate) except: pass
def set_valuation_method(item_code, valuation_method): frappe.db.set_value("Item", item_code, "valuation_method", valuation_method) for warehouse in frappe.get_all("Warehouse", filters={"company": "_Test Company"}): update_entries_after({ "item_code": item_code, "warehouse": warehouse.name }, allow_negative_stock=1)
def set_valuation_method(item_code, valuation_method): frappe.db.set_value("Item", item_code, "valuation_method", valuation_method) for warehouse in frappe.get_all("Warehouse", filters={"company": "_Test Company"}, fields=["name", "is_group"]): if not warehouse.is_group: update_entries_after({ "item_code": item_code, "warehouse": warehouse.name }, allow_negative_stock=1)
def repost_stock_as_per_valuation_method(valuation_method): frappe.db.set_value("Item", "_Test Item", "valuation_method", valuation_method) update_entries_after( { "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", }, allow_negative_stock=1)
def repost_actual_qty(item_code, warehouse, allow_zero_rate=False, allow_negative_stock=False): update_entries_after({ "item_code": item_code, "warehouse": warehouse }, allow_zero_rate=allow_zero_rate, allow_negative_stock=allow_negative_stock)
def update_stock(self, args): self.update_qty(args) if args.get("actual_qty"): from erpnext.stock.stock_ledger import update_entries_after if not args.get("posting_date"): args["posting_date"] = nowdate() # update valuation and qty after transaction for post dated entry update_entries_after({ "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time") })
def update_stock(self, args, allow_negative_stock=False): self.update_qty(args) if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": from erpnext.stock.stock_ledger import update_entries_after if not args.get("posting_date"): args["posting_date"] = nowdate() # update valuation and qty after transaction for post dated entry update_entries_after({ "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time") }, allow_negative_stock=allow_negative_stock)
def execute(): try: year_start_date = get_fiscal_year(today())[1] except: return if year_start_date: items = frappe.db.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry` where ifnull(serial_no, '') != '' and actual_qty > 0 and incoming_rate=0""", as_dict=1) for d in items: try: update_entries_after({ "item_code": d.item_code, "warehouse": d.warehouse, "posting_date": year_start_date }, allow_zero_rate=True) except: pass
def delete_and_repost_sle(self): """ Delete Stock Ledger Entries related to this voucher and repost future Stock Ledger Entries""" existing_entries = frappe.db.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name), as_dict=1) # delete entries frappe.db.sql("""delete from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""", (self.doctype, self.name)) # repost future entries for selected item_code, warehouse for entries in existing_entries: update_entries_after({ "item_code": entries.item_code, "warehouse": entries.warehouse, "posting_date": self.posting_date, "posting_time": self.posting_time })
def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": from erpnext.stock.stock_ledger import update_entries_after if not args.get("posting_date"): args["posting_date"] = nowdate() # update valuation and qty after transaction for post dated entry if args.get("is_cancelled") == "Yes" and via_landed_cost_voucher: return update_entries_after({ "item_code": self.item_code, "warehouse": self.warehouse, "posting_date": args.get("posting_date"), "posting_time": args.get("posting_time"), "voucher_no": args.get("voucher_no") }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher)
def execute(): try: year_start_date = get_fiscal_year(today())[1] except: return if year_start_date: items = frappe.db.sql( """select distinct item_code, warehouse from `tabStock Ledger Entry` where ifnull(serial_no, '') != '' and actual_qty > 0 and incoming_rate=0""", as_dict=1, ) for d in items: try: update_entries_after( {"item_code": d.item_code, "warehouse": d.warehouse, "posting_date": year_start_date}, allow_zero_rate=True, ) except: pass
def execute(): data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0 order by timestamp(posting_date, posting_time) asc, creation asc''', as_dict=1) for index, d in enumerate(data): update_entries_after({ "item_code": d.item_code, "warehouse": d.warehouse, "posting_date": d.posting_date, "posting_time": d.posting_time, "voucher_type": d.voucher_type, "voucher_no": d.voucher_no, "sle_id": d.name }, allow_negative_stock=True) frappe.db.auto_commit_on_many_writes = 1 for row in frappe.get_all('Company', filters= {'enable_perpetual_inventory': 1}): update_gl_entries_after('2020-12-25', '01:58:55', company=row.name) frappe.db.auto_commit_on_many_writes = 0
def purchase_invoice_on_update_after_submit(doc, method): doc.validate() frappe.db.sql("""delete from `tabGL Entry` where voucher_no=%(vname)s""", { 'vname': doc.name }) doc.update_valuation_rate("items") doc.update_children() doc.db_update() if cint(doc.update_stock): for i in doc.items: update_incoming_rate_serial_no(get_serial_nos(i.serial_no), i.valuation_rate) frappe.db.sql("""delete from `tabStock Ledger Entry` where voucher_no=%(vname)s""", { 'vname': doc.name }) #raw_input("Press Enter to continue...") doc.update_stock_ledger() doc.make_gl_entries(repost_future_gle=False) if cint(doc.update_stock): for i in doc.items: update_entries_after({ "item_code": i.item_code, "warehouse": i.warehouse, "posting_time": doc.posting_time, "posting_date": doc.posting_date #get_fiscal_year(today())[1] }, allow_zero_rate=True) if cint(doc.update_stock): for i in doc.items: repost_se(i.item_code) repost_si(i.item_code) repost_dn(i.item_code) update_outstanding_amt(doc.credit_to, "Supplier", doc.supplier,doc.doctype, doc.name) frappe.db.commit()
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() if not fiscal_year: fiscal_year = get_fiscal_year(posting_date)[0] 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 = 'Yes' %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 status = 'Available' and docstatus < 2""", (d[0], d[1]), ) if serial_nos and flt(serial_nos[0][0]) != flt(d[2]): print d[0], d[1], d[2], serial_nos[0][0] sle = frappe.db.sql( """select valuation_rate, company from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and ifnull(is_cancelled, 'No') = 'No' 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, "fiscal_year": fiscal_year, "is_cancelled": "No", "batch_no": "", "serial_no": "", } sle_doc = frappe.get_doc(sle_dict) sle_doc.insert() args = sle_dict.copy() args.update({"sle_id": sle_doc.name, "is_amended": "No"}) update_bin(args) update_entries_after( {"item_code": d[0], "warehouse": d[1], "posting_date": posting_date, "posting_time": posting_time} )
def repost_actual_qty(item_code, warehouse): try: update_entries_after({"item_code": item_code, "warehouse": warehouse}) except: pass
def repost_actual_qty(item_code, warehouse): from erpnext.stock.stock_ledger import update_entries_after try: update_entries_after({"item_code": item_code, "warehouse": warehouse}) except: pass
def repost_actual_qty(item_code, warehouse): try: update_entries_after({ "item_code": item_code, "warehouse": warehouse }) except: pass
def repost_stock_as_per_valuation_method(valuation_method): frappe.db.set_value("Item", "_Test Item", "valuation_method", valuation_method) update_entries_after({ "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", }, allow_negative_stock=1)