negative stock fixes
diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py
index 8606533..8e1c949 100644
--- a/erpnext/stock/doctype/bin/bin.py
+++ b/erpnext/stock/doctype/bin/bin.py
@@ -183,6 +183,7 @@
# get moving average inventory values
# ------------------------------------
def get_moving_average_inventory_values(self, val_rate, in_rate, opening_qty, actual_qty, is_cancelled):
+ #msgprint(actual_qty)
if flt(in_rate) <= 0: # In case of delivery/stock issue in_rate = 0 or wrong incoming rate
in_rate = val_rate
@@ -191,9 +192,8 @@
# 2. cancelled entry
# 3. val_rate is negative
# Otherwise it will be calculated as per moving average
- elif actual_qty > 0 and (opening_qty + actual_qty) > 0 and is_cancelled == 'No' and ((opening_qty * val_rate) + (actual_qty * in_rate)) > 0:
- if opening_qty < 0:
- opening_qty = 0
+ if actual_qty > 0 and (opening_qty + actual_qty) > 0 and is_cancelled == 'No' and ((opening_qty * val_rate) + (actual_qty * in_rate)) > 0:
+ opening_qty = opening_qty > 0 and opening_qty or 0
val_rate = ((opening_qty *val_rate) + (actual_qty * in_rate)) / (opening_qty + actual_qty)
elif (opening_qty + actual_qty) <= 0:
val_rate = 0
@@ -250,8 +250,10 @@
# get stock value
# ----------------
def get_stock_value(self, val_method, cqty, stock_val, serial_nos):
- if val_method == 'Moving Average' or serial_nos:
+ if serial_nos:
stock_val = flt(stock_val) * flt(cqty)
+ elif val_method == 'Moving Average':
+ stock_val = flt(cqty) > 0 and flt(stock_val) * flt(cqty) or 0
elif val_method == 'FIFO':
stock_val = sum([flt(d[0])*flt(d[1]) for d in self.fcfs_bal])
return stock_val
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 3d8a101..aeccc43 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -321,7 +321,6 @@
def on_submit(self):
self.validate_packed_qty()
set(self.doc, 'message', 'Items against your Order #%s have been delivered. Delivery #%s: ' % (self.doc.po_no, self.doc.name))
- self.check_qty_in_stock()
# Check for Approving Authority
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
sl_obj = get_obj("Stock Ledger")
@@ -360,14 +359,6 @@
webnotes.msgprint("Packing Error:\n" + err_msg, raise_exception=1)
- # *********** Checks whether actual quantity is present in warehouse *************
- def check_qty_in_stock(self):
- for d in getlist(self.doclist, 'packing_details'):
- is_stock_item = sql("select is_stock_item from `tabItem` where name = '%s'" % d.item_code)[0][0]
- if is_stock_item == 'Yes' and d.warehouse and flt(d.qty) > flt(d.actual_qty):
- msgprint("For Item: " + cstr(d.item_code) + " at Warehouse: " + cstr(d.warehouse) + " Quantity: " + cstr(d.qty) +" is not Available. (Must be less than or equal to " + cstr(d.actual_qty) + " )")
- raise Exception, "Validation Error"
-
# ON CANCEL