added StockFreezeError, and uncomment stock_auth_role check
This commit is contained in:
parent
166024a23c
commit
990d7c4862
@ -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():
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user