initial tests for freeze stock functionality

This commit is contained in:
Thura Hlaing
2014-01-29 13:28:11 +06:30
parent 258191ab40
commit 3c4bb0c7c9
2 changed files with 261 additions and 245 deletions

View File

@@ -800,6 +800,22 @@ class TestStockEntry(unittest.TestCase):
serial_no = get_serial_nos(se.doclist[1].serial_no)[0]
self.assertFalse(webnotes.conn.get_value("Serial No", serial_no, "warehouse"))
def test_freeze_stocks (self):
self._clear_stock_account_balance()
# 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)
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)
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto_days", 0)
def make_serialized_item():
se = webnotes.bean(copy=test_records[0])
se.doclist[1].item_code = "_Test Serialized Item With Series"

View File

@@ -87,14 +87,14 @@ class DocType(DocListController):
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():
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)
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():
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)