[fix] [minor] negative stock balance for batch

This commit is contained in:
Nabin Hait 2013-09-25 15:59:35 +05:30
parent c6871dc194
commit ee60763b45

View File

@ -34,28 +34,35 @@ class DocType(DocListController):
self.validate_item() self.validate_item()
validate_warehouse_user(self.doc.warehouse) validate_warehouse_user(self.doc.warehouse)
self.validate_warehouse_company() self.validate_warehouse_company()
self.actual_amt_check()
self.check_stock_frozen_date()
self.scrub_posting_time() self.scrub_posting_time()
from accounts.utils import validate_fiscal_year from accounts.utils import validate_fiscal_year
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, self.meta.get_label("posting_date")) validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, self.meta.get_label("posting_date"))
def on_submit(self): def on_submit(self):
self.check_stock_frozen_date()
self.actual_amt_check()
self.validate_serial_no() self.validate_serial_no()
#check for item quantity available in stock #check for item quantity available in stock
def actual_amt_check(self): def actual_amt_check(self):
if self.doc.batch_no: if self.doc.batch_no:
batch_bal = flt(webnotes.conn.sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and batch_no = '%s'"%(self.doc.warehouse,self.doc.item_code,self.doc.batch_no))[0][0]) batch_bal_after_transaction = flt(webnotes.conn.sql("""select sum(actual_qty)
self.doc.fields.update({'batch_bal': batch_bal}) from `tabStock Ledger Entry`
where warehouse=%s and item_code=%s and batch_no=%s""",
(self.doc.warehouse, self.doc.item_code, self.doc.batch_no))[0][0])
if (batch_bal + self.doc.actual_qty) < 0: if batch_bal_after_transaction < 0:
msgprint("""Not enough quantity (requested: %(actual_qty)s, current: %(batch_bal)s in Batch self.doc.fields.update({
<b>%(batch_no)s</b> for Item <b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b> 'batch_bal': batch_bal_after_transaction - self.doc.actual_qty
as on %(posting_date)s %(posting_time)s""" % self.doc.fields, raise_exception = 1) })
self.doc.fields.pop('batch_bal') webnotes.throw("""Not enough quantity (requested: %(actual_qty)s, \
current: %(batch_bal)s in Batch <b>%(batch_no)s</b> for Item \
<b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b> \
as on %(posting_date)s %(posting_time)s""" % self.doc.fields)
sself.doc.fields.pop('batch_bal')
def validate_warehouse_company(self): def validate_warehouse_company(self):
warehouse_company = webnotes.conn.get_value("Warehouse", self.doc.warehouse, "company") warehouse_company = webnotes.conn.get_value("Warehouse", self.doc.warehouse, "company")