mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-14 20:35:09 +00:00
[purchase] [validation] validate warehouse belongs to company if set
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user