fix(naming): Use creation instead of name to order SLEs
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index 2ed664c..3f6f1bb 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -329,7 +329,7 @@
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 684a2cd..b8a361f 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -179,7 +179,7 @@
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 63e89ab..0c79274 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -413,7 +413,7 @@
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 a8053cd..c2a576a 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -246,7 +246,7 @@
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 fec2dea..1eaf738 100644
--- a/erpnext/startup/report_data_map.py
+++ b/erpnext/startup/report_data_map.py
@@ -79,7 +79,7 @@
"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 f86a77d..aa5c69e 100644
--- a/erpnext/stock/doctype/bin/bin.py
+++ b/erpnext/stock/doctype/bin/bin.py
@@ -60,7 +60,7 @@
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 d070af0..8602c95 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -136,7 +136,7 @@
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 d9df18d..9095075 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 @@
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 ecdd96a..ae3d72e 100644
--- a/erpnext/stock/report/stock_ageing/stock_ageing.py
+++ b/erpnext/stock/report/stock_ageing/stock_ageing.py
@@ -81,7 +81,7 @@
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 cc1112c..14b1852 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.py
+++ b/erpnext/stock/report/stock_balance/stock_balance.py
@@ -130,7 +130,7 @@
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 805b314..acb3df5 100644
--- a/erpnext/stock/report/stock_ledger/stock_ledger.py
+++ b/erpnext/stock/report/stock_ledger/stock_ledger.py
@@ -77,7 +77,7 @@
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 09d4e43..0dbb7f8 100644
--- a/erpnext/stock/stock_balance.py
+++ b/erpnext/stock/stock_balance.py
@@ -59,7 +59,7 @@
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 @@
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 0ef2afa..c8706b2 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -432,7 +432,7 @@
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 @@
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 de31c54..c89fc10 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -62,7 +62,7 @@
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 = {}