Share some code for validating vendor field
and add validation for new Ordering batch
This commit is contained in:
parent
0d9a502801
commit
b4816c6289
|
@ -260,13 +260,6 @@ class VendorCatalogView(FileBatchMasterView):
|
|||
else:
|
||||
f.remove('cache_products')
|
||||
|
||||
def valid_vendor_uuid(self, node, value):
|
||||
model = self.model
|
||||
if value:
|
||||
vendor = self.Session.get(model.Vendor, value)
|
||||
if not vendor:
|
||||
raise colander.Invalid(node, "Vendor not found")
|
||||
|
||||
def render_parser_key(self, batch, field):
|
||||
key = getattr(batch, field)
|
||||
if not key:
|
||||
|
|
|
@ -847,6 +847,13 @@ class MasterView(View):
|
|||
url = self.request.route_url('vendors.view', uuid=vendor.uuid)
|
||||
return tags.link_to(text, url)
|
||||
|
||||
def valid_vendor_uuid(self, node, value):
|
||||
if value:
|
||||
model = self.model
|
||||
vendor = self.Session.get(model.Vendor, value)
|
||||
if not vendor:
|
||||
node.raise_invalid("Vendor not found")
|
||||
|
||||
def render_department(self, obj, field):
|
||||
department = getattr(obj, field)
|
||||
if not department:
|
||||
|
|
|
@ -277,6 +277,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
f.set_widget('vendor_uuid', forms.widgets.JQueryAutocompleteWidget(
|
||||
field_display=vendor_display, service_url=vendors_url))
|
||||
f.set_validator('vendor_uuid', self.valid_vendor_uuid)
|
||||
elif self.editing:
|
||||
f.set_readonly('vendor')
|
||||
|
||||
|
@ -395,12 +396,6 @@ class PurchasingBatchView(BatchMasterView):
|
|||
'vendor_contact',
|
||||
'status_code')
|
||||
|
||||
def valid_vendor_uuid(self, node, value):
|
||||
model = self.model
|
||||
vendor = self.Session.get(model.Vendor, value)
|
||||
if not vendor:
|
||||
raise colander.Invalid(node, "Invalid vendor selection")
|
||||
|
||||
def render_store(self, batch, field):
|
||||
store = batch.store
|
||||
if not store:
|
||||
|
|
Loading…
Reference in a new issue