[minor] move warehouse user to restrictions
This commit is contained in:
parent
57518fc5f1
commit
83638b5f05
@ -50,13 +50,12 @@ class BuyingController(StockController):
|
||||
break
|
||||
|
||||
def validate_warehouse(self):
|
||||
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||
from stock.utils import validate_warehouse_company
|
||||
|
||||
warehouses = list(set([d.warehouse for d in
|
||||
self.doclist.get({"doctype": self.tname}) if d.warehouse]))
|
||||
|
||||
for w in warehouses:
|
||||
validate_warehouse_user(w)
|
||||
validate_warehouse_company(w, self.doc.company)
|
||||
|
||||
def get_purchase_tax_details(self):
|
||||
|
@ -151,7 +151,7 @@ class DocType(DocListController):
|
||||
employee = webnotes.bean("Employee", self.doc.employee)
|
||||
leave_approvers = [l.leave_approver for l in
|
||||
employee.doclist.get({"parentfield": "employee_leave_approvers"})]
|
||||
|
||||
|
||||
if len(leave_approvers) and self.doc.leave_approver not in leave_approvers:
|
||||
msgprint(("[" + _("For Employee") + ' "' + self.doc.employee + '"] '
|
||||
+ _("Leave Approver can be one of") + ": "
|
||||
|
@ -10,6 +10,9 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
webnotes.set_user("Administrator")
|
||||
|
||||
# so that this test doesn't affect other tests
|
||||
webnotes.conn.sql("""delete from `tabEmployee Leave Approver`""")
|
||||
|
||||
def _clear_roles(self):
|
||||
webnotes.conn.sql("""delete from `tabUserRole` where parent in
|
||||
("test@example.com", "test1@example.com", "test2@example.com")""")
|
||||
@ -162,10 +165,10 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
|
||||
from webnotes.model.bean import BeanPermissionError
|
||||
self.assertRaises(BeanPermissionError, application.submit)
|
||||
|
||||
|
||||
webnotes.conn.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
|
||||
"_T-Employee-0001")
|
||||
|
||||
|
||||
def _test_leave_approval_valid_leave_approver_insert(self):
|
||||
self._clear_applications()
|
||||
self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com")
|
||||
|
@ -8,23 +8,23 @@ from hr.doctype.leave_block_list.leave_block_list import get_applicable_block_da
|
||||
|
||||
class TestLeaveBlockList(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
webnotes.session.user = "Administrator"
|
||||
webnotes.set_user("Administrator")
|
||||
|
||||
def test_get_applicable_block_dates(self):
|
||||
webnotes.session.user = "test@example.com"
|
||||
webnotes.set_user("test@example.com")
|
||||
webnotes.conn.set_value("Department", "_Test Department", "leave_block_list",
|
||||
"_Test Leave Block List")
|
||||
self.assertTrue("2013-01-02" in
|
||||
[d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")])
|
||||
|
||||
def test_get_applicable_block_dates_for_allowed_user(self):
|
||||
webnotes.session.user = "test1@example.com"
|
||||
webnotes.set_user("test1@example.com")
|
||||
webnotes.conn.set_value("Department", "_Test Department 1", "leave_block_list",
|
||||
"_Test Leave Block List")
|
||||
self.assertEquals([], [d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")])
|
||||
|
||||
def test_get_applicable_block_dates_all_lists(self):
|
||||
webnotes.session.user = "test1@example.com"
|
||||
webnotes.set_user("test1@example.com")
|
||||
webnotes.conn.set_value("Department", "_Test Department 1", "leave_block_list",
|
||||
"_Test Leave Block List")
|
||||
self.assertTrue("2013-01-02" in
|
||||
|
@ -54,10 +54,9 @@ class DocType:
|
||||
self.validate_production_order_against_so()
|
||||
|
||||
def validate_warehouse(self):
|
||||
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||
from stock.utils import validate_warehouse_company
|
||||
|
||||
for w in [self.doc.fg_warehouse, self.doc.wip_warehouse]:
|
||||
validate_warehouse_user(w)
|
||||
validate_warehouse_company(w, self.doc.company)
|
||||
|
||||
def validate_production_order_against_so(self):
|
||||
|
12
patches/1311/p07_move_warehouse_user_to_restrictions.py
Normal file
12
patches/1311/p07_move_warehouse_user_to_restrictions.py
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
def execute():
|
||||
from core.page.user_properties import user_properties
|
||||
for warehouse, profile in webnotes.conn.sql("""select parent, user from `tabWarehouse User`"""):
|
||||
user_properties.add(profile, "Warehouse", warehouse)
|
||||
|
||||
webnotes.delete_doc("DocType", "Warehouse User")
|
@ -263,4 +263,5 @@ patch_list = [
|
||||
"patches.1311.p07_scheduler_errors_digest",
|
||||
"patches.1311.p08_email_digest_recipients",
|
||||
"execute:webnotes.delete_doc('DocType', 'Warehouse Type')",
|
||||
"patches.1311.p07_move_warehouse_user_to_restrictions",
|
||||
]
|
@ -127,13 +127,12 @@ class DocType(SellingController):
|
||||
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
|
||||
|
||||
def validate_warehouse(self):
|
||||
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||
from stock.utils import validate_warehouse_company
|
||||
|
||||
warehouses = list(set([d.reserved_warehouse for d in
|
||||
self.doclist.get({"doctype": self.tname}) if d.reserved_warehouse]))
|
||||
|
||||
for w in warehouses:
|
||||
validate_warehouse_user(w)
|
||||
validate_warehouse_company(w, self.doc.company)
|
||||
|
||||
def validate_with_previous_doc(self):
|
||||
|
@ -6,6 +6,9 @@ from webnotes.utils import flt
|
||||
import unittest
|
||||
|
||||
class TestSalesOrder(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
webnotes.set_user("Administrator")
|
||||
|
||||
def test_make_material_request(self):
|
||||
from selling.doctype.sales_order.sales_order import make_material_request
|
||||
|
||||
@ -276,28 +279,29 @@ class TestSalesOrder(unittest.TestCase):
|
||||
so.doclist[1].reserved_warehouse, 20.0)
|
||||
|
||||
def test_warehouse_user(self):
|
||||
webnotes.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@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.session.user = "test@example.com"
|
||||
webnotes.set_user("test@example.com")
|
||||
|
||||
from stock.utils import UserNotAllowedForWarehouse
|
||||
from webnotes.model.bean import BeanPermissionError
|
||||
so = webnotes.bean(copy = test_records[0])
|
||||
so.doc.company = "_Test Company 1"
|
||||
so.doc.conversion_rate = 0.02
|
||||
so.doc.plc_conversion_rate = 0.02
|
||||
so.doclist[1].reserved_warehouse = "_Test Warehouse 2 - _TC1"
|
||||
self.assertRaises(UserNotAllowedForWarehouse, so.insert)
|
||||
self.assertRaises(BeanPermissionError, so.insert)
|
||||
|
||||
webnotes.session.user = "test2@example.com"
|
||||
webnotes.set_user("test2@example.com")
|
||||
so.insert()
|
||||
|
||||
webnotes.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", parenttype="Restriction")
|
||||
|
||||
webnotes.session.user = "Administrator"
|
||||
|
||||
test_dependencies = ["Sales BOM"]
|
||||
test_dependencies = ["Sales BOM", "Currency Exchange"]
|
||||
|
||||
test_records = [
|
||||
[
|
||||
|
@ -4,6 +4,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
standard_queries = {
|
||||
"Warehouse": "stock.utils.get_warehouse_list",
|
||||
"Customer": "selling.utils.get_customer_list",
|
||||
}
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user