Expose config for identifying supported vendors
unfortunately must identify vendors at each app node separately, but this is definitely still an improvement..
This commit is contained in:
parent
983a06abe3
commit
e3b1be5835
35
tailbone/templates/vendors/configure.mako
vendored
35
tailbone/templates/vendors/configure.mako
vendored
|
@ -16,6 +16,41 @@
|
|||
</b-field>
|
||||
|
||||
</div>
|
||||
|
||||
<h3 class="block is-size-3">Supported Vendors</h3>
|
||||
<div class="block" style="padding-left: 2rem;">
|
||||
|
||||
<p class="block">
|
||||
The following vendor "keys" are defined within various places in
|
||||
the software. You must identify each explicitly with a
|
||||
Vendor record, for things to work as designed.
|
||||
</p>
|
||||
|
||||
<b-field v-for="setting in supportedVendorSettings"
|
||||
:key="setting.key"
|
||||
horizontal
|
||||
:label="setting.key"
|
||||
:type="supportedVendorSettings[setting.key].value ? null : 'is-warning'"
|
||||
style="max-width: 75%;">
|
||||
|
||||
<tailbone-autocomplete :name="'rattail.vendor.' + setting.key"
|
||||
service-url="${url('vendors.autocomplete')}"
|
||||
v-model="supportedVendorSettings[setting.key].value"
|
||||
:initial-label="setting.label"
|
||||
@input="settingsNeedSaved = true">
|
||||
</tailbone-autocomplete>
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="modify_this_page_vars()">
|
||||
${parent.modify_this_page_vars()}
|
||||
<script type="text/javascript">
|
||||
|
||||
ThisPageData.supportedVendorSettings = ${json.dumps(supported_vendor_settings)|n}
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
||||
|
|
|
@ -4359,6 +4359,21 @@ class MasterView(View):
|
|||
|
||||
def configure_get_context(self, simple_settings=None,
|
||||
input_file_templates=True):
|
||||
"""
|
||||
Returns the full context dict, for rendering the configure
|
||||
page template.
|
||||
|
||||
Default context will include the "simple" settings, as well as
|
||||
any "input file template" settings.
|
||||
|
||||
You may need to override this method, to add additional
|
||||
"custom" settings.
|
||||
|
||||
:param simple_settings: Optional list of simple settings, if
|
||||
already initialized.
|
||||
|
||||
:returns: Context dict for the page template.
|
||||
"""
|
||||
context = {}
|
||||
if simple_settings is None:
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
|
|
57
tailbone/views/vendors/core.py
vendored
57
tailbone/views/vendors/core.py
vendored
|
@ -33,6 +33,7 @@ from rattail.db import model
|
|||
from webhelpers2.html import tags
|
||||
|
||||
from tailbone.views import MasterView
|
||||
from tailbone.db import Session
|
||||
|
||||
|
||||
class VendorView(MasterView):
|
||||
|
@ -179,6 +180,62 @@ class VendorView(MasterView):
|
|||
'type': bool},
|
||||
]
|
||||
|
||||
def configure_get_context(self, **kwargs):
|
||||
context = super(VendorView, self).configure_get_context(**kwargs)
|
||||
|
||||
context['supported_vendor_settings'] = self.configure_get_supported_vendor_settings()
|
||||
|
||||
return context
|
||||
|
||||
def configure_gather_settings(self, data, **kwargs):
|
||||
settings = super(VendorView, self).configure_gather_settings(
|
||||
data, **kwargs)
|
||||
|
||||
supported_vendor_settings = self.configure_get_supported_vendor_settings()
|
||||
for setting in six.itervalues(supported_vendor_settings):
|
||||
name = 'rattail.vendor.{}'.format(setting['key'])
|
||||
settings.append({'name': name,
|
||||
'value': data[name]})
|
||||
|
||||
return settings
|
||||
|
||||
def configure_remove_settings(self, **kwargs):
|
||||
super(VendorView, self).configure_remove_settings(**kwargs)
|
||||
|
||||
model = self.model
|
||||
names = []
|
||||
|
||||
supported_vendor_settings = self.configure_get_supported_vendor_settings()
|
||||
for setting in six.itervalues(supported_vendor_settings):
|
||||
names.append('rattail.vendor.{}'.format(setting['key']))
|
||||
|
||||
if names:
|
||||
# nb. we do not use self.Session b/c that may not point to
|
||||
# the Rattail DB for the subclass
|
||||
Session().query(model.Setting)\
|
||||
.filter(model.Setting.name.in_(names))\
|
||||
.delete(synchronize_session=False)
|
||||
|
||||
def configure_get_supported_vendor_settings(self):
|
||||
app = self.get_rattail_app()
|
||||
vendor_handler = app.get_vendor_handler()
|
||||
batch_handler = app.get_batch_handler('purchase')
|
||||
settings = {}
|
||||
|
||||
for parser in batch_handler.get_supported_invoice_parsers():
|
||||
key = parser.vendor_key
|
||||
if not key:
|
||||
continue
|
||||
|
||||
vendor = vendor_handler.get_vendor(self.Session(), key)
|
||||
settings[key] = {
|
||||
'key': key,
|
||||
'value': vendor.uuid if vendor else None,
|
||||
'label': six.text_type(vendor) if vendor else None,
|
||||
}
|
||||
|
||||
return settings
|
||||
|
||||
|
||||
def defaults(config, **kwargs):
|
||||
base = globals()
|
||||
|
|
Loading…
Reference in a new issue