diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 2ed664c9bf..3f6f1bb971 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -329,7 +329,7 @@ class GrossProfitGenerator(object): where company=%(company)s order by item_code desc, warehouse desc, posting_date desc, - posting_time desc, name desc""", self.filters, as_dict=True) + posting_time desc, creation desc""", self.filters, as_dict=True) self.sle = {} for r in res: if (r.item_code, r.warehouse) not in self.sle: diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 684a2cdbcb..b8a361fa5f 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -179,7 +179,7 @@ class SellingController(StockController): last_valuation_rate = frappe.db.sql(""" SELECT valuation_rate FROM `tabStock Ledger Entry` WHERE item_code = %s AND warehouse = %s AND valuation_rate > 0 - ORDER BY posting_date DESC, posting_time DESC, name DESC LIMIT 1 + ORDER BY posting_date DESC, posting_time DESC, creation DESC LIMIT 1 """, (it.item_code, it.warehouse)) if last_valuation_rate: last_valuation_rate_in_sales_uom = last_valuation_rate[0][0] / (it.conversion_factor or 1) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 63e89ab6e3..0c7927438a 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -413,7 +413,7 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no from `tabStock Ledger Entry` sle where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) {condition} - order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(condition=condition), + order by timestamp(sle.posting_date, sle.posting_time) asc, creation asc""".format(condition=condition), tuple([posting_date, posting_time] + values), as_dict=True): future_stock_vouchers.append([d.voucher_type, d.voucher_no]) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index a8053cdf4a..c2a576a104 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -246,7 +246,7 @@ class BOM(WebsiteGenerator): last_valuation_rate = frappe.db.sql("""select valuation_rate from `tabStock Ledger Entry` where item_code = %s and valuation_rate > 0 - order by posting_date desc, posting_time desc, name desc limit 1""", args['item_code']) + order by posting_date desc, posting_time desc, creation desc limit 1""", args['item_code']) valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0 diff --git a/erpnext/startup/report_data_map.py b/erpnext/startup/report_data_map.py index fec2deaf41..1eaf738dde 100644 --- a/erpnext/startup/report_data_map.py +++ b/erpnext/startup/report_data_map.py @@ -79,7 +79,7 @@ data_map = { "actual_qty as qty", "voucher_type", "voucher_no", "project", "incoming_rate as incoming_rate", "stock_uom", "serial_no", "qty_after_transaction", "valuation_rate"], - "order_by": "posting_date, posting_time, name", + "order_by": "posting_date, posting_time, creation", "links": { "item_code": ["Item", "name"], "warehouse": ["Warehouse", "name"], diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index f86a77dea1..aa5c69e64f 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -60,7 +60,7 @@ class Bin(Document): select * from `tabStock Ledger Entry` where item_code = %s and warehouse = %s - order by timestamp(posting_date, posting_time) asc, name asc + order by timestamp(posting_date, posting_time) asc, creation asc limit 1 """, (self.item_code, self.warehouse), as_dict=1) return sle and sle[0] or None diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index d070af05c8..8602c95bec 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -136,7 +136,7 @@ class SerialNo(StockController): sle_dict = {} for sle in frappe.db.sql("""select * from `tabStock Ledger Entry` where serial_no like %s and item_code=%s and ifnull(is_cancelled, 'No')='No' - order by posting_date desc, posting_time desc, name desc""", + order by posting_date desc, posting_time desc, creation desc""", ("%%%s%%" % self.name, self.item_code), as_dict=1): if self.name.upper() in get_serial_nos(sle.serial_no): if sle.actual_qty > 0: diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index d9df18d212..9095075b41 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -27,7 +27,7 @@ def get_sle(**args): values.append(value) return frappe.db.sql("""select * from `tabStock Ledger Entry` %s - order by timestamp(posting_date, posting_time) desc, name desc limit 1"""% condition, + order by timestamp(posting_date, posting_time) desc, creation desc limit 1"""% condition, values, as_dict=1) class TestStockEntry(unittest.TestCase): diff --git a/erpnext/stock/report/stock_ageing/stock_ageing.py b/erpnext/stock/report/stock_ageing/stock_ageing.py index ecdd96ac4f..ae3d72ee4f 100644 --- a/erpnext/stock/report/stock_ageing/stock_ageing.py +++ b/erpnext/stock/report/stock_ageing/stock_ageing.py @@ -81,7 +81,7 @@ def get_stock_ledger_entries(filters): company = %(company)s and posting_date <= %(to_date)s {sle_conditions} - order by posting_date, posting_time, sle.name"""\ + order by posting_date, posting_time, sle.creation"""\ .format(item_conditions=get_item_conditions(filters), sle_conditions=get_sle_conditions(filters)), filters, as_dict=True) diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index cc1112c0c0..14b1852a7f 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -130,7 +130,7 @@ def get_stock_ledger_entries(filters, items): from `tabStock Ledger Entry` sle force index (posting_sort_index) where sle.docstatus < 2 %s %s - order by sle.posting_date, sle.posting_time, sle.name""" % + order by sle.posting_date, sle.posting_time, sle.creation""" % (item_conditions_sql, conditions), as_dict=1) def get_item_warehouse_map(filters, sle): diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 805b314ca1..acb3df5541 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -77,7 +77,7 @@ def get_stock_ledger_entries(filters, items): posting_date between %(from_date)s and %(to_date)s {sle_conditions} {item_conditions_sql} - order by posting_date asc, posting_time asc, name asc"""\ + order by posting_date asc, posting_time asc, creation asc"""\ .format( sle_conditions=get_sle_conditions(filters), item_conditions_sql = item_conditions_sql diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 09d4e43840..0dbb7f82be 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -59,7 +59,7 @@ def repost_actual_qty(item_code, warehouse, allow_zero_rate=False): def get_balance_qty_from_sle(item_code, warehouse): balance_qty = frappe.db.sql("""select qty_after_transaction from `tabStock Ledger Entry` where item_code=%s and warehouse=%s and is_cancelled='No' - order by posting_date desc, posting_time desc, name desc + order by posting_date desc, posting_time desc, creation desc limit 1""", (item_code, warehouse)) return flt(balance_qty[0][0]) if balance_qty else 0.0 @@ -235,7 +235,7 @@ def repost_all_stock_vouchers(): vouchers = frappe.db.sql("""select distinct voucher_type, voucher_no from `tabStock Ledger Entry` sle where voucher_type != "Serial No" and sle.warehouse in (%s) - order by posting_date, posting_time, name""" % + order by posting_date, posting_time, creation""" % ', '.join(['%s']*len(warehouses_with_account)), tuple(warehouses_with_account)) rejected = [] diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 0ef2afa4a8..c8706b291e 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -432,7 +432,7 @@ def get_stock_ledger_entries(previous_sle, operator=None, order="desc", limit=No where item_code = %%(item_code)s and ifnull(is_cancelled, 'No')='No' %(conditions)s - order by timestamp(posting_date, posting_time) %(order)s, name %(order)s + order by timestamp(posting_date, posting_time) %(order)s, creation %(order)s %(limit)s %(for_update)s""" % { "conditions": conditions, "limit": limit or "", @@ -450,14 +450,14 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, from `tabStock Ledger Entry` where item_code = %s and warehouse = %s and valuation_rate >= 0 - order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse)) + order by posting_date desc, posting_time desc, creation desc limit 1""", (item_code, warehouse)) if not last_valuation_rate: # Get valuation rate from last sle for the item against any warehouse last_valuation_rate = frappe.db.sql("""select valuation_rate from `tabStock Ledger Entry` where item_code = %s and valuation_rate > 0 - order by posting_date desc, posting_time desc, name desc limit 1""", item_code) + order by posting_date desc, posting_time desc, creation desc limit 1""", item_code) if last_valuation_rate: return flt(last_valuation_rate[0][0]) # as there is previous records, it might come with zero rate diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index de31c54f96..c89fc10973 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -62,7 +62,7 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): SELECT item_code, stock_value, name, warehouse FROM `tabStock Ledger Entry` sle WHERE posting_date <= %s {0} - ORDER BY timestamp(posting_date, posting_time) DESC, name DESC + ORDER BY timestamp(posting_date, posting_time) DESC, creation DESC """.format(condition), values, as_dict=1) sle_map = {}