mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
Merge branch 'master' of github.com:webnotes/erpnext into wsgi
Conflicts: accounts/doctype/account/account.py accounts/doctype/gl_entry/gl_entry.py accounts/doctype/period_closing_voucher/period_closing_voucher.py stock/doctype/delivery_note/delivery_note.py stock/doctype/landed_cost_wizard/landed_cost_wizard.py stock/doctype/purchase_receipt/purchase_receipt.py stock/doctype/stock_ledger/stock_ledger.py stock/doctype/warehouse/warehouse.py stock/stock_ledger.py
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import webnotes
|
||||
from webnotes import msgprint
|
||||
from webnotes.utils import cint, flt, cstr
|
||||
from webnotes.utils import cint, flt, cstr, now
|
||||
from stock.utils import get_valuation_method
|
||||
import json
|
||||
|
||||
@@ -11,8 +11,51 @@ import json
|
||||
class NegativeStockError(webnotes.ValidationError): pass
|
||||
|
||||
_exceptions = webnotes.local('stockledger_exceptions')
|
||||
|
||||
# _exceptions = []
|
||||
|
||||
def make_sl_entries(sl_entries, is_amended=None):
|
||||
from stock.utils import update_bin
|
||||
|
||||
cancel = True if sl_entries[0].get("is_cancelled") == "Yes" else False
|
||||
if cancel:
|
||||
set_as_cancel(sl_entries[0].get('voucher_no'), sl_entries[0].get('voucher_type'))
|
||||
|
||||
for sle in sl_entries:
|
||||
sle_id = None
|
||||
if sle.get('is_cancelled') == 'Yes':
|
||||
sle['actual_qty'] = -flt(sle['actual_qty'])
|
||||
|
||||
if sle.get("actual_qty"):
|
||||
sle_id = make_entry(sle)
|
||||
|
||||
args = sle.copy()
|
||||
args.update({
|
||||
"sle_id": sle_id,
|
||||
"is_amended": is_amended
|
||||
})
|
||||
update_bin(args)
|
||||
|
||||
if cancel:
|
||||
delete_cancelled_entry(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no'))
|
||||
|
||||
def set_as_cancel(voucher_type, voucher_no):
|
||||
webnotes.conn.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes',
|
||||
modified=%s, modified_by=%s
|
||||
where voucher_no=%s and voucher_type=%s""",
|
||||
(now(), webnotes.session.user, voucher_type, voucher_no))
|
||||
|
||||
def make_entry(args):
|
||||
args.update({"doctype": "Stock Ledger Entry"})
|
||||
sle = webnotes.bean([args])
|
||||
sle.ignore_permissions = 1
|
||||
sle.insert()
|
||||
sle.submit()
|
||||
return sle.doc.name
|
||||
|
||||
def delete_cancelled_entry(voucher_type, voucher_no):
|
||||
webnotes.conn.sql("""delete from `tabStock Ledger Entry`
|
||||
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
|
||||
|
||||
def update_entries_after(args, verbose=1):
|
||||
"""
|
||||
update valution rate and qty after transaction
|
||||
@@ -33,13 +76,15 @@ def update_entries_after(args, verbose=1):
|
||||
qty_after_transaction = flt(previous_sle.get("qty_after_transaction"))
|
||||
valuation_rate = flt(previous_sle.get("valuation_rate"))
|
||||
stock_queue = json.loads(previous_sle.get("stock_queue") or "[]")
|
||||
stock_value = 0.0
|
||||
|
||||
stock_value = flt(previous_sle.get("stock_value"))
|
||||
prev_stock_value = flt(previous_sle.get("stock_value"))
|
||||
|
||||
entries_to_fix = get_sle_after_datetime(previous_sle or \
|
||||
{"item_code": args["item_code"], "warehouse": args["warehouse"]}, for_update=True)
|
||||
|
||||
|
||||
valuation_method = get_valuation_method(args["item_code"])
|
||||
|
||||
stock_value_difference = 0.0
|
||||
|
||||
for sle in entries_to_fix:
|
||||
if sle.serial_no or not cint(webnotes.conn.get_default("allow_negative_stock")):
|
||||
# validate negative stock for serialized items, fifo valuation
|
||||
@@ -47,7 +92,7 @@ def update_entries_after(args, verbose=1):
|
||||
if not validate_negative_stock(qty_after_transaction, sle):
|
||||
qty_after_transaction += flt(sle.actual_qty)
|
||||
continue
|
||||
|
||||
|
||||
if sle.serial_no:
|
||||
valuation_rate = get_serialized_values(qty_after_transaction, sle, valuation_rate)
|
||||
elif valuation_method == "Moving Average":
|
||||
@@ -65,13 +110,16 @@ def update_entries_after(args, verbose=1):
|
||||
(qty_after_transaction * valuation_rate) or 0
|
||||
else:
|
||||
stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
|
||||
# print sle.posting_date, sle.actual_qty, sle.incoming_rate, stock_queue, stock_value
|
||||
|
||||
stock_value_difference = stock_value - prev_stock_value
|
||||
prev_stock_value = stock_value
|
||||
|
||||
# update current sle
|
||||
webnotes.conn.sql("""update `tabStock Ledger Entry`
|
||||
set qty_after_transaction=%s, valuation_rate=%s, stock_queue=%s,
|
||||
stock_value=%s where name=%s""",
|
||||
stock_value=%s, stock_value_difference=%s where name=%s""",
|
||||
(qty_after_transaction, valuation_rate,
|
||||
json.dumps(stock_queue), stock_value, sle.name))
|
||||
json.dumps(stock_queue), stock_value, stock_value_difference, sle.name))
|
||||
|
||||
if _exceptions:
|
||||
_raise_exceptions(args, verbose)
|
||||
@@ -126,7 +174,7 @@ def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, fo
|
||||
return webnotes.conn.sql("""select * from `tabStock Ledger Entry`
|
||||
where item_code = %%(item_code)s
|
||||
and warehouse = %%(warehouse)s
|
||||
and ifnull(is_cancelled, 'No') = 'No'
|
||||
and ifnull(is_cancelled, 'No')='No'
|
||||
%(conditions)s
|
||||
order by timestamp(posting_date, posting_time) %(order)s, name %(order)s
|
||||
%(limit)s %(for_update)s""" % {
|
||||
|
||||
Reference in New Issue
Block a user