Validate warehouse for allowed users and matched company

This commit is contained in:
Nabin Hait 2013-10-07 13:08:13 +05:30
parent 842e9d60cc
commit 8f05c05bfb
6 changed files with 43 additions and 43 deletions

View File

@ -24,7 +24,7 @@ class BuyingController(StockController):
self.doc.supplier_name = webnotes.conn.get_value("Supplier",
self.doc.supplier, "supplier_name")
self.validate_stock_or_nonstock_items()
self.validate_warehouse_belongs_to_company()
self.validate_warehouse()
def set_missing_values(self, for_validate=False):
super(BuyingController, self).set_missing_values(for_validate)
@ -49,17 +49,20 @@ class BuyingController(StockController):
if supplier:
self.doc.supplier = supplier
break
def validate_warehouse(self):
from stock.utils import validate_warehouse_user, 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):
self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details")
self.set_taxes("purchase_tax_details", "purchase_other_charges")
def validate_warehouse_belongs_to_company(self):
for warehouse, company in webnotes.conn.get_values("Warehouse",
self.doclist.get_distinct_values("warehouse"), "company").items():
if company and company != self.doc.company:
webnotes.msgprint(_("Company mismatch for Warehouse") + (": %s" % (warehouse,)),
raise_exception=WrongWarehouseCompany)
def validate_stock_or_nonstock_items(self):
if not self.get_stock_items():

View File

@ -22,13 +22,14 @@ class DocType:
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"In Process", "Completed", "Cancelled"])
if self.doc.production_item :
item_detail = sql("select name from `tabItem` where name = '%s' and docstatus != 2"
% self.doc.production_item, as_dict = 1)
if not item_detail:
msgprint("Item '%s' does not exist or cancelled in the system."
% cstr(self.doc.production_item), raise_exception=1)
self.validate_bom_no()
self.validate_sales_order()
self.validate_warehouse()
from utilities.transaction_base import validate_uom_is_integer
validate_uom_is_integer(self.doclist, "stock_uom", ["qty", "produced_qty"])
def validate_bom_no(self):
if self.doc.bom_no:
bom = sql("""select name from `tabBOM` where name=%s and docstatus=1
and is_active=1 and item=%s"""
@ -38,16 +39,20 @@ class DocType:
May be BOM not exists or inactive or not submitted
or for some other item.""" % cstr(self.doc.bom_no), raise_exception=1)
def validate_sales_order(self):
if self.doc.sales_order:
if not webnotes.conn.sql("""select name from `tabSales Order`
where name=%s and docstatus = 1""", self.doc.sales_order):
msgprint("Sales Order: %s is not valid" % self.doc.sales_order, raise_exception=1)
self.validate_production_order_against_so()
from utilities.transaction_base import validate_uom_is_integer
validate_uom_is_integer(self.doclist, "stock_uom", ["qty", "produced_qty"])
def validate_warehouse(self):
from stock.utils import validate_warehouse_user, 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):
# already ordered qty

View File

@ -127,7 +127,7 @@ class DocType(SellingController):
self.validate_po()
self.validate_uom_is_integer("stock_uom", "qty")
self.validate_for_items()
self.validate_warehouse_user()
self.validate_warehouse()
sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_active_sales_items(self)
sales_com_obj.check_conversion_rate(self)
@ -148,14 +148,15 @@ class DocType(SellingController):
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
def validate_warehouse_user(self):
from stock.utils import validate_warehouse_user
def validate_warehouse(self):
from stock.utils import validate_warehouse_user, 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):
super(DocType, self).validate_with_previous_doc(self.tname, {

View File

@ -68,22 +68,14 @@ class DocType(BuyingController):
self.doc.status = "Draft"
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped", "Cancelled"])
# restrict material request type
self.validate_value("material_request_type", "in", ["Purchase", "Transfer"])
# Get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common')
# Validate for items
pc_obj.validate_for_items(self)
# Validate qty against SO
self.validate_qty_against_so()
self.validate_qty_against_so()
def update_bin(self, is_submit, is_stopped):
""" Update Quantity Requested for Purchase in Bin for Material Request of type 'Purchase'"""

View File

@ -7,7 +7,6 @@ from webnotes import _, msgprint, ValidationError
from webnotes.utils import cint, flt, getdate, cstr
from webnotes.model.controller import DocListController
class InvalidWarehouseCompany(ValidationError): pass
class SerialNoNotRequiredError(ValidationError): pass
class SerialNoRequiredError(ValidationError): pass
class SerialNoQtyError(ValidationError): pass
@ -25,7 +24,7 @@ class DocType(DocListController):
self.doclist = doclist
def validate(self):
from stock.utils import validate_warehouse_user
from stock.utils import validate_warehouse_user, validate_warehouse_company
if not hasattr(webnotes, "new_stock_ledger_entries"):
webnotes.new_stock_ledger_entries = []
@ -33,7 +32,7 @@ class DocType(DocListController):
self.validate_mandatory()
self.validate_item()
validate_warehouse_user(self.doc.warehouse)
self.validate_warehouse_company()
validate_warehouse_company(self.doc.warehouse, self.doc.company)
self.scrub_posting_time()
from accounts.utils import validate_fiscal_year
@ -63,13 +62,6 @@ class DocType(DocListController):
as on %(posting_date)s %(posting_time)s""" % self.doc.fields)
sself.doc.fields.pop('batch_bal')
def validate_warehouse_company(self):
warehouse_company = webnotes.conn.get_value("Warehouse", self.doc.warehouse, "company")
if warehouse_company and warehouse_company != self.doc.company:
webnotes.msgprint(_("Warehouse does not belong to company.") + " (" + \
self.doc.warehouse + ", " + self.doc.company +")",
raise_exception=InvalidWarehouseCompany)
def validate_mandatory(self):
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']

View File

@ -9,6 +9,7 @@ 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):
if not posting_date: posting_date = nowdate()
@ -216,6 +217,12 @@ def validate_warehouse_user(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:
webnotes.msgprint(_("Warehouse does not belong to company.") + " (" + \
warehouse + ", " + company +")", raise_exception=InvalidWarehouseCompany)
def get_sales_bom_buying_amount(item_code, warehouse, voucher_type, voucher_no, voucher_detail_no,
stock_ledger_entries, item_sales_bom):