added StockFreezeError, and uncomment stock_auth_role check
diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py
index 78ca019..b88f1c9 100644
--- a/stock/doctype/stock_entry/test_stock_entry.py
+++ b/stock/doctype/stock_entry/test_stock_entry.py
@@ -6,7 +6,7 @@
from webnotes.utils import flt
from stock.doctype.serial_no.serial_no import *
from stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
-
+from stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError
class TestStockEntry(unittest.TestCase):
def tearDown(self):
@@ -802,18 +802,19 @@
def test_freeze_stocks (self):
self._clear_stock_account_balance()
+ stock_auth_role = webnotes.conn.set_value('Stock Settings', None,'stock_auth_role', '')
# test freeze_stocks_upto
date_newer_than_test_records = add_days(getdate(test_records[0][0]['posting_date']), 5)
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto", date_newer_than_test_records)
se = webnotes.bean(copy=test_records[0]).insert()
- self.assertRaises (ValidationError, se.submit)
+ self.assertRaises (StockFreezeError, se.submit)
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto", '')
# test freeze_stocks_upto_days
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto_days", 7)
se = webnotes.bean(copy=test_records[0]).insert()
- self.assertRaises (ValidationError, se.submit)
+ self.assertRaises (StockFreezeError, se.submit)
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto_days", 0)
def make_serialized_item():
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 232d8df..277992b 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -9,6 +9,8 @@
from webnotes.model.controller import DocListController
from datetime import date
+class StockFreezeError(webnotes.ValidationError): pass
+
class DocType(DocListController):
def __init__(self, doc, doclist=[]):
self.doc = doc
@@ -87,15 +89,15 @@
stock_frozen_upto = webnotes.conn.get_value('Stock Settings', None, 'stock_frozen_upto') or ''
if stock_frozen_upto:
stock_auth_role = webnotes.conn.get_value('Stock Settings', None,'stock_auth_role')
- if getdate(self.doc.posting_date) <= getdate(stock_frozen_upto): # and not stock_auth_role in webnotes.user.get_roles():
- msgprint("You are not authorized to do / modify back dated stock entries before %s" % getdate(stock_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
+ if getdate(self.doc.posting_date) <= getdate(stock_frozen_upto) and not stock_auth_role in webnotes.user.get_roles():
+ msgprint("You are not authorized to do / modify back dated stock entries before %s" % getdate(stock_frozen_upto).strftime('%d-%m-%Y'), raise_exception=StockFreezeError)
stock_frozen_upto_days = int(webnotes.conn.get_value('Stock Settings', None, 'stock_frozen_upto_days') or 0)
if stock_frozen_upto_days:
stock_auth_role = webnotes.conn.get_value('Stock Settings', None,'stock_auth_role')
older_than_x_days_ago = (add_days(getdate(self.doc.posting_date), stock_frozen_upto_days) <= date.today())
- if older_than_x_days_ago: # and not stock_auth_role in webnotes.user.get_roles():
- msgprint("You are not authorized to do / modify back dated stock entries older than %d days ago" %stock_frozen_upto_days, raise_exception=1)
+ if older_than_x_days_ago and not stock_auth_role in webnotes.user.get_roles():
+ msgprint("You are not authorized to do / modify back dated stock entries older than %d days ago" %stock_frozen_upto_days, raise_exception=StockFreezeError)
def scrub_posting_time(self):