fix: get serial nos based on posting date and time
This commit is contained in:
parent
94a505d31c
commit
560f822dbf
@ -488,12 +488,14 @@ def get_stock_balance_for(item_code, warehouse,
|
||||
["has_serial_no", "has_batch_no"], as_dict=1)
|
||||
|
||||
serial_nos = ""
|
||||
if item_dict.get("has_serial_no"):
|
||||
qty, rate, serial_nos = get_qty_rate_for_serial_nos(item_code,
|
||||
warehouse, posting_date, posting_time, item_dict)
|
||||
with_serial_no = True if item_dict.get("has_serial_no") else False
|
||||
data = get_stock_balance(item_code, warehouse, posting_date, posting_time,
|
||||
with_valuation_rate=with_valuation_rate, with_serial_no=with_serial_no)
|
||||
|
||||
if with_serial_no:
|
||||
qty, rate, serial_nos = data
|
||||
else:
|
||||
qty, rate = get_stock_balance(item_code, warehouse,
|
||||
posting_date, posting_time, with_valuation_rate=with_valuation_rate)
|
||||
qty, rate = data
|
||||
|
||||
if item_dict.get("has_batch_no"):
|
||||
qty = get_batch_qty(batch_no, warehouse) or 0
|
||||
@ -504,28 +506,6 @@ def get_stock_balance_for(item_code, warehouse,
|
||||
'serial_nos': serial_nos
|
||||
}
|
||||
|
||||
def get_qty_rate_for_serial_nos(item_code, warehouse, posting_date, posting_time, item_dict):
|
||||
args = {
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"posting_date": posting_date,
|
||||
"posting_time": posting_time,
|
||||
}
|
||||
|
||||
serial_nos_list = [serial_no.get("name")
|
||||
for serial_no in get_available_serial_nos(args)]
|
||||
|
||||
qty = len(serial_nos_list)
|
||||
serial_nos = '\n'.join(serial_nos_list)
|
||||
args.update({
|
||||
'qty': qty,
|
||||
"serial_nos": serial_nos
|
||||
})
|
||||
|
||||
rate = get_incoming_rate(args, raise_error_if_no_rate=False) or 0
|
||||
|
||||
return qty, rate, serial_nos
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_difference_account(purpose, company):
|
||||
if purpose == 'Stock Reconciliation':
|
||||
|
@ -35,7 +35,7 @@ def get_data(report_filters):
|
||||
gl_data = voucher_wise_gl_data.get(key) or {}
|
||||
d.account_value = gl_data.get("account_value", 0)
|
||||
d.difference_value = (d.stock_value - d.account_value)
|
||||
if abs(d.difference_value) > 1.0/10 ** currency_precision:
|
||||
if abs(d.difference_value) > 0.1:
|
||||
data.append(d)
|
||||
|
||||
return data
|
||||
|
@ -74,7 +74,8 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None):
|
||||
return sum(sle_map.values())
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None, with_valuation_rate=False):
|
||||
def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None,
|
||||
with_valuation_rate=False, with_serial_no=False):
|
||||
"""Returns stock balance quantity at given warehouse on given posting date or current date.
|
||||
|
||||
If `with_valuation_rate` is True, will return tuple (qty, rate)"""
|
||||
@ -84,17 +85,51 @@ def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None
|
||||
if not posting_date: posting_date = nowdate()
|
||||
if not posting_time: posting_time = nowtime()
|
||||
|
||||
last_entry = get_previous_sle({
|
||||
args = {
|
||||
"item_code": item_code,
|
||||
"warehouse":warehouse,
|
||||
"posting_date": posting_date,
|
||||
"posting_time": posting_time })
|
||||
"posting_time": posting_time
|
||||
}
|
||||
|
||||
last_entry = get_previous_sle(args)
|
||||
|
||||
if with_valuation_rate:
|
||||
return (last_entry.qty_after_transaction, last_entry.valuation_rate) if last_entry else (0.0, 0.0)
|
||||
if with_serial_no:
|
||||
serial_nos = last_entry.get("serial_no")
|
||||
|
||||
if (serial_nos and
|
||||
len(get_serial_nos_data(serial_nos)) < last_entry.qty_after_transaction):
|
||||
serial_nos = get_serial_nos_data_after_transactions(args)
|
||||
|
||||
return ((last_entry.qty_after_transaction, last_entry.valuation_rate, serial_nos)
|
||||
if last_entry else (0.0, 0.0, 0.0))
|
||||
else:
|
||||
return (last_entry.qty_after_transaction, last_entry.valuation_rate) if last_entry else (0.0, 0.0)
|
||||
else:
|
||||
return last_entry.qty_after_transaction if last_entry else 0.0
|
||||
|
||||
def get_serial_nos_data_after_transactions(args):
|
||||
serial_nos = []
|
||||
data = frappe.db.sql(""" SELECT serial_no, actual_qty
|
||||
FROM `tabStock Ledger Entry`
|
||||
WHERE
|
||||
item_code = %(item_code)s and warehouse = %(warehouse)s
|
||||
and timestamp(posting_date, posting_time) < timestamp(%(posting_date)s, %(posting_time)s)
|
||||
order by posting_date, posting_time asc """, args, as_dict=1)
|
||||
|
||||
for d in data:
|
||||
if d.actual_qty > 0:
|
||||
serial_nos.extend(get_serial_nos_data(d.serial_no))
|
||||
else:
|
||||
serial_nos = list(set(serial_nos) - set(get_serial_nos_data(d.serial_no)))
|
||||
|
||||
return '\n'.join(serial_nos)
|
||||
|
||||
def get_serial_nos_data(serial_nos):
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
return get_serial_nos(serial_nos)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_latest_stock_qty(item_code, warehouse=None):
|
||||
values, condition = [item_code], ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user