[purchase] [validation] validate warehouse belongs to company if set
This commit is contained in:
parent
e97b07e43f
commit
ecb36f2cb0
@ -27,6 +27,12 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
po.insert()
|
||||
self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2)
|
||||
|
||||
def test_warehouse_company_validation(self):
|
||||
from controllers.buying_controller import WrongWarehouseCompany
|
||||
po = webnotes.bean(copy=test_records[0])
|
||||
po.doc.company = "_Test Company 1"
|
||||
self.assertRaises(WrongWarehouseCompany, po.insert)
|
||||
|
||||
|
||||
test_dependencies = ["BOM"]
|
||||
|
||||
|
@ -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:
|
||||
|
@ -263,6 +263,12 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
se = webnotes.bean(copy=se_doclist)
|
||||
self.assertRaises(webnotes.MappingMismatchError, se.insert)
|
||||
|
||||
def test_warehouse_company_validation(self):
|
||||
from controllers.buying_controller import WrongWarehouseCompany
|
||||
mr = webnotes.bean(copy=test_records[0])
|
||||
mr.doc.company = "_Test Company 1"
|
||||
self.assertRaises(WrongWarehouseCompany, mr.insert)
|
||||
|
||||
test_records = [
|
||||
[
|
||||
{
|
||||
|
@ -2,7 +2,8 @@ test_records = [
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse",
|
||||
"warehouse_type": "_Test Warehouse Type"
|
||||
"warehouse_type": "_Test Warehouse Type",
|
||||
"company": "_Test Company"
|
||||
}],
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
|
Loading…
x
Reference in New Issue
Block a user