Misc. tweaks for vendor catalog batch

per rattail changes, in particular for sake of Corporal, to allow for
non-native vendor and product associations
This commit is contained in:
Lance Edgar 2021-02-15 12:57:35 -06:00
parent ff904d840f
commit 793022b92f
4 changed files with 39 additions and 20 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -38,7 +38,9 @@ from rattail.db.util import maxlen
from webhelpers2.html import *
from webhelpers2.html.tags import *
from tailbone.util import csrf_token, get_csrf_token, pretty_datetime, raw_datetime
from tailbone.util import (csrf_token, get_csrf_token,
pretty_datetime, raw_datetime,
route_exists)
def pretty_date(date):

View file

@ -3,7 +3,7 @@
<%def name="context_menu_items()">
${parent.context_menu_items()}
% if request.has_perm('vendors.list'):
% if h.route_exists(request, 'vendors') and request.has_perm('vendors.list'):
<li>${h.link_to("View Vendors", url('vendors'))}</li>
% endif
</%def>

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -37,6 +37,7 @@ from rattail.files import resource_path
import colander
from pyramid.renderers import get_renderer
from pyramid.interfaces import IRoutesMapper
from webhelpers2.html import HTML, tags
@ -239,3 +240,14 @@ def email_address_is_valid(address):
except colander.Invalid:
return False
return True
def route_exists(request, route_name):
"""
Checks for existence of the given route name, within the running app
config. Returns boolean indicating whether it exists.
"""
reg = request.registry
mapper = reg.getUtility(IRoutesMapper)
route = mapper.get_route(route_name)
return bool(route)

View file

@ -58,6 +58,10 @@ class VendorCatalogView(FileBatchMasterView):
editable = False
rows_bulk_deletable = True
labels = {
'vendor_id': "Vendor ID",
}
grid_columns = [
'id',
'vendor',
@ -107,6 +111,7 @@ class VendorCatalogView(FileBatchMasterView):
'brand_name',
'description',
'size',
'is_preferred_vendor',
'old_vendor_code',
'vendor_code',
'old_case_size',
@ -148,7 +153,7 @@ class VendorCatalogView(FileBatchMasterView):
# vendor
f.set_renderer('vendor', self.render_vendor)
if self.creating:
if self.creating and 'vendor' in f:
f.replace('vendor', 'vendor_uuid')
f.set_node('vendor_uuid', colander.String())
vendor_display = ""
@ -167,24 +172,19 @@ class VendorCatalogView(FileBatchMasterView):
# filename
f.set_label('filename', "Catalog File")
# parser_key
if self.creating:
f.set_fields([
'filename',
'parser_key',
'vendor_uuid',
'future',
'description',
'notes',
])
parser_values = [(p.key, p.display) for p in self.get_parsers()]
parser_values.insert(0, ('', "(please choose)"))
f.set_widget('parser_key', dfwidget.SelectWidget(values=parser_values))
if 'parser_key' not in f:
f.insert_after('filename', 'parser_key')
values = [(p.key, p.display) for p in self.get_parsers()]
values.insert(0, ('', "(please choose)"))
f.set_widget('parser_key', dfwidget.SelectWidget(values=values))
f.set_label('parser_key', "File Type")
# effective
if not self.creating:
if self.creating:
f.remove('effective')
else:
f.set_readonly('effective')
def get_batch_kwargs(self, batch):
@ -194,6 +194,10 @@ class VendorCatalogView(FileBatchMasterView):
kwargs['vendor'] = batch.vendor
elif batch.vendor_uuid:
kwargs['vendor_uuid'] = batch.vendor_uuid
if batch.vendor_id:
kwargs['vendor_id'] = batch.vendor_id
if batch.vendor_name:
kwargs['vendor_name'] = batch.vendor_name
kwargs['future'] = batch.future
return kwargs
@ -227,7 +231,8 @@ class VendorCatalogView(FileBatchMasterView):
row.STATUS_UPDATE_COST, # TODO: deprecate/remove this one
row.STATUS_CHANGE_VENDOR_ITEM_CODE,
row.STATUS_CHANGE_CASE_SIZE,
row.STATUS_CHANGE_COST):
row.STATUS_CHANGE_COST,
row.STATUS_CHANGE_PRODUCT):
return 'notice'
def configure_row_form(self, f):