Allow nagative batch balance from landed cost voucher
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 6202e94..58a4412 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -32,16 +32,15 @@
#check for item quantity available in stock
def actual_amt_check(self):
- if self.batch_no:
+ if self.batch_no and not self.get("allow_negative_stock"):
batch_bal_after_transaction = flt(frappe.db.sql("""select sum(actual_qty)
from `tabStock Ledger Entry`
where warehouse=%s and item_code=%s and batch_no=%s""",
(self.warehouse, self.item_code, self.batch_no))[0][0])
if batch_bal_after_transaction < 0:
- frappe.throw(_("Negative balance {0} in Batch {1} for Item {2} at Warehouse {3} on {4} {5}")
- .format(batch_bal_after_transaction - self.actual_qty, self.batch_no, self.item_code, self.warehouse,
- formatdate(self.posting_date), self.posting_time))
+ frappe.throw(_("Stock balance in Batch {0} will become negative {1} for Item {2} at Warehouse {3}")
+ .format(self.batch_no, batch_bal_after_transaction, self.item_code, self.warehouse))
def validate_mandatory(self):
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','company']
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index 7bbf8fc..97a1f82 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -28,7 +28,7 @@
sle['actual_qty'] = -flt(sle['actual_qty'])
if sle.get("actual_qty") or sle.get("voucher_type")=="Stock Reconciliation":
- sle_id = make_entry(sle)
+ sle_id = make_entry(sle, allow_negative_stock)
args = sle.copy()
args.update({
@@ -46,10 +46,11 @@
where voucher_no=%s and voucher_type=%s""",
(now(), frappe.session.user, voucher_type, voucher_no))
-def make_entry(args):
+def make_entry(args, allow_negative_stock=False):
args.update({"doctype": "Stock Ledger Entry"})
sle = frappe.get_doc(args)
sle.ignore_permissions = 1
+ sle.allow_negative_stock=allow_negative_stock
sle.insert()
sle.submit()
return sle.name