From 990d7c48627015694e9832bff3703aed34d78d14 Mon Sep 17 00:00:00 2001 From: Thura Hlaing Date: Wed, 29 Jan 2014 14:53:21 +0630 Subject: [PATCH] added StockFreezeError, and uncomment stock_auth_role check --- stock/doctype/stock_entry/test_stock_entry.py | 7 ++++--- stock/doctype/stock_ledger_entry/stock_ledger_entry.py | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index 78ca0198db..b88f1c9d18 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -6,7 +6,7 @@ import webnotes, unittest 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 @@ class TestStockEntry(unittest.TestCase): 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 232d8dff9d..277992bcd9 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.utils import flt, getdate, add_days 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 @@ 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(): - 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):