fix(naming): Use creation instead of name to order SLEs

This commit is contained in:
Aditya Hase 2019-01-07 22:07:13 +05:30
parent 972f659fd5
commit 0c16424d7d
14 changed files with 17 additions and 17 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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])

View File

@ -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

View File

@ -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"],

View File

@ -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

View File

@ -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:

View File

@ -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):

View File

@ -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)

View File

@ -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):

View File

@ -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

View File

@ -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 = []

View File

@ -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

View File

@ -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 = {}