Add basic "config" view for Receiving
This commit is contained in:
parent
340a177a29
commit
1fbe429a08
6 changed files with 278 additions and 8 deletions
|
@ -4041,14 +4041,109 @@ class MasterView(View):
|
|||
context = self.configure_get_context()
|
||||
return self.render_to_response('configure', context)
|
||||
|
||||
def configure_get_simple_settings(self):
|
||||
"""
|
||||
If you have some "simple" settings, each of which basically
|
||||
just needs to be rendered as a separate field, then you can
|
||||
declare them via this method.
|
||||
|
||||
You should return a list of settings; each setting should be
|
||||
represented as a dict with various pieces of info, e.g.::
|
||||
|
||||
{
|
||||
'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_cases',
|
||||
'name': 'rattail.batch.purchase.allow_cases',
|
||||
'type': bool,
|
||||
'value': config.getbool('rattail.batch',
|
||||
'purchase.allow_cases'),
|
||||
}
|
||||
|
||||
Note that some of the above is optional, in particular it
|
||||
works like this:
|
||||
|
||||
If you pass ``section`` and ``option`` then you do not need to
|
||||
pass ``name`` since that can be deduced. Also in this case
|
||||
you need not pass ``value`` as the normal view logic can fetch
|
||||
the value automatically. Note that when fetching, it honors
|
||||
``type`` which, if you do not specify, would be ``str`` by
|
||||
default.
|
||||
|
||||
However if you pass ``name`` then you need not pass
|
||||
``section`` or ``option``, but you must pass ``value`` since
|
||||
that cannot be automatically fetched in this case.
|
||||
|
||||
:returns: List of simple setting info dicts, as described
|
||||
above.
|
||||
"""
|
||||
|
||||
def configure_get_name_for_simple_setting(self, simple):
|
||||
if 'name' in simple:
|
||||
return simple['name']
|
||||
return '{}.{}'.format(simple['section'],
|
||||
simple['option'])
|
||||
|
||||
def configure_get_context(self):
|
||||
return {}
|
||||
context = {}
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings:
|
||||
|
||||
config = self.rattail_config
|
||||
settings = {}
|
||||
for simple in simple_settings:
|
||||
|
||||
name = self.configure_get_name_for_simple_setting(simple)
|
||||
|
||||
if 'value' in simple:
|
||||
value = simple['value']
|
||||
elif simple.get('type') is bool:
|
||||
value = config.getbool(simple['section'],
|
||||
simple['option'],
|
||||
default=False)
|
||||
else:
|
||||
value = config.get(simple['section'],
|
||||
simple['option'])
|
||||
|
||||
settings[name] = value
|
||||
|
||||
context['simple_settings'] = settings
|
||||
|
||||
return context
|
||||
|
||||
def configure_gather_settings(self, data):
|
||||
return []
|
||||
settings = []
|
||||
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings and 'simple_settings' in data:
|
||||
|
||||
data_settings = data['simple_settings']
|
||||
|
||||
for simple in simple_settings:
|
||||
name = self.configure_get_name_for_simple_setting(simple)
|
||||
value = None
|
||||
|
||||
if name in data_settings:
|
||||
value = data_settings[name]
|
||||
|
||||
if simple.get('type') is bool:
|
||||
value = six.text_type(bool(value)).lower()
|
||||
else:
|
||||
value = six.text_type(value)
|
||||
|
||||
settings.append({'name': name,
|
||||
'value': value})
|
||||
|
||||
return settings
|
||||
|
||||
def configure_remove_settings(self):
|
||||
pass
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings:
|
||||
model = self.model
|
||||
names = [self.configure_get_name_for_simple_setting(simple)
|
||||
for simple in simple_settings]
|
||||
self.Session.query(model.Setting)\
|
||||
.filter(model.Setting.name.in_(names))\
|
||||
.delete(synchronize_session=False)
|
||||
|
||||
def configure_save_settings(self, settings):
|
||||
model = self.model
|
||||
|
|
|
@ -78,6 +78,9 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
index_title = "Receiving"
|
||||
downloadable = True
|
||||
bulk_deletable = True
|
||||
configurable = True
|
||||
config_title = "Receiving"
|
||||
|
||||
rows_editable = False
|
||||
rows_editable_but_not_directly = True
|
||||
rows_deletable = True
|
||||
|
@ -1826,6 +1829,47 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
progress.session['success_url'] = success_url
|
||||
progress.session.save()
|
||||
|
||||
def configure_get_simple_settings(self):
|
||||
config = self.rattail_config
|
||||
return [
|
||||
|
||||
# supported workflows
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_scratch',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_invoice',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_purchase_order',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_purchase_order_with_invoice',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_truck_dump_receiving',
|
||||
'type': bool},
|
||||
|
||||
# product handling
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_cases',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_expired_credits',
|
||||
'type': bool},
|
||||
|
||||
# mobile interface
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.mobile_images',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.mobile_quick_receive',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.mobile_quick_receive_all',
|
||||
'type': bool},
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
cls._receiving_defaults(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue