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():