[purchase] [validation] validate warehouse belongs to company if set

This commit is contained in:
Rushabh Mehta
2013-05-02 11:34:37 +05:30
parent e97b07e43f
commit ecb36f2cb0
4 changed files with 26 additions and 2 deletions

View File

@@ -26,10 +26,13 @@ from webnotes.model.utils import round_floats_in_doc
from controllers.stock_controller import StockController
class WrongWarehouseCompany(Exception): pass
class BuyingController(StockController):
def validate(self):
super(BuyingController, self).validate()
self.validate_stock_or_nonstock_items()
self.validate_warehouse_belongs_to_company()
if self.meta.get_field("currency"):
self.company_currency = get_company_currency(self.doc.company)
self.validate_conversion_rate("currency", "conversion_rate")
@@ -42,7 +45,15 @@ class BuyingController(StockController):
# set total in words
self.set_total_in_words()
def validate_warehouse_belongs_to_company(self):
for d in self.doclist.get({"warehouse": True}):
warehouse_company = webnotes.conn.get_value("Warehouse", d.warehouse, "company")
if warehouse_company and warehouse_company != self.doc.company:
webnotes.msgprint(_("Warehouse must belong to company") + \
(": %s (%s, %s)" % (d.warehouse, warehouse_company, self.doc.company)),
raise_exception=WrongWarehouseCompany)
def validate_stock_or_nonstock_items(self):
items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
if self.stock_items: