mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
[minor] move warehouse user to restrictions
This commit is contained in:
@@ -7,9 +7,9 @@ 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
|
||||
|
||||
|
||||
class TestStockEntry(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
webnotes.set_user("Administrator")
|
||||
set_perpetual_inventory(0)
|
||||
if hasattr(self, "old_default_company"):
|
||||
webnotes.conn.set_default("company", self.old_default_company)
|
||||
@@ -39,46 +39,6 @@ class TestStockEntry(unittest.TestCase):
|
||||
|
||||
webnotes.conn.set_default("company", self.old_default_company)
|
||||
|
||||
def test_warehouse_company_validation(self):
|
||||
set_perpetual_inventory(0)
|
||||
self._clear_stock_account_balance()
|
||||
webnotes.bean("Profile", "test2@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
webnotes.session.user = "test2@example.com"
|
||||
|
||||
from stock.utils import InvalidWarehouseCompany
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
st1.insert()
|
||||
self.assertRaises(InvalidWarehouseCompany, st1.submit)
|
||||
|
||||
webnotes.session.user = "Administrator"
|
||||
|
||||
def test_warehouse_user(self):
|
||||
set_perpetual_inventory(0)
|
||||
from stock.utils import UserNotAllowedForWarehouse
|
||||
|
||||
webnotes.bean("Profile", "test@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
|
||||
webnotes.bean("Profile", "test2@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
webnotes.session.user = "test@example.com"
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doc.company = "_Test Company 1"
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
st1.insert()
|
||||
self.assertRaises(UserNotAllowedForWarehouse, st1.submit)
|
||||
|
||||
webnotes.session.user = "test2@example.com"
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doc.company = "_Test Company 1"
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
st1.insert()
|
||||
st1.submit()
|
||||
|
||||
webnotes.session.user = "Administrator"
|
||||
|
||||
def test_material_receipt_gl_entry(self):
|
||||
self._clear_stock_account_balance()
|
||||
set_perpetual_inventory()
|
||||
@@ -799,7 +759,49 @@ 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_warehouse_company_validation(self):
|
||||
set_perpetual_inventory(0)
|
||||
self._clear_stock_account_balance()
|
||||
webnotes.bean("Profile", "test2@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
webnotes.set_user("test2@example.com")
|
||||
|
||||
from stock.utils import InvalidWarehouseCompany
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
st1.insert()
|
||||
self.assertRaises(InvalidWarehouseCompany, st1.submit)
|
||||
|
||||
# permission tests
|
||||
def test_warehouse_user(self):
|
||||
import webnotes.defaults
|
||||
from webnotes.model.bean import BeanPermissionError
|
||||
set_perpetual_inventory(0)
|
||||
|
||||
webnotes.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", "Restriction")
|
||||
webnotes.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", "Restriction")
|
||||
webnotes.bean("Profile", "test@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
webnotes.bean("Profile", "test2@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
|
||||
webnotes.set_user("test@example.com")
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doc.company = "_Test Company 1"
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
self.assertRaises(BeanPermissionError, st1.insert)
|
||||
|
||||
webnotes.set_user("test2@example.com")
|
||||
st1 = webnotes.bean(copy=test_records[0])
|
||||
st1.doc.company = "_Test Company 1"
|
||||
st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
|
||||
st1.insert()
|
||||
st1.submit()
|
||||
|
||||
webnotes.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", parenttype="Restriction")
|
||||
webnotes.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", parenttype="Restriction")
|
||||
|
||||
def make_serialized_item():
|
||||
se = webnotes.bean(copy=test_records[0])
|
||||
se.doclist[1].item_code = "_Test Serialized Item With Series"
|
||||
|
||||
@@ -13,10 +13,9 @@ class DocType(DocListController):
|
||||
self.doclist = doclist
|
||||
|
||||
def validate(self):
|
||||
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||
from stock.utils import validate_warehouse_company
|
||||
self.validate_mandatory()
|
||||
self.validate_item()
|
||||
validate_warehouse_user(self.doc.warehouse)
|
||||
validate_warehouse_company(self.doc.warehouse, self.doc.company)
|
||||
self.scrub_posting_time()
|
||||
|
||||
|
||||
@@ -19,10 +19,6 @@ test_records = [
|
||||
"warehouse_name": "_Test Warehouse 2",
|
||||
"create_account_under": "Stock Assets - _TC",
|
||||
"company": "_Test Company 1"
|
||||
}, {
|
||||
"doctype": "Warehouse User",
|
||||
"parentfield": "warehouse_users",
|
||||
"user": "test2@example.com"
|
||||
}],
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
|
||||
@@ -8,7 +8,6 @@ from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
||||
from webnotes.defaults import get_global_default
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
|
||||
class UserNotAllowedForWarehouse(webnotes.ValidationError): pass
|
||||
class InvalidWarehouseCompany(webnotes.ValidationError): pass
|
||||
|
||||
def get_stock_balance_on(warehouse, posting_date=None):
|
||||
@@ -191,33 +190,7 @@ def get_valid_serial_nos(sr_nos, qty=0, item_code=''):
|
||||
raise_exception=1)
|
||||
|
||||
return valid_serial_nos
|
||||
|
||||
def get_warehouse_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
"""used in search queries"""
|
||||
wlist = []
|
||||
for w in webnotes.conn.sql_list("""select name from tabWarehouse
|
||||
where name like '%%%s%%'""" % txt):
|
||||
if webnotes.session.user=="Administrator":
|
||||
wlist.append([w])
|
||||
else:
|
||||
warehouse_users = webnotes.conn.sql_list("""select user from `tabWarehouse User`
|
||||
where parent=%s""", w)
|
||||
if not warehouse_users:
|
||||
wlist.append([w])
|
||||
elif webnotes.session.user in warehouse_users:
|
||||
wlist.append([w])
|
||||
return wlist
|
||||
|
||||
def validate_warehouse_user(warehouse):
|
||||
if webnotes.session.user=="Administrator" or not warehouse:
|
||||
return
|
||||
warehouse_users = [p[0] for p in webnotes.conn.sql("""select user from `tabWarehouse User`
|
||||
where parent=%s""", warehouse)]
|
||||
|
||||
if warehouse_users and not (webnotes.session.user in warehouse_users):
|
||||
webnotes.throw(_("Not allowed entry in Warehouse") \
|
||||
+ ": " + warehouse, UserNotAllowedForWarehouse)
|
||||
|
||||
def validate_warehouse_company(warehouse, company):
|
||||
warehouse_company = webnotes.conn.get_value("Warehouse", warehouse, "company")
|
||||
if warehouse_company and warehouse_company != company:
|
||||
|
||||
Reference in New Issue
Block a user