Compare commits

...

62 commits

Author SHA1 Message Date
e150453801 fix: add startup hack for tempmon DB model 2025-03-05 10:34:52 -06:00
e2582ffec5 bump: version 0.22.6 → 0.22.7 2025-02-19 10:33:39 -06:00
a6508154cb docs: update intersphinx doc links per server migration 2025-02-18 12:13:28 -06:00
7348eec671 fix: stop using old config for logo image url on login page 2025-02-18 11:16:23 -06:00
4221fa50dd fix: fix warning msg for deprecated Grid param 2025-02-14 11:37:21 -06:00
e0ebd43e7a bump: version 0.22.5 → 0.22.6 2025-02-01 15:18:12 -06:00
c7ee9de9eb fix: register vue3 form component for products -> make batch 2024-12-28 16:43:22 -06:00
950db697a0 bump: version 0.22.4 → 0.22.5 2024-12-16 12:46:45 -06:00
358b3b75a5 fix: whoops this is latest rattail 2024-12-10 13:05:32 -06:00
7e559a01b3 fix: require newer rattail lib 2024-12-10 12:52:49 -06:00
23bdde245a fix: require newer wuttaweb 2024-12-10 12:34:34 -06:00
2c269b640b fix: let caller request safe HTML literal for rendered grid table
mostly just for convenience
2024-12-01 18:12:30 -06:00
Lance Edgar
f1c8ffedda bump: version 0.22.3 → 0.22.4 2024-11-22 12:57:04 -06:00
Lance Edgar
aace6033c5 fix: avoid error in product search for duplicated key 2024-11-20 20:17:21 -06:00
Lance Edgar
7171c7fb06 fix: use vmodel for confirm password widget input
since previously this did not work at all for butterball (vue3 +
oruga) - although it was never clear why per se..

Refs: #1
2024-11-19 20:53:23 -06:00
Lance Edgar
993f066f2c bump: version 0.22.2 → 0.22.3 2024-11-19 15:45:37 -06:00
Lance Edgar
980031f524 fix: avoid error for trainwreck query when not a customer
when viewing a person's profile, who does not have a customer record,
the trainwreck query can't really return anything since it normally
should be matching on the customer ID
2024-11-18 14:59:50 -06:00
Lance Edgar
bcaf0d08bc bump: version 0.22.1 → 0.22.2 2024-11-18 14:08:10 -06:00
Lance Edgar
ac439c949b fix: use local/custom enum for continuum operations
since we can't rely on that existing in rattail proper, due to it not
always having sqlalchemy
2024-11-12 19:45:24 -06:00
Lance Edgar
20b3f87dbe fix: add basic master view for Product Costs 2024-11-12 18:30:50 -06:00
Lance Edgar
9e55717041 fix: show continuum operation type when viewing version history 2024-11-12 18:28:41 -06:00
Lance Edgar
772b6610cb fix: always define app attr for ViewSupplement 2024-11-12 18:26:36 -06:00
Lance Edgar
3f27f626df fix: avoid deprecated import 2024-11-10 19:16:45 -06:00
Lance Edgar
29743e70b7 bump: version 0.22.0 → 0.22.1 2024-11-02 16:56:28 -05:00
Lance Edgar
54220601ed fix: fix submit button for running problem report
esp. on Chrome(-based) browsers
2024-11-01 17:47:46 -05:00
Lance Edgar
9a6f8970ae fix: avoid deprecated grid method 2024-10-23 09:46:14 -05:00
Lance Edgar
28f90ad6b5 bump: version 0.21.11 → 0.22.0 2024-10-22 17:09:29 -05:00
Lance Edgar
535317e4f7 fix: avoid deprecated method to suggest username 2024-10-22 15:04:40 -05:00
Lance Edgar
072db39233 feat: add support for new ordering batch from parsed file 2024-10-22 14:26:10 -05:00
Lance Edgar
c6365f2631 bump: version 0.21.10 → 0.21.11 2024-10-03 09:05:46 -05:00
Lance Edgar
d520f64fee fix: custom method for adding grid action
since for now, we are using custom grid action class
2024-10-03 08:56:52 -05:00
Lance Edgar
2308d2e240 fix: become/stop root should redirect to previous url
for default theme; butterball already did that
2024-09-16 12:55:58 -05:00
Lance Edgar
0b4efae392 bump: version 0.21.9 → 0.21.10 2024-09-15 10:56:01 -05:00
Lance Edgar
0b646d2d18 fix: update project repo links, kallithea -> forgejo 2024-09-14 12:49:37 -05:00
Lance Edgar
a4d81a6e3c docs: use markdown for readme file 2024-09-13 18:16:07 -05:00
Lance Edgar
5e742eab17 fix: use better icon for submit button on login page 2024-09-09 08:32:28 -05:00
Lance Edgar
b9b8bbd2ea fix: wrap notes text for batch view 2024-08-29 17:18:32 -05:00
Lance Edgar
8df52bf2a2 fix: expose datasync consumer batch size via configure page 2024-08-29 17:01:49 -05:00
Lance Edgar
55f45ae8a0 bump: version 0.21.8 → 0.21.9 2024-08-28 17:38:33 -05:00
Lance Edgar
2219cf8198 fix: render custom attrs in form component tag 2024-08-28 17:38:05 -05:00
Lance Edgar
9be2f63475 bump: version 0.21.7 → 0.21.8 2024-08-28 14:37:40 -05:00
Lance Edgar
812d8d2349 fix: ignore session kwarg for MasterView.make_row_grid() 2024-08-28 14:37:18 -05:00
Lance Edgar
20dcdd8b86 bump: version 0.21.6 → 0.21.7 2024-08-28 14:20:51 -05:00
Lance Edgar
bc399182ba fix: avoid error when form value cannot be obtained 2024-08-28 14:20:17 -05:00
Lance Edgar
71d63f6b93 bump: version 0.21.5 → 0.21.6 2024-08-28 09:53:37 -05:00
Lance Edgar
0b6cfaa9c5 fix: avoid error when grid value cannot be obtained 2024-08-28 09:53:14 -05:00
Lance Edgar
b81914fbf5 test: fix broken test 2024-08-28 00:35:15 -05:00
Lance Edgar
b30f066c41 bump: version 0.21.4 → 0.21.5 2024-08-28 00:30:15 -05:00
Lance Edgar
2e20fc5b75 fix: set empty string for "-new-" file configure option
otherwise the "-new-" option is not properly auto-selected
2024-08-27 13:50:30 -05:00
Lance Edgar
ca05e68890 bump: version 0.21.3 → 0.21.4 2024-08-26 16:12:14 -05:00
Lance Edgar
7a9d5772db fix: handle differing email profile keys for appinfo/configure
hopefully this all can improve some day soon..
2024-08-26 16:11:32 -05:00
Lance Edgar
dffd951369 bump: version 0.21.2 → 0.21.3 2024-08-26 15:25:56 -05:00
Lance Edgar
d67eb2f1cc fix: show non-standard config values for app info configure email
this page is currently showing some basic email sender/recips etc. but
the config keys traditionally used by rattail are different than
wuttjamaican..so for now we must "translate"
2024-08-26 15:24:40 -05:00
Lance Edgar
3a9bf69aa7 bump: version 0.21.1 → 0.21.2 2024-08-26 14:56:15 -05:00
Lance Edgar
d1f4c0f150 fix: refactor waterpark base template to use wutta feedback component
although for now we still provide the template and add reply-to
2024-08-26 14:54:45 -05:00
Lance Edgar
b7991b5dc6 fix: fix input/output file upload feature for configure pages, per oruga 2024-08-23 16:18:17 -05:00
Lance Edgar
c1a2c9cc70 fix: tweak how grid data translates to Vue template context
per wuttaweb changes
2024-08-23 14:14:17 -05:00
Lance Edgar
37f760959d fix: merge filters into main grid template
to better match wuttaweb
2024-08-22 19:58:27 -05:00
Lance Edgar
cea3e4b927 fix: add basic wutta view for users
just proving concepts still at this point..nothing reliable
2024-08-22 19:40:21 -05:00
Lance Edgar
29531c83c4 fix: some fixes for wutta people view 2024-08-22 19:21:48 -05:00
Lance Edgar
4c3e3aeb6a fix: various fixes for waterpark theme 2024-08-22 17:09:58 -05:00
Lance Edgar
c176d97870 fix: avoid deprecated component form kwarg 2024-08-22 15:54:15 -05:00
41 changed files with 1504 additions and 786 deletions

View file

@ -5,6 +5,139 @@ All notable changes to Tailbone will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## v0.22.7 (2025-02-19)
### Fix
- stop using old config for logo image url on login page
- fix warning msg for deprecated Grid param
## v0.22.6 (2025-02-01)
### Fix
- register vue3 form component for products -> make batch
## v0.22.5 (2024-12-16)
### Fix
- whoops this is latest rattail
- require newer rattail lib
- require newer wuttaweb
- let caller request safe HTML literal for rendered grid table
## v0.22.4 (2024-11-22)
### Fix
- avoid error in product search for duplicated key
- use vmodel for confirm password widget input
## v0.22.3 (2024-11-19)
### Fix
- avoid error for trainwreck query when not a customer
## v0.22.2 (2024-11-18)
### Fix
- use local/custom enum for continuum operations
- add basic master view for Product Costs
- show continuum operation type when viewing version history
- always define `app` attr for ViewSupplement
- avoid deprecated import
## v0.22.1 (2024-11-02)
### Fix
- fix submit button for running problem report
- avoid deprecated grid method
## v0.22.0 (2024-10-22)
### Feat
- add support for new ordering batch from parsed file
### Fix
- avoid deprecated method to suggest username
## v0.21.11 (2024-10-03)
### Fix
- custom method for adding grid action
- become/stop root should redirect to previous url
## v0.21.10 (2024-09-15)
### Fix
- update project repo links, kallithea -> forgejo
- use better icon for submit button on login page
- wrap notes text for batch view
- expose datasync consumer batch size via configure page
## v0.21.9 (2024-08-28)
### Fix
- render custom attrs in form component tag
## v0.21.8 (2024-08-28)
### Fix
- ignore session kwarg for `MasterView.make_row_grid()`
## v0.21.7 (2024-08-28)
### Fix
- avoid error when form value cannot be obtained
## v0.21.6 (2024-08-28)
### Fix
- avoid error when grid value cannot be obtained
## v0.21.5 (2024-08-28)
### Fix
- set empty string for "-new-" file configure option
## v0.21.4 (2024-08-26)
### Fix
- handle differing email profile keys for appinfo/configure
## v0.21.3 (2024-08-26)
### Fix
- show non-standard config values for app info configure email
## v0.21.2 (2024-08-26)
### Fix
- refactor waterpark base template to use wutta feedback component
- fix input/output file upload feature for configure pages, per oruga
- tweak how grid data translates to Vue template context
- merge filters into main grid template
- add basic wutta view for users
- some fixes for wutta people view
- various fixes for waterpark theme
- avoid deprecated `component` form kwarg
## v0.21.1 (2024-08-22)
### Fix

View file

@ -1,10 +1,8 @@
Tailbone
========
# Tailbone
Tailbone is an extensible web application based on Rattail. It provides a
"back-office network environment" (BONE) for use in managing retail data.
Please see Rattail's `home page`_ for more information.
.. _home page: http://rattailproject.org/
Please see Rattail's [home page](http://rattailproject.org/) for more
information.

View file

@ -27,10 +27,10 @@ templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
intersphinx_mapping = {
'rattail': ('https://rattailproject.org/docs/rattail/', None),
'rattail': ('https://docs.wuttaproject.org/rattail/', None),
'webhelpers2': ('https://webhelpers2.readthedocs.io/en/latest/', None),
'wuttaweb': ('https://rattailproject.org/docs/wuttaweb/', None),
'wuttjamaican': ('https://rattailproject.org/docs/wuttjamaican/', None),
'wuttaweb': ('https://docs.wuttaproject.org/wuttaweb/', None),
'wuttjamaican': ('https://docs.wuttaproject.org/wuttjamaican/', None),
}
# allow todo entries to show up

View file

@ -6,9 +6,9 @@ build-backend = "hatchling.build"
[project]
name = "Tailbone"
version = "0.21.1"
version = "0.22.7"
description = "Backoffice Web Application for Rattail"
readme = "README.rst"
readme = "README.md"
authors = [{name = "Lance Edgar", email = "lance@edbob.org"}]
license = {text = "GNU GPL v3+"}
classifiers = [
@ -53,13 +53,13 @@ dependencies = [
"pyramid_mako",
"pyramid_retry",
"pyramid_tm",
"rattail[db,bouncer]>=0.18.4",
"rattail[db,bouncer]>=0.20.1",
"sa-filters",
"simplejson",
"transaction",
"waitress",
"WebHelpers2",
"WuttaWeb>=0.12.0",
"WuttaWeb>=0.21.0",
"zope.sqlalchemy>=1.5",
]
@ -84,9 +84,9 @@ tailbone = "tailbone.config:ConfigExtension"
[project.urls]
Homepage = "https://rattailproject.org"
Repository = "https://kallithea.rattailproject.org/rattail-project/tailbone"
Issues = "https://redmine.rattailproject.org/projects/tailbone/issues"
Changelog = "https://kallithea.rattailproject.org/rattail-project/tailbone/files/master/CHANGELOG.md"
Repository = "https://forgejo.wuttaproject.org/rattail/tailbone"
Issues = "https://forgejo.wuttaproject.org/rattail/tailbone/issues"
Changelog = "https://forgejo.wuttaproject.org/rattail/tailbone/src/branch/master/CHANGELOG.md"
[tool.commitizen]

View file

@ -29,8 +29,7 @@ import logging
import humanize
import sqlalchemy as sa
from rattail.db import model
from rattail.util import pretty_quantity
from rattail.db.model import PurchaseBatch, PurchaseBatchRow
from cornice import Service
from deform import widget as dfwidget
@ -45,7 +44,7 @@ log = logging.getLogger(__name__)
class ReceivingBatchViews(APIBatchView):
model_class = model.PurchaseBatch
model_class = PurchaseBatch
default_handler_spec = 'rattail.batch.purchase:PurchaseBatchHandler'
route_prefix = 'receivingbatchviews'
permission_prefix = 'receiving'
@ -55,7 +54,8 @@ class ReceivingBatchViews(APIBatchView):
supports_execute = True
def base_query(self):
query = super(ReceivingBatchViews, self).base_query()
model = self.app.model
query = super().base_query()
query = query.filter(model.PurchaseBatch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING)
return query
@ -85,7 +85,7 @@ class ReceivingBatchViews(APIBatchView):
# assume "receive from PO" if given a PO key
if data.get('purchase_key'):
data['receiving_workflow'] = 'from_po'
data['workflow'] = 'from_po'
return super().create_object(data)
@ -120,6 +120,7 @@ class ReceivingBatchViews(APIBatchView):
return self._get(obj=batch)
def eligible_purchases(self):
model = self.app.model
uuid = self.request.params.get('vendor_uuid')
vendor = self.Session.get(model.Vendor, uuid) if uuid else None
if not vendor:
@ -176,7 +177,7 @@ class ReceivingBatchViews(APIBatchView):
class ReceivingBatchRowViews(APIBatchRowView):
model_class = model.PurchaseBatchRow
model_class = PurchaseBatchRow
default_handler_spec = 'rattail.batch.purchase:PurchaseBatchHandler'
route_prefix = 'receiving.rows'
permission_prefix = 'receiving'
@ -185,7 +186,8 @@ class ReceivingBatchRowViews(APIBatchRowView):
supports_quick_entry = True
def make_filter_spec(self):
filters = super(ReceivingBatchRowViews, self).make_filter_spec()
model = self.app.model
filters = super().make_filter_spec()
if filters:
# must translate certain convenience filters
@ -296,11 +298,11 @@ class ReceivingBatchRowViews(APIBatchRowView):
return filters
def normalize(self, row):
data = super(ReceivingBatchRowViews, self).normalize(row)
data = super().normalize(row)
model = self.app.model
batch = row.batch
app = self.get_rattail_app()
prodder = app.get_products_handler()
prodder = self.app.get_products_handler()
data['product_uuid'] = row.product_uuid
data['item_id'] = row.item_id
@ -375,7 +377,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
if accounted_for:
# some product accounted for; button should receive "remainder" only
if remainder:
remainder = pretty_quantity(remainder)
remainder = self.app.render_quantity(remainder)
data['quick_receive_quantity'] = remainder
data['quick_receive_text'] = "Receive Remainder ({} {})".format(
remainder, data['unit_uom'])
@ -386,7 +388,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
else: # nothing yet accounted for, button should receive "all"
if not remainder:
log.warning("quick receive remainder is empty for row %s", row.uuid)
remainder = pretty_quantity(remainder)
remainder = self.app.render_quantity(remainder)
data['quick_receive_quantity'] = remainder
data['quick_receive_text'] = "Receive ALL ({} {})".format(
remainder, data['unit_uom'])
@ -414,7 +416,7 @@ class ReceivingBatchRowViews(APIBatchRowView):
data['received_alert'] = None
if self.batch_handler.get_units_confirmed(row):
msg = "You have already received some of this product; last update was {}.".format(
humanize.naturaltime(app.make_utc() - row.modified))
humanize.naturaltime(self.app.make_utc() - row.modified))
data['received_alert'] = msg
return data
@ -423,6 +425,8 @@ class ReceivingBatchRowViews(APIBatchRowView):
"""
View which handles "receiving" against a particular batch row.
"""
model = self.app.model
# first do basic input validation
schema = ReceiveRow().bind(session=self.Session())
form = forms.Form(schema=schema, request=self.request)

View file

@ -26,7 +26,6 @@ Tailbone Web API - Master View
import json
from rattail.config import parse_bool
from rattail.db.util import get_fieldnames
from cornice import resource, Service
@ -185,7 +184,7 @@ class APIMasterView(APIView):
if sortcol:
spec = {
'field': sortcol.field_name,
'direction': 'asc' if parse_bool(self.request.params['ascending']) else 'desc',
'direction': 'asc' if self.config.parse_bool(self.request.params['ascending']) else 'desc',
}
if sortcol.model_name:
spec['model'] = sortcol.model_name

View file

@ -62,6 +62,17 @@ def make_rattail_config(settings):
# nb. this is for compaibility with wuttaweb
settings['wutta_config'] = rattail_config
# must import all sqlalchemy models before things get rolling,
# otherwise can have errors about continuum TransactionMeta class
# not yet mapped, when relevant pages are first requested...
# cf. https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/database/sqlalchemy.html#importing-all-sqlalchemy-models
# hat tip to https://stackoverflow.com/a/59241485
if getattr(rattail_config, 'tempmon_engine', None):
from rattail_tempmon.db import model as tempmon_model, Session as TempmonSession
tempmon_session = TempmonSession()
tempmon_session.query(tempmon_model.Appliance).first()
tempmon_session.close()
# configure database sessions
if hasattr(rattail_config, 'appdb_engine'):
tailbone.db.Session.configure(bind=rattail_config.appdb_engine)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -270,9 +270,21 @@ class VersionDiff(Diff):
for field in self.fields:
values[field] = {'before': self.render_old_value(field),
'after': self.render_new_value(field)}
operation = None
if self.version.operation_type == continuum.Operation.INSERT:
operation = 'INSERT'
elif self.version.operation_type == continuum.Operation.UPDATE:
operation = 'UPDATE'
elif self.version.operation_type == continuum.Operation.DELETE:
operation = 'DELETE'
else:
operation = self.version.operation_type
return {
'key': id(self.version),
'model_title': self.title,
'operation': operation,
'diff_class': self.nature,
'fields': self.fields,
'values': values,

View file

@ -401,6 +401,8 @@ class Form(object):
self.edit_help_url = edit_help_url
self.route_prefix = route_prefix
self.button_icon_submit = kwargs.get('button_icon_submit', 'save')
def __iter__(self):
return iter(self.fields)
@ -1037,9 +1039,9 @@ class Form(object):
def render_vue_tag(self, **kwargs):
""" """
return self.render_vuejs_component()
return self.render_vuejs_component(**kwargs)
def render_vuejs_component(self):
def render_vuejs_component(self, **kwargs):
"""
Render the Vue.js component HTML for the form.
@ -1050,10 +1052,11 @@ class Form(object):
<tailbone-form :configure-fields-help="configureFieldsHelp">
</tailbone-form>
"""
kwargs = dict(self.vuejs_component_kwargs)
kw = dict(self.vuejs_component_kwargs)
kw.update(kwargs)
if self.can_edit_help:
kwargs.setdefault(':configure-fields-help', 'configureFieldsHelp')
return HTML.tag(self.vue_tagname, **kwargs)
kw.setdefault(':configure-fields-help', 'configureFieldsHelp')
return HTML.tag(self.vue_tagname, **kw)
def set_json_data(self, key, value):
"""
@ -1380,7 +1383,11 @@ class Form(object):
return getattr(record, field_name)
except AttributeError:
pass
return record[field_name]
try:
return record[field_name]
except TypeError:
pass
# TODO: is this always safe to do?
elif self.defaults and field_name in self.defaults:

View file

@ -24,9 +24,10 @@
Core Grid Classes
"""
from urllib.parse import urlencode
import warnings
import inspect
import logging
import warnings
from urllib.parse import urlencode
import sqlalchemy as sa
from sqlalchemy import orm
@ -234,7 +235,7 @@ class Grid(WuttaGrid):
if 'pageable' in kwargs:
warnings.warn("pageable param is deprecated for Grid(); "
"please use vue_tagname param instead",
"please use paginated param instead",
DeprecationWarning, stacklevel=2)
kwargs.setdefault('paginated', kwargs.pop('pageable'))
@ -574,7 +575,11 @@ class Grid(WuttaGrid):
return getattr(obj, column_name)
except AttributeError:
pass
return obj[column_name]
try:
return obj[column_name]
except TypeError:
pass
def render_currency(self, obj, column_name):
value = self.obtain_value(obj, column_name)
@ -858,9 +863,13 @@ class Grid(WuttaGrid):
settings['page'] = self.page
if self.filterable:
for filtr in self.iter_filters():
settings['filter.{}.active'.format(filtr.key)] = filtr.default_active
settings['filter.{}.verb'.format(filtr.key)] = filtr.default_verb
settings['filter.{}.value'.format(filtr.key)] = filtr.default_value
defaults = self.filter_defaults.get(filtr.key, {})
settings[f'filter.{filtr.key}.active'] = defaults.get('active',
filtr.default_active)
settings[f'filter.{filtr.key}.verb'] = defaults.get('verb',
filtr.default_verb)
settings[f'filter.{filtr.key}.value'] = defaults.get('value',
filtr.default_value)
# If user has default settings on file, apply those first.
if self.user_has_defaults():
@ -1214,6 +1223,7 @@ class Grid(WuttaGrid):
def render_table_element(self, template='/grids/b-table.mako',
data_prop='gridData', empty_labels=False,
literal=False,
**kwargs):
"""
This is intended for ad-hoc "small" grids with static data. Renders
@ -1230,7 +1240,10 @@ class Grid(WuttaGrid):
if context['paginated']:
context.setdefault('per_page', 20)
context['view_click_handler'] = self.get_view_click_handler()
return render(template, context)
result = render(template, context)
if literal:
result = HTML.literal(result)
return result
def get_view_click_handler(self):
""" """
@ -1239,7 +1252,7 @@ class Grid(WuttaGrid):
view = None
for action in self.actions:
if action.key == 'view':
return action.click_handler
return getattr(action, 'click_handler', None)
def set_filters_sequence(self, filters, only=False):
"""
@ -1313,28 +1326,6 @@ class Grid(WuttaGrid):
return data
def render_filters(self, template='/grids/filters.mako', **kwargs):
"""
Render the filters to a Unicode string, using the specified template.
Additional kwargs are passed along as context to the template.
"""
# Provide default data to filters form, so renderer can do some of the
# work for us.
data = {}
for filtr in self.iter_active_filters():
data['{}.active'.format(filtr.key)] = filtr.active
data['{}.verb'.format(filtr.key)] = filtr.verb
data[filtr.key] = filtr.value
form = gridfilters.GridFiltersForm(self.filters,
request=self.request,
defaults=data)
kwargs['request'] = self.request
kwargs['grid'] = self
kwargs['form'] = form
return render(template, kwargs)
def render_actions(self, row, i): # pragma: no cover
""" """
warnings.warn("grid.render_actions() is deprecated!",
@ -1420,6 +1411,10 @@ class Grid(WuttaGrid):
if hasattr(rowobj, 'uuid'):
return rowobj.uuid
def get_vue_context(self):
""" """
return self.get_table_data()
def get_vue_data(self):
""" """
table_data = self.get_table_data()
@ -1475,10 +1470,22 @@ class Grid(WuttaGrid):
# leverage configured rendering logic where applicable;
# otherwise use "raw" data value as string
value = self.obtain_value(rowobj, name)
if self.renderers and name in self.renderers:
value = self.renderers[name](rowobj, name)
else:
value = self.obtain_value(rowobj, name)
renderer = self.renderers[name]
# TODO: legacy renderer callables require 2 args,
# but wuttaweb callables require 3 args
sig = inspect.signature(renderer)
required = [param for param in sig.parameters.values()
if param.default == param.empty]
if len(required) == 2:
# TODO: legacy renderer
value = renderer(rowobj, name)
else: # the future
value = renderer(rowobj, name, value)
if value is None:
value = ""
@ -1511,6 +1518,8 @@ class Grid(WuttaGrid):
results = {
'data': data,
'row_classes': status_map,
# TODO: deprecate / remove this
'row_status_map': status_map,
}
@ -1539,6 +1548,11 @@ class Grid(WuttaGrid):
self._table_data = results
return self._table_data
# TODO: remove this when we use upstream GridAction
def add_action(self, key, **kwargs):
""" """
self.actions.append(GridAction(self.request, key, **kwargs))
def set_action_urls(self, row, rowobj, i):
"""
Pre-generate all action URLs for the given data row. Meant for use

View file

@ -394,6 +394,11 @@ class TailboneMenuHandler(WuttaMenuHandler):
'route': 'products',
'perm': 'products.list',
},
{
'title': "Product Costs",
'route': 'product_costs',
'perm': 'product_costs.list',
},
{
'title': "Departments",
'route': 'departments',
@ -451,6 +456,11 @@ class TailboneMenuHandler(WuttaMenuHandler):
'route': 'vendors',
'perm': 'vendors.list',
},
{
'title': "Product Costs",
'route': 'product_costs',
'perm': 'product_costs.list',
},
{'type': 'sep'},
{
'title': "Ordering",

View file

@ -632,9 +632,23 @@
% endif
<div class="navbar-dropdown">
% if request.is_root:
${h.link_to("Stop being root", url('stop_root'), class_='navbar-item root-user')}
${h.form(url('stop_root'), ref='stopBeingRootForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" value="${request.current_route_url()}" />
<a @click="$refs.stopBeingRootForm.submit()"
class="navbar-item root-user">
Stop being root
</a>
${h.end_form()}
% elif request.is_admin:
${h.link_to("Become root", url('become_root'), class_='navbar-item root-user')}
${h.form(url('become_root'), ref='startBeingRootForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" value="${request.current_route_url()}" />
<a @click="$refs.startBeingRootForm.submit()"
class="navbar-item root-user">
Become root
</a>
${h.end_form()}
% endif
% if messaging_enabled:
${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'), class_='navbar-item')}
@ -642,7 +656,11 @@
% if request.is_root or not request.user.prevent_password_change:
${h.link_to("Change Password", url('change_password'), class_='navbar-item')}
% endif
${h.link_to("Edit Preferences", url('my.preferences'), class_='navbar-item')}
% try:
## nb. does not exist yet for wuttaweb
${h.link_to("Edit Preferences", url('my.preferences'), class_='navbar-item')}
% except:
% endtry
${h.link_to("Logout", url('logout'), class_='navbar-item')}
</div>
</div>
@ -668,7 +686,7 @@
text="Edit This">
</once-button>
% endif
% if getattr(master, 'cloneable', False) and master.has_perm('clone'):
% if getattr(master, 'cloneable', False) and not master.cloning and master.has_perm('clone'):
<once-button tag="a" href="${master.get_action_url('clone', instance)}"
icon-left="object-ungroup"
text="Clone This">

View file

@ -92,7 +92,7 @@
<b-select name="${tmpl['setting_file']}"
v-model="inputFileTemplateSettings['${tmpl['setting_file']}']"
@input="settingsNeedSaved = true">
<option :value="null">-new-</option>
<option value="">-new-</option>
<option v-for="option in inputFileTemplateFileOptions['${tmpl['key']}']"
:key="option"
:value="option">
@ -104,22 +104,40 @@
<b-field label="Upload"
v-show="inputFileTemplateSettings['${tmpl['setting_mode']}'] == 'hosted' && !inputFileTemplateSettings['${tmpl['setting_file']}']">
<b-field class="file is-primary"
:class="{'has-name': !!inputFileTemplateSettings['${tmpl['setting_file']}']}">
<b-upload name="${tmpl['setting_file']}.upload"
v-model="inputFileTemplateUploads['${tmpl['key']}']"
class="file-label"
@input="settingsNeedSaved = true">
<span class="file-cta">
<b-icon class="file-icon" pack="fas" icon="upload"></b-icon>
<span class="file-label">Click to upload</span>
</span>
</b-upload>
<span v-if="inputFileTemplateUploads['${tmpl['key']}']"
class="file-name">
{{ inputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</b-field>
% if request.use_oruga:
<o-field class="file">
<o-upload name="${tmpl['setting_file']}.upload"
v-model="inputFileTemplateUploads['${tmpl['key']}']"
v-slot="{ onclick }"
@input="settingsNeedSaved = true">
<o-button variant="primary"
@click="onclick">
<o-icon icon="upload" />
<span>Click to upload</span>
</o-button>
<span class="file-name" v-if="inputFileTemplateUploads['${tmpl['key']}']">
{{ inputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</o-upload>
</o-field>
% else:
<b-field class="file is-primary"
:class="{'has-name': !!inputFileTemplateSettings['${tmpl['setting_file']}']}">
<b-upload name="${tmpl['setting_file']}.upload"
v-model="inputFileTemplateUploads['${tmpl['key']}']"
class="file-label"
@input="settingsNeedSaved = true">
<span class="file-cta">
<b-icon class="file-icon" pack="fas" icon="upload"></b-icon>
<span class="file-label">Click to upload</span>
</span>
</b-upload>
<span v-if="inputFileTemplateUploads['${tmpl['key']}']"
class="file-name">
{{ inputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</b-field>
% endif
</b-field>
@ -162,7 +180,7 @@
<b-select name="${tmpl['setting_file']}"
v-model="outputFileTemplateSettings['${tmpl['setting_file']}']"
@input="settingsNeedSaved = true">
<option :value="null">-new-</option>
<option value="">-new-</option>
<option v-for="option in outputFileTemplateFileOptions['${tmpl['key']}']"
:key="option"
:value="option">
@ -174,23 +192,40 @@
<b-field label="Upload"
v-show="outputFileTemplateSettings['${tmpl['setting_mode']}'] == 'hosted' && !outputFileTemplateSettings['${tmpl['setting_file']}']">
<b-field class="file is-primary"
:class="{'has-name': !!outputFileTemplateSettings['${tmpl['setting_file']}']}">
<b-upload name="${tmpl['setting_file']}.upload"
v-model="outputFileTemplateUploads['${tmpl['key']}']"
class="file-label"
@input="settingsNeedSaved = true">
<span class="file-cta">
<b-icon class="file-icon" pack="fas" icon="upload"></b-icon>
<span class="file-label">Click to upload</span>
</span>
</b-upload>
<span v-if="outputFileTemplateUploads['${tmpl['key']}']"
class="file-name">
{{ outputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</b-field>
% if request.use_oruga:
<o-field class="file">
<o-upload name="${tmpl['setting_file']}.upload"
v-model="outputFileTemplateUploads['${tmpl['key']}']"
v-slot="{ onclick }"
@input="settingsNeedSaved = true">
<o-button variant="primary"
@click="onclick">
<o-icon icon="upload" />
<span>Click to upload</span>
</o-button>
<span class="file-name" v-if="outputFileTemplateUploads['${tmpl['key']}']">
{{ outputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</o-upload>
</o-field>
% else:
<b-field class="file is-primary"
:class="{'has-name': !!outputFileTemplateSettings['${tmpl['setting_file']}']}">
<b-upload name="${tmpl['setting_file']}.upload"
v-model="outputFileTemplateUploads['${tmpl['key']}']"
class="file-label"
@input="settingsNeedSaved = true">
<span class="file-cta">
<b-icon class="file-icon" pack="fas" icon="upload"></b-icon>
<span class="file-label">Click to upload</span>
</span>
</b-upload>
<span v-if="outputFileTemplateUploads['${tmpl['key']}']"
class="file-name">
{{ outputFileTemplateUploads['${tmpl['key']}'].name }}
</span>
</b-field>
% endif
</b-field>
</b-field>
@ -245,15 +280,14 @@
<b-button @click="purgeSettingsShowDialog = false">
Cancel
</b-button>
${h.form(request.current_route_url())}
${h.form(request.current_route_url(), **{'@submit': 'purgingSettings = true'})}
${h.csrf_token(request)}
${h.hidden('remove_settings', 'true')}
<b-button type="is-danger"
native-type="submit"
:disabled="purgingSettings"
icon-pack="fas"
icon-left="trash"
@click="purgingSettings = true">
icon-left="trash">
{{ purgingSettings ? "Working, please wait..." : "Remove All Settings" }}
</b-button>
${h.end_form()}
@ -275,16 +309,6 @@
ThisPageData.simpleSettings = ${json.dumps(simple_settings)|n}
% endif
% if input_file_template_settings is not Undefined:
ThisPageData.inputFileTemplateSettings = ${json.dumps(input_file_template_settings)|n}
ThisPageData.inputFileTemplateFileOptions = ${json.dumps(input_file_options)|n}
ThisPageData.inputFileTemplateUploads = {
% for key in input_file_templates:
'${key}': null,
% endfor
}
% endif
ThisPageData.purgeSettingsShowDialog = false
ThisPageData.purgingSettings = false
@ -297,30 +321,7 @@
this.purgeSettingsShowDialog = true
}
% if input_file_template_settings is not Undefined:
ThisPage.methods.validateInputFileTemplateSettings = function() {
% for tmpl in input_file_templates.values():
if (this.inputFileTemplateSettings['${tmpl['setting_mode']}'] == 'hosted') {
if (!this.inputFileTemplateSettings['${tmpl['setting_file']}']) {
if (!this.inputFileTemplateUploads['${tmpl['key']}']) {
return "You must provide a file to upload for the ${tmpl['label']} template."
}
}
}
% endfor
}
% endif
ThisPage.methods.validateSettings = function() {
let msg
% if input_file_template_settings is not Undefined:
msg = this.validateInputFileTemplateSettings()
if (msg) {
return msg
}
% endif
}
ThisPage.methods.validateSettings = function() {}
ThisPage.methods.saveSettings = function() {
let msg
@ -366,6 +367,36 @@
window.addEventListener('beforeunload', this.beforeWindowUnload)
}
##############################
## input file templates
##############################
% if input_file_template_settings is not Undefined:
ThisPageData.inputFileTemplateSettings = ${json.dumps(input_file_template_settings)|n}
ThisPageData.inputFileTemplateFileOptions = ${json.dumps(input_file_options)|n}
ThisPageData.inputFileTemplateUploads = {
% for key in input_file_templates:
'${key}': null,
% endfor
}
ThisPage.methods.validateInputFileTemplateSettings = function() {
% for tmpl in input_file_templates.values():
if (this.inputFileTemplateSettings['${tmpl['setting_mode']}'] == 'hosted') {
if (!this.inputFileTemplateSettings['${tmpl['setting_file']}']) {
if (!this.inputFileTemplateUploads['${tmpl['key']}']) {
return "You must provide a file to upload for the ${tmpl['label']} template."
}
}
}
% endfor
}
ThisPageData.validators.push(ThisPage.methods.validateInputFileTemplateSettings)
% endif
##############################
## output file templates
##############################

View file

@ -83,8 +83,8 @@
</b-notification>
<b-field>
<b-checkbox name="use_profile_settings"
v-model="useProfileSettings"
<b-checkbox name="rattail.datasync.use_profile_settings"
v-model="simpleSettings['rattail.datasync.use_profile_settings']"
native-value="true"
@input="settingsNeedSaved = true">
Use these Settings to configure watchers and consumers
@ -99,7 +99,7 @@
</div>
<div class="level-right">
<div class="level-item"
v-show="useProfileSettings">
v-show="simpleSettings['rattail.datasync.use_profile_settings']">
<b-button type="is-primary"
@click="newProfile()"
icon-pack="fas"
@ -162,7 +162,7 @@
</${b}-table-column>
<${b}-table-column label="Actions"
v-slot="props"
v-if="useProfileSettings">
v-if="simpleSettings['rattail.datasync.use_profile_settings']">
<a href="#"
class="grid-action"
@click.prevent="editProfile(props.row)">
@ -580,18 +580,27 @@
<b-field label="Supervisor Process Name"
message="This should be the complete name, including group - e.g. poser:poser_datasync"
expanded>
<b-input name="supervisor_process_name"
v-model="supervisorProcessName"
<b-input name="rattail.datasync.supervisor_process_name"
v-model="simpleSettings['rattail.datasync.supervisor_process_name']"
@input="settingsNeedSaved = true"
expanded>
</b-input>
</b-field>
<b-field label="Consumer Batch Size"
message="Max number of changes to be consumed at once."
expanded>
<numeric-input name="rattail.datasync.batch_size_limit"
v-model="simpleSettings['rattail.datasync.batch_size_limit']"
@input="settingsNeedSaved = true" />
</b-field>
<h3 class="is-size-3">Legacy</h3>
<b-field label="Restart Command"
message="This will run as '${system_user}' system user - please configure sudoers as needed. Typical command is like: sudo supervisorctl restart poser:poser_datasync"
expanded>
<b-input name="restart_command"
v-model="restartCommand"
<b-input name="tailbone.datasync.restart"
v-model="simpleSettings['tailbone.datasync.restart']"
@input="settingsNeedSaved = true"
expanded>
</b-input>
@ -606,7 +615,6 @@
ThisPageData.showConfigFilesNote = false
ThisPageData.profilesData = ${json.dumps(profiles_data)|n}
ThisPageData.showDisabledProfiles = false
ThisPageData.useProfileSettings = ${json.dumps(use_profile_settings)|n}
ThisPageData.editProfileShowDialog = false
ThisPageData.editingProfile = null
@ -631,9 +639,6 @@
ThisPageData.editingConsumerRunas = null
ThisPageData.editingConsumerEnabled = true
ThisPageData.supervisorProcessName = ${json.dumps(supervisor_process_name)|n}
ThisPageData.restartCommand = ${json.dumps(restart_command)|n}
ThisPage.computed.updateConsumerDisabled = function() {
if (!this.editingConsumerKey) {
return true

View file

@ -1,6 +1,7 @@
<div i18n:domain="deform" tal:omit-tag=""
tal:define="oid oid|field.oid;
name name|field.name;
vmodel vmodel|'field_model_' + name;
css_class css_class|field.widget.css_class;
style style|field.widget.style;">
@ -8,7 +9,7 @@
${field.start_mapping()}
<b-input type="password"
name="${name}"
value="${field.widget.redisplay and cstruct or ''}"
v-model="${vmodel}"
tal:attributes="class string: form-control ${css_class or ''};
style style;
attributes|field.widget.attributes|{};"
@ -18,7 +19,6 @@
</b-input>
<b-input type="password"
name="${name}-confirm"
value="${field.widget.redisplay and confirm or ''}"
tal:attributes="class string: form-control ${css_class or ''};
style style;
confirm_attributes|field.widget.confirm_attributes|{};"

View file

@ -59,7 +59,7 @@
native-type="submit"
:disabled="${form.vue_component}Submitting"
icon-pack="fas"
icon-left="save">
icon-left="${form.button_icon_submit}">
{{ ${form.vue_component}Submitting ? "Working, please wait..." : "${form.button_label_submit}" }}
</b-button>
% else:

View file

@ -10,8 +10,70 @@
<div style="display: flex; flex-direction: column; justify-content: end;">
<div class="filters">
% if getattr(grid, 'filterable', False):
## TODO: stop using |n filter
${grid.render_filters(allow_save_defaults=allow_save_defaults)|n}
<form method="GET" @submit.prevent="applyFilters()">
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
<grid-filter v-for="key in filtersSequence"
:key="key"
:filter="filters[key]"
ref="gridFilters">
</grid-filter>
</div>
<div style="display: flex; gap: 0.5rem; margin-top: 0.5rem;">
<b-button type="is-primary"
native-type="submit"
icon-pack="fas"
icon-left="check">
Apply Filters
</b-button>
<b-button v-if="!addFilterShow"
icon-pack="fas"
icon-left="plus"
@click="addFilterInit()">
Add Filter
</b-button>
<b-autocomplete v-if="addFilterShow"
ref="addFilterAutocomplete"
:data="addFilterChoices"
v-model="addFilterTerm"
placeholder="Add Filter"
field="key"
:custom-formatter="formatAddFilterItem"
open-on-focus
keep-first
icon-pack="fas"
clearable
clear-on-select
@select="addFilterSelect">
</b-autocomplete>
<b-button @click="resetView()"
icon-pack="fas"
icon-left="home">
Default View
</b-button>
<b-button @click="clearFilters()"
icon-pack="fas"
icon-left="trash">
No Filters
</b-button>
% if allow_save_defaults and request.user:
<b-button @click="saveDefaults()"
icon-pack="fas"
icon-left="save"
:disabled="savingDefaults">
{{ savingDefaults ? "Working, please wait..." : "Save Defaults" }}
</b-button>
% endif
</div>
</form>
% endif
</div>
</div>
@ -249,7 +311,8 @@
<script type="text/javascript">
let ${grid.vue_component}CurrentData = ${json.dumps(grid.get_vue_data())|n}
const ${grid.vue_component}Context = ${json.dumps(grid.get_vue_context())|n}
let ${grid.vue_component}CurrentData = ${grid.vue_component}Context.data
let ${grid.vue_component}Data = {
loading: false,

View file

@ -1,67 +0,0 @@
## -*- coding: utf-8; -*-
<form action="${form.action_url}" method="GET" @submit.prevent="applyFilters()">
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
<grid-filter v-for="key in filtersSequence"
:key="key"
:filter="filters[key]"
ref="gridFilters">
</grid-filter>
</div>
<div style="display: flex; gap: 0.5rem; margin-top: 0.5rem;">
<b-button type="is-primary"
native-type="submit"
icon-pack="fas"
icon-left="check">
Apply Filters
</b-button>
<b-button v-if="!addFilterShow"
icon-pack="fas"
icon-left="plus"
@click="addFilterInit()">
Add Filter
</b-button>
<b-autocomplete v-if="addFilterShow"
ref="addFilterAutocomplete"
:data="addFilterChoices"
v-model="addFilterTerm"
placeholder="Add Filter"
field="key"
:custom-formatter="formatAddFilterItem"
open-on-focus
keep-first
icon-pack="fas"
clearable
clear-on-select
@select="addFilterSelect">
</b-autocomplete>
<b-button @click="resetView()"
icon-pack="fas"
icon-left="home">
Default View
</b-button>
<b-button @click="clearFilters()"
icon-pack="fas"
icon-left="trash">
No Filters
</b-button>
% if allow_save_defaults and request.user:
<b-button @click="saveDefaults()"
icon-pack="fas"
icon-left="save"
:disabled="savingDefaults">
{{ savingDefaults ? "Working, please wait..." : "Save Defaults" }}
</b-button>
% endif
</div>
</form>

View file

@ -196,6 +196,7 @@
<p class="block has-text-weight-bold">
{{ version.model_title }}
({{ version.operation }})
</p>
<table class="diff monospace is-size-7"

View file

@ -0,0 +1,74 @@
## -*- coding: utf-8; -*-
<%inherit file="/configure.mako" />
<%def name="form_content()">
<h3 class="block is-size-3">Workflows</h3>
<div class="block" style="padding-left: 2rem;">
<p class="block">
Users can only choose from the workflows enabled below.
</p>
<b-field>
<b-checkbox name="rattail.batch.purchase.allow_ordering_from_scratch"
v-model="simpleSettings['rattail.batch.purchase.allow_ordering_from_scratch']"
native-value="true"
@input="settingsNeedSaved = true">
From Scratch
</b-checkbox>
</b-field>
<b-field>
<b-checkbox name="rattail.batch.purchase.allow_ordering_from_file"
v-model="simpleSettings['rattail.batch.purchase.allow_ordering_from_file']"
native-value="true"
@input="settingsNeedSaved = true">
From Order File
</b-checkbox>
</b-field>
</div>
<h3 class="block is-size-3">Vendors</h3>
<div class="block" style="padding-left: 2rem;">
<b-field message="If not set, user must choose a &quot;supported&quot; vendor.">
<b-checkbox name="rattail.batch.purchase.allow_ordering_any_vendor"
v-model="simpleSettings['rattail.batch.purchase.allow_ordering_any_vendor']"
native-value="true"
@input="settingsNeedSaved = true">
Allow ordering for <span class="has-text-weight-bold">any</span> vendor
</b-checkbox>
</b-field>
</div>
<h3 class="block is-size-3">Order Parsers</h3>
<div class="block" style="padding-left: 2rem;">
<p class="block">
Only the selected file parsers will be exposed to users.
</p>
% for Parser in order_parsers:
<b-field message="${Parser.key}">
<b-checkbox name="order_parser_${Parser.key}"
v-model="orderParsers['${Parser.key}']"
native-value="true"
@input="settingsNeedSaved = true">
${Parser.title}
</b-checkbox>
</b-field>
% endfor
</div>
</%def>
<%def name="modify_vue_vars()">
${parent.modify_vue_vars()}
<script>
ThisPageData.orderParsers = ${json.dumps(order_parsers_data)|n}
</script>
</%def>

View file

@ -55,19 +55,20 @@
</%def>
<%def name="render_form_template()">
<script type="text/x-template" id="${form.component}-template">
<script type="text/x-template" id="${form.vue_tagname}-template">
${self.render_form_innards()}
</script>
</%def>
<%def name="modify_vue_vars()">
${parent.modify_vue_vars()}
<% request.register_component(form.vue_tagname, form.vue_component) %>
<script>
## TODO: ugh, an awful lot of duplicated code here (from /forms/deform.mako)
let ${form.vue_component} = {
template: '#${form.component}-template',
template: '#${form.vue_tagname}-template',
methods: {
## TODO: deprecate / remove the latter option here

View file

@ -69,12 +69,12 @@
<h3 class="block is-size-3">Vendors</h3>
<div class="block" style="padding-left: 2rem;">
<b-field message="If set, user must choose a &quot;supported&quot; vendor; otherwise they may choose &quot;any&quot; vendor.">
<b-checkbox name="rattail.batch.purchase.supported_vendors_only"
v-model="simpleSettings['rattail.batch.purchase.supported_vendors_only']"
<b-field message="If not set, user must choose a &quot;supported&quot; vendor.">
<b-checkbox name="rattail.batch.purchase.allow_receiving_any_vendor"
v-model="simpleSettings['rattail.batch.purchase.allow_receiving_any_vendor']"
native-value="true"
@input="settingsNeedSaved = true">
Only allow batch for "supported" vendors
Allow receiving for <span class="has-text-weight-bold">any</span> vendor
</b-checkbox>
</b-field>

View file

@ -45,11 +45,10 @@
<b-button @click="runReportShowDialog = false">
Cancel
</b-button>
${h.form(master.get_action_url('execute', instance))}
${h.form(master.get_action_url('execute', instance), **{'@submit': 'runReportSubmitting = true'})}
${h.csrf_token(request)}
<b-button type="is-primary"
native-type="submit"
@click="runReportSubmitting = true"
:disabled="runReportSubmitting"
icon-pack="fas"
icon-left="arrow-circle-right">

View file

@ -909,7 +909,7 @@
${h.form(url('stop_root'), ref='stopBeingRootForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" value="${request.current_route_url()}" />
<a @click="stopBeingRoot()"
<a @click="$refs.stopBeingRootForm.submit()"
class="navbar-item has-background-danger has-text-white">
Stop being root
</a>
@ -918,7 +918,7 @@
${h.form(url('become_root'), ref='startBeingRootForm')}
${h.csrf_token(request)}
<input type="hidden" name="referrer" value="${request.current_route_url()}" />
<a @click="startBeingRoot()"
<a @click="$refs.startBeingRootForm.submit()"
class="navbar-item has-background-danger has-text-white">
Become root
</a>
@ -1103,18 +1103,6 @@
const key = 'menu_' + hash + '_shown'
this[key] = !this[key]
},
% if request.is_admin:
startBeingRoot() {
this.$refs.startBeingRootForm.submit()
},
stopBeingRoot() {
this.$refs.stopBeingRootForm.submit()
},
% endif
},
}

View file

@ -7,6 +7,7 @@
<%def name="base_styles()">
${parent.base_styles()}
${h.stylesheet_link(request.static_url('tailbone:static/css/diffs.css') + '?ver={}'.format(tailbone.__version__))}
<style>
.filters .filter-fieldname .field,
@ -163,11 +164,88 @@
/>
</div>
% if request.has_perm('common.feedback'):
<feedback-form
action="${url('feedback')}"
:message="feedbackMessage">
</feedback-form>
${parent.render_feedback_button()}
</%def>
<%def name="render_crud_header_buttons()">
% if master:
% if master.viewing:
% if instance_editable and master.has_perm('edit'):
<wutta-button once
tag="a" href="${master.get_action_url('edit', instance)}"
icon-left="edit"
label="Edit This" />
% endif
% if getattr(master, 'cloneable', False) and not master.cloning and master.has_perm('clone'):
<wutta-button once
tag="a" href="${master.get_action_url('clone', instance)}"
icon-left="object-ungroup"
label="Clone This" />
% endif
% if instance_deletable and master.has_perm('delete'):
<wutta-button once type="is-danger"
tag="a" href="${master.get_action_url('delete', instance)}"
icon-left="trash"
label="Delete This" />
% endif
% elif master.editing:
% if master.has_perm('view'):
<wutta-button once
tag="a" href="${master.get_action_url('view', instance)}"
icon-left="eye"
label="View This" />
% endif
% if instance_deletable and master.has_perm('delete'):
<wutta-button once type="is-danger"
tag="a" href="${master.get_action_url('delete', instance)}"
icon-left="trash"
label="Delete This" />
% endif
% elif master.deleting:
% if master.has_perm('view'):
<wutta-button once
tag="a" href="${master.get_action_url('view', instance)}"
icon-left="eye"
label="View This" />
% endif
% if instance_editable and master.has_perm('edit'):
<wutta-button once
tag="a" href="${master.get_action_url('edit', instance)}"
icon-left="edit"
label="Edit This" />
% endif
% endif
% endif
</%def>
<%def name="render_prevnext_header_buttons()">
% if show_prev_next is not Undefined and show_prev_next:
% if prev_url:
<wutta-button once
tag="a" href="${prev_url}"
icon-left="arrow-left"
label="Older" />
% else:
<b-button tag="a" href="#"
disabled
icon-pack="fas"
icon-left="arrow-left">
Older
</b-button>
% endif
% if next_url:
<wutta-button once
tag="a" href="${next_url}"
icon-left="arrow-right"
label="Newer" />
% else:
<b-button tag="a" href="#"
disabled
icon-pack="fas"
icon-left="arrow-right">
Newer
</b-button>
% endif
% endif
</%def>
@ -179,174 +257,133 @@
/>
</%def>
<%def name="render_vue_templates()">
${parent.render_vue_templates()}
<%def name="render_vue_template_feedback()">
<script type="text/x-template" id="feedback-template">
<div>
${page_help.render_template()}
${page_help.declare_vars()}
<div class="level-item">
<b-button type="is-primary"
@click="showFeedback()"
icon-pack="fas"
icon-left="comment">
Feedback
</b-button>
</div>
% if request.has_perm('common.feedback'):
<script type="text/x-template" id="feedback-template">
<div>
<b-modal has-modal-card
:active.sync="showDialog">
<div class="modal-card">
<div class="level-item">
<b-button type="is-primary"
@click="showFeedback()"
icon-pack="fas"
icon-left="comment">
Feedback
</b-button>
</div>
<header class="modal-card-head">
<p class="modal-card-title">User Feedback</p>
</header>
<b-modal has-modal-card
:active.sync="showDialog">
<div class="modal-card">
<section class="modal-card-body">
<p class="block">
Questions, suggestions, comments, complaints, etc.
<span class="red">regarding this website</span> are
welcome and may be submitted below.
</p>
<header class="modal-card-head">
<p class="modal-card-title">User Feedback</p>
</header>
<b-field label="User Name">
<b-input v-model="userName"
% if request.user:
disabled
% endif
>
</b-input>
</b-field>
<section class="modal-card-body">
<p class="block">
Questions, suggestions, comments, complaints, etc.
<span class="red">regarding this website</span> are
welcome and may be submitted below.
</p>
<b-field label="Referring URL">
<b-input
v-model="referrer"
disabled="true">
</b-input>
</b-field>
<b-field label="User Name">
<b-input v-model="userName"
% if request.user:
disabled
% endif
>
</b-input>
</b-field>
<b-field label="Message">
<b-input type="textarea"
v-model="message"
ref="textarea">
</b-input>
</b-field>
<b-field label="Referring URL">
<b-input
v-model="referrer"
disabled="true">
</b-input>
</b-field>
<b-field label="Message">
<b-input type="textarea"
v-model="message"
ref="textarea">
</b-input>
</b-field>
% if config.get_bool('tailbone.feedback_allows_reply'):
<div class="level">
<div class="level-left">
<div class="level-item">
<b-checkbox v-model="pleaseReply"
@input="pleaseReplyChanged">
Please email me back{{ pleaseReply ? " at: " : "" }}
</b-checkbox>
</div>
<div class="level-item" v-show="pleaseReply">
<b-input v-model="userEmail"
ref="userEmail">
</b-input>
</div>
</div>
% if config.get_bool('tailbone.feedback_allows_reply'):
<div class="level">
<div class="level-left">
<div class="level-item">
<b-checkbox v-model="pleaseReply"
@input="pleaseReplyChanged">
Please email me back{{ pleaseReply ? " at: " : "" }}
</b-checkbox>
</div>
% endif
<div class="level-item" v-show="pleaseReply">
<b-input v-model="userEmail"
ref="userEmail">
</b-input>
</div>
</div>
</div>
% endif
</section>
<footer class="modal-card-foot">
<b-button @click="showDialog = false">
Cancel
</b-button>
<b-button type="is-primary"
icon-pack="fas"
icon-left="paper-plane"
@click="sendFeedback()"
:disabled="sendingFeedback || !message.trim()">
{{ sendingFeedback ? "Working, please wait..." : "Send Message" }}
</b-button>
</footer>
</div>
</b-modal>
</section>
<footer class="modal-card-foot">
<b-button @click="showDialog = false">
Cancel
</b-button>
<b-button type="is-primary"
icon-pack="fas"
icon-left="paper-plane"
@click="sendFeedback()"
:disabled="sendingFeedback || !message || !message.trim()">
{{ sendingFeedback ? "Working, please wait..." : "Send Message" }}
</b-button>
</footer>
</div>
</script>
<script>
</b-modal>
const FeedbackForm = {
template: '#feedback-template',
mixins: [SimpleRequestMixin],
props: [
'action',
'message',
],
methods: {
</div>
</script>
</%def>
showFeedback() {
this.referrer = location.href
this.showDialog = true
this.$nextTick(function() {
this.$refs.textarea.focus()
})
},
<%def name="render_vue_script_feedback()">
${parent.render_vue_script_feedback()}
<script>
% if config.get_bool('tailbone.feedback_allows_reply'):
pleaseReplyChanged(value) {
this.$nextTick(() => {
this.$refs.userEmail.focus()
})
},
% endif
WuttaFeedbackForm.template = '#feedback-template'
WuttaFeedbackForm.props.message = String
sendFeedback() {
this.sendingFeedback = true
% if config.get_bool('tailbone.feedback_allows_reply'):
const params = {
referrer: this.referrer,
user: this.userUUID,
user_name: this.userName,
% if config.get_bool('tailbone.feedback_allows_reply'):
please_reply_to: this.pleaseReply ? this.userEmail : null,
% endif
message: this.message.trim(),
}
WuttaFeedbackFormData.pleaseReply = false
WuttaFeedbackFormData.userEmail = null
this.simplePOST(this.action, params, response => {
WuttaFeedbackForm.methods.pleaseReplyChanged = function(value) {
this.$nextTick(() => {
this.$refs.userEmail.focus()
})
}
this.$buefy.toast.open({
message: "Message sent! Thank you for your feedback.",
type: 'is-info',
duration: 4000, // 4 seconds
})
this.showDialog = false
// clear out message, in case they need to send another
this.message = ""
this.sendingFeedback = false
}, response => { // failure
this.sendingFeedback = false
})
},
WuttaFeedbackForm.methods.getExtraParams = function() {
return {
please_reply_to: this.pleaseReply ? this.userEmail : null,
}
}
const FeedbackFormData = {
referrer: null,
userUUID: null,
userName: null,
userEmail: null,
% if config.get_bool('tailbone.feedback_allows_reply'):
pleaseReply: false,
% endif
showDialog: false,
sendingFeedback: false,
}
% endif
</script>
% endif
// TODO: deprecate / remove these
const FeedbackForm = WuttaFeedbackForm
const FeedbackFormData = WuttaFeedbackFormData
</script>
</%def>
<%def name="render_vue_templates()">
${parent.render_vue_templates()}
${page_help.render_template()}
${page_help.declare_vars()}
</%def>
<%def name="modify_vue_vars()">
@ -445,21 +482,6 @@
% endif
##############################
## feedback
##############################
% if request.has_perm('common.feedback'):
WholePageData.feedbackMessage = ""
% if request.user:
FeedbackFormData.userUUID = ${json.dumps(request.user.uuid)|n}
FeedbackFormData.userName = ${json.dumps(str(request.user))|n}
% endif
% endif
##############################
## edit fields help
##############################
@ -479,10 +501,4 @@
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.timepicker.js') + f'?ver={tailbone.__version__}')}
${make_grid_filter_components()}
${page_help.make_component()}
% if request.has_perm('common.feedback'):
<script>
FeedbackForm.data = function() { return FeedbackFormData }
Vue.component('feedback-form', FeedbackForm)
</script>
% endif
</%def>

View file

@ -1,2 +1,10 @@
## -*- coding: utf-8; -*-
<%inherit file="wuttaweb:templates/form.mako" />
<%def name="render_vue_template_form()">
% if form is not Undefined:
${form.render_vue_template(buttons=capture(self.render_form_buttons))}
% endif
</%def>
<%def name="render_form_buttons()"></%def>

View file

@ -24,8 +24,6 @@
Auth Views
"""
from rattail.db.auth import set_user_password
import colander
from deform import widget as dfwidget
from pyramid.httpexceptions import HTTPForbidden
@ -46,28 +44,6 @@ class UserLogin(colander.MappingSchema):
widget=dfwidget.PasswordWidget())
@colander.deferred
def current_password_correct(node, kw):
request = kw['request']
app = request.rattail_config.get_app()
auth = app.get_auth_handler()
user = kw['user']
def validate(node, value):
if not auth.authenticate_user(Session(), user.username, value):
raise colander.Invalid(node, "The password is incorrect")
return validate
class ChangePassword(colander.MappingSchema):
current_password = colander.SchemaNode(colander.String(),
widget=dfwidget.PasswordWidget(),
validator=current_password_correct)
new_password = colander.SchemaNode(colander.String(),
widget=dfwidget.CheckedPasswordWidget())
class AuthenticationView(View):
def forbidden(self):
@ -104,6 +80,7 @@ class AuthenticationView(View):
form.save_label = "Login"
form.show_reset = True
form.show_cancel = False
form.button_icon_submit = 'user'
if form.validate():
user = self.authenticate_user(form.validated['username'],
form.validated['password'])
@ -117,10 +94,6 @@ class AuthenticationView(View):
else:
self.request.session.flash("Invalid username or password", 'error')
image_url = self.rattail_config.get(
'tailbone', 'main_image_url',
default=self.request.static_url('tailbone:static/img/home_logo.png'))
# nb. hacky..but necessary, to add the refs, for autofocus
# (also add key handler, so ENTER acts like TAB)
dform = form.make_deform_form()
@ -133,7 +106,6 @@ class AuthenticationView(View):
return {
'form': form,
'referrer': referrer,
'image_url': image_url,
'index_title': app.get_node_title(),
'help_url': global_help_url(self.rattail_config),
}
@ -182,10 +154,27 @@ class AuthenticationView(View):
self.request.user))
return self.redirect(self.request.get_referrer())
schema = ChangePassword().bind(user=self.request.user, request=self.request)
def check_user_password(node, value):
auth = self.app.get_auth_handler()
user = self.request.user
if not auth.check_user_password(user, value):
node.raise_invalid("The password is incorrect")
schema = colander.Schema()
schema.add(colander.SchemaNode(colander.String(),
name='current_password',
widget=dfwidget.PasswordWidget(),
validator=check_user_password))
schema.add(colander.SchemaNode(colander.String(),
name='new_password',
widget=dfwidget.CheckedPasswordWidget()))
form = forms.Form(schema=schema, request=self.request)
if form.validate():
set_user_password(self.request.user, form.validated['new_password'])
auth = self.app.get_auth_handler()
auth.set_user_password(self.request.user, form.validated['new_password'])
self.request.session.flash("Your password has been changed.")
return self.redirect(self.request.get_referrer())

View file

@ -46,10 +46,11 @@ import colander
from deform import widget as dfwidget
from webhelpers2.html import HTML, tags
from wuttaweb.util import render_csrf_token
from tailbone import forms, grids
from tailbone.db import Session
from tailbone.views import MasterView
from tailbone.util import csrf_token
log = logging.getLogger(__name__)
@ -383,7 +384,7 @@ class BatchMasterView(MasterView):
f.set_label('executed_by', "Executed by")
# notes
f.set_type('notes', 'text')
f.set_type('notes', 'text_wrapped')
# if self.creating and self.request.user:
# batch = fs.model
@ -441,7 +442,7 @@ class BatchMasterView(MasterView):
form = [
begin_form,
csrf_token(self.request),
render_csrf_token(self.request),
tags.hidden('complete', value=value),
submit,
tags.end_form(),
@ -861,7 +862,7 @@ class BatchMasterView(MasterView):
if not schema:
schema = colander.Schema()
kwargs['component'] = 'execute-form'
kwargs['vue_tagname'] = 'execute-form'
form = forms.Form(schema=schema, request=self.request, defaults=defaults, **kwargs)
self.configure_execute_form(form)
return form

View file

@ -202,10 +202,36 @@ class DataSyncThreadView(MasterView):
return self.redirect(self.request.get_referrer(
default=self.request.route_url('datasyncchanges')))
def configure_get_context(self):
def configure_get_simple_settings(self):
""" """
return [
# basic
{'section': 'rattail.datasync',
'option': 'use_profile_settings',
'type': bool},
# misc.
{'section': 'rattail.datasync',
'option': 'supervisor_process_name'},
{'section': 'rattail.datasync',
'option': 'batch_size_limit',
'type': int},
# legacy
{'section': 'tailbone',
'option': 'datasync.restart'},
]
def configure_get_context(self, **kwargs):
""" """
context = super().configure_get_context(**kwargs)
profiles = self.datasync_handler.get_configured_profiles(
include_disabled=True,
ignore_problems=True)
context['profiles'] = profiles
profiles_data = []
for profile in sorted(profiles.values(), key=lambda p: p.key):
@ -243,25 +269,15 @@ class DataSyncThreadView(MasterView):
data['consumers_data'] = consumers
profiles_data.append(data)
return {
'profiles': profiles,
'profiles_data': profiles_data,
'use_profile_settings': self.datasync_handler.should_use_profile_settings(),
'supervisor_process_name': self.rattail_config.get(
'rattail.datasync', 'supervisor_process_name'),
'restart_command': self.rattail_config.get(
'tailbone', 'datasync.restart'),
}
context['profiles_data'] = profiles_data
return context
def configure_gather_settings(self, data):
settings = []
watch = []
def configure_gather_settings(self, data, **kwargs):
""" """
settings = super().configure_gather_settings(data, **kwargs)
use_profile_settings = data.get('use_profile_settings') == 'true'
settings.append({'name': 'rattail.datasync.use_profile_settings',
'value': 'true' if use_profile_settings else 'false'})
if use_profile_settings:
if data.get('rattail.datasync.use_profile_settings') == 'true':
watch = []
for profile in json.loads(data['profiles']):
pkey = profile['key']
@ -323,17 +339,12 @@ class DataSyncThreadView(MasterView):
settings.append({'name': 'rattail.datasync.watch',
'value': ', '.join(watch)})
if data['supervisor_process_name']:
settings.append({'name': 'rattail.datasync.supervisor_process_name',
'value': data['supervisor_process_name']})
if data['restart_command']:
settings.append({'name': 'tailbone.datasync.restart',
'value': data['restart_command']})
return settings
def configure_remove_settings(self):
def configure_remove_settings(self, **kwargs):
""" """
super().configure_remove_settings(**kwargs)
purge_datasync_settings(self.rattail_config, self.Session())
@classmethod

View file

@ -412,7 +412,7 @@ class MasterView(View):
session = self.Session()
kwargs.setdefault('paginated', False)
grid = self.make_grid(session=session, **kwargs)
return grid.make_visible_data()
return grid.get_visible_data()
def get_grid_columns(self):
"""
@ -551,7 +551,8 @@ class MasterView(View):
def get_quickie_result_url(self, obj):
return self.get_action_url('view', obj)
def make_row_grid(self, factory=None, key=None, data=None, columns=None, **kwargs):
def make_row_grid(self, factory=None, key=None, data=None, columns=None,
session=None, **kwargs):
"""
Make and return a new (configured) rows grid instance.
"""
@ -612,7 +613,9 @@ class MasterView(View):
# delete action
if self.rows_deletable and self.has_perm('delete_row'):
actions.append(self.make_action('delete', icon='trash', url=self.row_delete_action_url))
actions.append(self.make_action('delete', icon='trash',
url=self.row_delete_action_url,
link_class='has-text-danger'))
defaults['delete_speedbump'] = self.rows_deletable_speedbump
defaults['actions'] = actions
@ -900,7 +903,7 @@ class MasterView(View):
def valid_employee_uuid(self, node, value):
if value:
model = self.model
model = self.app.model
employee = self.Session.get(model.Employee, value)
if not employee:
node.raise_invalid("Employee not found")
@ -936,7 +939,7 @@ class MasterView(View):
def valid_vendor_uuid(self, node, value):
if value:
model = self.model
model = self.app.model
vendor = self.Session.get(model.Vendor, value)
if not vendor:
node.raise_invalid("Vendor not found")
@ -1379,7 +1382,7 @@ class MasterView(View):
return classes
def make_revisions_grid(self, obj, empty_data=False):
model = self.model
model = self.app.model
route_prefix = self.get_route_prefix()
row_url = lambda txn, i: self.request.route_url(f'{route_prefix}.version',
uuid=obj.uuid,
@ -1707,7 +1710,7 @@ class MasterView(View):
kwargs.setdefault('paginated', False)
kwargs.setdefault('sortable', sort)
grid = self.make_row_grid(session=session, **kwargs)
return grid.make_visible_data()
return grid.get_visible_data()
@classmethod
def get_row_url_prefix(cls):
@ -2150,7 +2153,7 @@ class MasterView(View):
Thread target for executing an object.
"""
app = self.get_rattail_app()
model = self.model
model = self.app.model
session = app.make_session()
obj = self.get_instance_for_key(key, session)
user = session.get(model.User, user_uuid)
@ -2591,7 +2594,7 @@ class MasterView(View):
"""
# nb. self.Session may differ, so use tailbone.db.Session
session = Session()
model = self.model
model = self.app.model
route_prefix = self.get_route_prefix()
info = session.query(model.TailbonePageHelp)\
@ -2614,7 +2617,7 @@ class MasterView(View):
"""
# nb. self.Session may differ, so use tailbone.db.Session
session = Session()
model = self.model
model = self.app.model
route_prefix = self.get_route_prefix()
info = session.query(model.TailbonePageHelp)\
@ -2636,7 +2639,7 @@ class MasterView(View):
# nb. self.Session may differ, so use tailbone.db.Session
session = Session()
model = self.model
model = self.app.model
route_prefix = self.get_route_prefix()
schema = colander.Schema()
@ -2670,7 +2673,7 @@ class MasterView(View):
# nb. self.Session may differ, so use tailbone.db.Session
session = Session()
model = self.model
model = self.app.model
route_prefix = self.get_route_prefix()
schema = colander.Schema()
@ -3322,7 +3325,7 @@ class MasterView(View):
url=self.default_clone_url)
def make_grid_action_delete(self):
kwargs = {}
kwargs = {'link_class': 'has-text-danger'}
if self.delete_confirm == 'simple':
kwargs['click_handler'] = 'deleteObject'
return self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs)
@ -5439,7 +5442,7 @@ class MasterView(View):
for template in self.normalize_input_file_templates(
include_file_options=True):
settings[template['setting_mode']] = template['mode']
settings[template['setting_file']] = template['file']
settings[template['setting_file']] = template['file'] or ''
settings[template['setting_url']] = template['url']
file_options[template['key']] = template['file_options']
file_option_dirs[template['key']] = template['file_options_dir']
@ -5455,7 +5458,7 @@ class MasterView(View):
for template in self.normalize_output_file_templates(
include_file_options=True):
settings[template['setting_mode']] = template['mode']
settings[template['setting_file']] = template['file']
settings[template['setting_file']] = template['file'] or ''
settings[template['setting_url']] = template['url']
file_options[template['key']] = template['file_options']
file_option_dirs[template['key']] = template['file_options_dir']
@ -5538,7 +5541,7 @@ class MasterView(View):
input_file_templates=True,
output_file_templates=True):
app = self.get_rattail_app()
model = self.model
model = self.app.model
names = []
if simple_settings is None:
@ -6097,7 +6100,7 @@ class MasterView(View):
renderer='json')
class ViewSupplement(object):
class ViewSupplement:
"""
Base class for view "supplements" - which are sort of like plugins
which can "supplement" certain aspects of the view.
@ -6124,6 +6127,7 @@ class ViewSupplement(object):
def __init__(self, master):
self.master = master
self.request = master.request
self.app = master.app
self.model = master.model
self.rattail_config = master.rattail_config
self.Session = master.Session
@ -6157,7 +6161,7 @@ class ViewSupplement(object):
This is accomplished by subjecting the current base query to a
join, e.g. something like::
model = self.model
model = self.app.model
query = query.outerjoin(model.MyExtension)
return query
"""

View file

@ -564,15 +564,19 @@ class PersonView(MasterView):
Method which must return the base query for the profile's POS
Transactions grid data.
"""
app = self.get_rattail_app()
customer = app.get_customer(person)
customer = self.app.get_customer(person)
key_field = app.get_customer_key_field()
customer_key = getattr(customer, key_field)
if customer_key is not None:
customer_key = str(customer_key)
if customer:
key_field = self.app.get_customer_key_field()
customer_key = getattr(customer, key_field)
if customer_key is not None:
customer_key = str(customer_key)
else:
# nb. this should *not* match anything, so query returns
# no results..
customer_key = person.uuid
trainwreck = app.get_trainwreck_handler()
trainwreck = self.app.get_trainwreck_handler()
model = trainwreck.get_model()
query = TrainwreckSession.query(model.Transaction)\
.filter(model.Transaction.customer_id == customer_key)
@ -1382,8 +1386,8 @@ class PersonView(MasterView):
}
if not context['users']:
context['suggested_username'] = auth.generate_unique_username(self.Session(),
person=person)
context['suggested_username'] = auth.make_unique_username(self.Session(),
person=person)
return context

View file

@ -34,7 +34,7 @@ import sqlalchemy_continuum as continuum
from rattail import enum, pod, sil
from rattail.db import api, auth, Session as RattailSession
from rattail.db.model import Product, PendingProduct, CustomerOrderItem
from rattail.db.model import Product, PendingProduct, ProductCost, CustomerOrderItem
from rattail.gpc import GPC
from rattail.threads import Thread
from rattail.exceptions import LabelPrintingError
@ -1857,7 +1857,8 @@ class ProductView(MasterView):
lookup_fields.append('alt_code')
if lookup_fields:
product = self.products_handler.locate_product_for_entry(
session, term, lookup_fields=lookup_fields)
session, term, lookup_fields=lookup_fields,
first_if_multiple=True)
if product:
final_results.append(self.search_normalize_result(product))
@ -2668,6 +2669,78 @@ class PendingProductView(MasterView):
permission=f'{permission_prefix}.ignore_product')
class ProductCostView(MasterView):
"""
Master view for Product Costs
"""
model_class = ProductCost
route_prefix = 'product_costs'
url_prefix = '/products/costs'
has_versions = True
grid_columns = [
'_product_key_',
'vendor',
'preference',
'code',
'case_size',
'case_cost',
'pack_size',
'pack_cost',
'unit_cost',
]
def query(self, session):
""" """
query = super().query(session)
model = self.app.model
# always join on Product
return query.join(model.Product)
def configure_grid(self, g):
""" """
super().configure_grid(g)
model = self.app.model
# product key
field = self.get_product_key_field()
g.set_renderer(field, self.render_product_key)
g.set_sorter(field, getattr(model.Product, field))
g.set_sort_defaults(field)
g.set_filter(field, getattr(model.Product, field))
# vendor
g.set_joiner('vendor', lambda q: q.join(model.Vendor))
g.set_sorter('vendor', model.Vendor.name)
g.set_filter('vendor', model.Vendor.name, label="Vendor Name")
def render_product_key(self, cost, field):
""" """
handler = self.app.get_products_handler()
return handler.render_product_key(cost.product)
def configure_form(self, f):
""" """
super().configure_form(f)
# product
f.set_renderer('product', self.render_product)
if 'product_uuid' in f and 'product' in f:
f.remove('product')
f.replace('product_uuid', 'product')
# vendor
f.set_renderer('vendor', self.render_vendor)
if 'vendor_uuid' in f and 'vendor' in f:
f.remove('vendor')
f.replace('vendor_uuid', 'vendor')
# futures
# TODO: should eventually show a subgrid here?
f.remove('futures')
def defaults(config, **kwargs):
base = globals()
@ -2677,6 +2750,9 @@ def defaults(config, **kwargs):
PendingProductView = kwargs.get('PendingProductView', base['PendingProductView'])
PendingProductView.defaults(config)
ProductCostView = kwargs.get('ProductCostView', base['ProductCostView'])
ProductCostView.defaults(config)
def includeme(config):
defaults(config)

View file

@ -24,6 +24,8 @@
Base class for purchasing batch views
"""
import warnings
from rattail.db.model import PurchaseBatch, PurchaseBatchRow
import colander
@ -67,6 +69,8 @@ class PurchasingBatchView(BatchMasterView):
'store',
'buyer',
'vendor',
'description',
'workflow',
'department',
'purchase',
'vendor_email',
@ -158,6 +162,174 @@ class PurchasingBatchView(BatchMasterView):
def batch_mode(self):
raise NotImplementedError("Please define `batch_mode` for your purchasing batch view")
def get_supported_workflows(self):
"""
Return the supported "create batch" workflows.
"""
enum = self.app.enum
if self.batch_mode == enum.PURCHASE_BATCH_MODE_ORDERING:
return self.batch_handler.supported_ordering_workflows()
elif self.batch_mode == enum.PURCHASE_BATCH_MODE_RECEIVING:
return self.batch_handler.supported_receiving_workflows()
elif self.batch_mode == enum.PURCHASE_BATCH_MODE_COSTING:
return self.batch_handler.supported_costing_workflows()
raise ValueError("unknown batch mode")
def allow_any_vendor(self):
"""
Return boolean indicating whether creating a batch for "any"
vendor is allowed, vs. only supported vendors.
"""
enum = self.app.enum
if self.batch_mode == enum.PURCHASE_BATCH_MODE_ORDERING:
return self.batch_handler.allow_ordering_any_vendor()
elif self.batch_mode == enum.PURCHASE_BATCH_MODE_RECEIVING:
value = self.config.get_bool('rattail.batch.purchase.allow_receiving_any_vendor')
if value is not None:
return value
value = self.config.get_bool('rattail.batch.purchase.supported_vendors_only')
if value is not None:
warnings.warn("setting rattail.batch.purchase.supported_vendors_only is deprecated; "
"please use rattail.batch.purchase.allow_receiving_any_vendor instead",
DeprecationWarning)
# nb. must negate this setting
return not value
return False
raise ValueError("unknown batch mode")
def get_supported_vendors(self):
"""
Return the supported vendors for creating a batch.
"""
return []
def create(self, form=None, **kwargs):
"""
Custom view for creating a new batch. We split the process
into two steps, 1) choose workflow and 2) create batch. This
is because the specific form details for creating a batch will
depend on which "type" of batch creation is to be done, and
it's much easier to keep conditional logic for that in the
server instead of client-side etc.
"""
model = self.app.model
enum = self.app.enum
route_prefix = self.get_route_prefix()
workflows = self.get_supported_workflows()
valid_workflows = [workflow['workflow_key']
for workflow in workflows]
# if user has already identified their desired workflow, then
# we can just farm out to the default logic. we will of
# course configure our form differently, based on workflow,
# but this create() method at least will not need
# customization for that.
if self.request.matched_route.name.endswith('create_workflow'):
redirect = self.redirect(self.request.route_url(f'{route_prefix}.create'))
# however we do have one more thing to check - the workflow
# requested must of course be valid!
workflow_key = self.request.matchdict['workflow_key']
if workflow_key not in valid_workflows:
self.request.session.flash(f"Not a supported workflow: {workflow_key}", 'error')
raise redirect
# also, we require vendor to be correctly identified. if
# someone e.g. navigates to a URL by accident etc. we want
# to gracefully handle and redirect
uuid = self.request.matchdict['vendor_uuid']
vendor = self.Session.get(model.Vendor, uuid)
if not vendor:
self.request.session.flash("Invalid vendor selection. "
"Please choose an existing vendor.",
'warning')
raise redirect
# okay now do the normal thing, per workflow
return super().create(**kwargs)
# on the other hand, if caller provided a form, that means we are in
# the middle of some other custom workflow, e.g. "add child to truck
# dump parent" or some such. in which case we also defer to the normal
# logic, so as to not interfere with that.
if form:
return super().create(form=form, **kwargs)
# okay, at this point we need the user to select a vendor and workflow
self.creating = True
context = {}
# form to accept user choice of vendor/workflow
schema = colander.Schema()
schema.add(colander.SchemaNode(colander.String(), name='vendor'))
schema.add(colander.SchemaNode(colander.String(), name='workflow',
validator=colander.OneOf(valid_workflows)))
factory = self.get_form_factory()
form = factory(schema=schema, request=self.request)
# configure vendor field
vendor_handler = self.app.get_vendor_handler()
if self.allow_any_vendor():
# user may choose *any* available vendor
use_dropdown = vendor_handler.choice_uses_dropdown()
if use_dropdown:
vendors = self.Session.query(model.Vendor)\
.order_by(model.Vendor.id)\
.all()
vendor_values = [(vendor.uuid, f"({vendor.id}) {vendor.name}")
for vendor in vendors]
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
if len(vendors) == 1:
form.set_default('vendor', vendors[0].uuid)
else:
vendor_display = ""
if self.request.method == 'POST':
if self.request.POST.get('vendor'):
vendor = self.Session.get(model.Vendor, self.request.POST['vendor'])
if vendor:
vendor_display = str(vendor)
vendors_url = self.request.route_url('vendors.autocomplete')
form.set_widget('vendor', forms.widgets.JQueryAutocompleteWidget(
field_display=vendor_display, service_url=vendors_url))
else: # only "supported" vendors allowed
vendors = self.get_supported_vendors()
vendor_values = [(vendor.uuid, vendor_handler.render_vendor(vendor))
for vendor in vendors]
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
form.set_validator('vendor', self.valid_vendor_uuid)
# configure workflow field
values = [(workflow['workflow_key'], workflow['display'])
for workflow in workflows]
form.set_widget('workflow',
dfwidget.SelectWidget(values=values))
if len(workflows) == 1:
form.set_default('workflow', workflows[0]['workflow_key'])
form.submit_label = "Continue"
form.cancel_url = self.get_index_url()
# if form validates, that means user has chosen a creation
# type, so we just redirect to the appropriate "new batch of
# type X" page
if form.validate():
workflow_key = form.validated['workflow']
vendor_uuid = form.validated['vendor']
url = self.request.route_url(f'{route_prefix}.create_workflow',
workflow_key=workflow_key,
vendor_uuid=vendor_uuid)
raise self.redirect(url)
context['form'] = form
if hasattr(form, 'make_deform_form'):
context['dform'] = form.make_deform_form()
return self.render_to_response('create', context)
def query(self, session):
model = self.model
return session.query(model.PurchaseBatch)\
@ -226,20 +398,40 @@ class PurchasingBatchView(BatchMasterView):
def configure_form(self, f):
super().configure_form(f)
model = self.model
model = self.app.model
enum = self.app.enum
route_prefix = self.get_route_prefix()
today = self.app.today()
batch = f.model_instance
app = self.get_rattail_app()
today = app.localtime().date()
workflow = self.request.matchdict.get('workflow_key')
vendor_handler = self.app.get_vendor_handler()
# mode
f.set_enum('mode', self.enum.PURCHASE_BATCH_MODE)
f.set_enum('mode', enum.PURCHASE_BATCH_MODE)
# workflow
if self.creating:
if workflow:
f.set_widget('workflow', dfwidget.HiddenWidget())
f.set_default('workflow', workflow)
f.set_hidden('workflow')
# nb. show readonly '_workflow'
f.insert_after('workflow', '_workflow')
f.set_readonly('_workflow')
f.set_renderer('_workflow', self.render_workflow)
else:
f.set_readonly('workflow')
f.set_renderer('workflow', self.render_workflow)
else:
f.remove('workflow')
# store
single_store = self.rattail_config.single_store()
single_store = self.config.single_store()
if self.creating:
f.replace('store', 'store_uuid')
if single_store:
store = self.rattail_config.get_store(self.Session())
store = self.config.get_store(self.Session())
f.set_widget('store_uuid', dfwidget.HiddenWidget())
f.set_default('store_uuid', store.uuid)
f.set_hidden('store_uuid')
@ -263,7 +455,6 @@ class PurchasingBatchView(BatchMasterView):
if self.creating:
f.replace('vendor', 'vendor_uuid')
f.set_label('vendor_uuid', "Vendor")
vendor_handler = app.get_vendor_handler()
use_dropdown = vendor_handler.choice_uses_dropdown()
if use_dropdown:
vendors = self.Session.query(model.Vendor)\
@ -313,7 +504,7 @@ class PurchasingBatchView(BatchMasterView):
if buyer:
buyer_display = str(buyer)
elif self.creating:
buyer = app.get_employee(self.request.user)
buyer = self.app.get_employee(self.request.user)
if buyer:
buyer_display = str(buyer)
f.set_default('buyer_uuid', buyer.uuid)
@ -324,6 +515,30 @@ class PurchasingBatchView(BatchMasterView):
field_display=buyer_display, service_url=buyers_url))
f.set_label('buyer_uuid', "Buyer")
# order_file
if self.creating:
f.set_type('order_file', 'file', required=False)
else:
f.set_readonly('order_file')
f.set_renderer('order_file', self.render_downloadable_file)
# order_parser_key
if self.creating:
kwargs = {}
if 'vendor_uuid' in self.request.matchdict:
vendor = self.Session.get(model.Vendor,
self.request.matchdict['vendor_uuid'])
if vendor:
kwargs['vendor'] = vendor
parsers = vendor_handler.get_supported_order_parsers(**kwargs)
parser_values = [(p.key, p.title) for p in parsers]
if len(parsers) == 1:
f.set_default('order_parser_key', parsers[0].key)
f.set_widget('order_parser_key', dfwidget.SelectWidget(values=parser_values))
f.set_label('order_parser_key', "Order Parser")
else:
f.remove_field('order_parser_key')
# invoice_file
if self.creating:
f.set_type('invoice_file', 'file', required=False)
@ -341,7 +556,7 @@ class PurchasingBatchView(BatchMasterView):
if vendor:
kwargs['vendor'] = vendor
parsers = self.handler.get_supported_invoice_parsers(**kwargs)
parsers = self.batch_handler.get_supported_invoice_parsers(**kwargs)
parser_values = [(p.key, p.display) for p in parsers]
if len(parsers) == 1:
f.set_default('invoice_parser_key', parsers[0].key)
@ -400,6 +615,35 @@ class PurchasingBatchView(BatchMasterView):
'vendor_contact',
'status_code')
# tweak some things if we are in "step 2" of creating new batch
if self.creating and workflow:
# display vendor but do not allow changing
vendor = self.Session.get(model.Vendor, self.request.matchdict['vendor_uuid'])
if not vendor:
raise ValueError(f"vendor not found: {self.request.matchdict['vendor_uuid']}")
f.set_readonly('vendor_uuid')
f.set_default('vendor_uuid', str(vendor))
# cancel should take us back to choosing a workflow
f.cancel_url = self.request.route_url(f'{route_prefix}.create')
def render_workflow(self, batch, field):
key = self.request.matchdict['workflow_key']
info = self.get_workflow_info(key)
if info:
return info['display']
def get_workflow_info(self, key):
enum = self.app.enum
if self.batch_mode == enum.PURCHASE_BATCH_MODE_ORDERING:
return self.batch_handler.ordering_workflow_info(key)
elif self.batch_mode == enum.PURCHASE_BATCH_MODE_RECEIVING:
return self.batch_handler.receiving_workflow_info(key)
elif self.batch_mode == enum.PURCHASE_BATCH_MODE_COSTING:
return self.batch_handler.costing_workflow_info(key)
raise ValueError("unknown batch mode")
def render_store(self, batch, field):
store = batch.store
if not store:
@ -515,10 +759,12 @@ class PurchasingBatchView(BatchMasterView):
def get_batch_kwargs(self, batch, **kwargs):
kwargs = super().get_batch_kwargs(batch, **kwargs)
model = self.model
model = self.app.model
kwargs['mode'] = self.batch_mode
kwargs['workflow'] = self.request.POST['workflow']
kwargs['truck_dump'] = batch.truck_dump
kwargs['order_parser_key'] = batch.order_parser_key
kwargs['invoice_parser_key'] = batch.invoice_parser_key
if batch.store:
@ -536,6 +782,11 @@ class PurchasingBatchView(BatchMasterView):
elif batch.vendor_uuid:
kwargs['vendor_uuid'] = batch.vendor_uuid
# must pull vendor from URL if it was not in form data
if 'vendor_uuid' not in kwargs and 'vendor' not in kwargs:
if 'vendor_uuid' in self.request.matchdict:
kwargs['vendor_uuid'] = self.request.matchdict['vendor_uuid']
if batch.department:
kwargs['department'] = batch.department
elif batch.department_uuid:
@ -919,6 +1170,25 @@ class PurchasingBatchView(BatchMasterView):
# # otherwise just view batch again
# return self.get_action_url('view', batch)
@classmethod
def defaults(cls, config):
cls._purchase_batch_defaults(config)
cls._batch_defaults(config)
cls._defaults(config)
@classmethod
def _purchase_batch_defaults(cls, config):
route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix()
permission_prefix = cls.get_permission_prefix()
# new batch using workflow X
config.add_route(f'{route_prefix}.create_workflow',
f'{url_prefix}/new/{{workflow_key}}/{{vendor_uuid}}')
config.add_view(cls, attr='create',
route_name=f'{route_prefix}.create_workflow',
permission=f'{permission_prefix}.create')
class NewProduct(colander.Schema):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,14 +28,10 @@ import os
import json
import openpyxl
from sqlalchemy import orm
from rattail.db import model, api
from rattail.core import Object
from rattail.time import localtime
from webhelpers2.html import tags
from tailbone.db import Session
from tailbone.views.purchasing import PurchasingBatchView
@ -51,6 +47,8 @@ class OrderingBatchView(PurchasingBatchView):
rows_editable = True
has_worksheet = True
default_help_url = 'https://rattailproject.org/docs/rattail-manual/features/purchasing/ordering/index.html'
downloadable = True
configurable = True
labels = {
'po_total_calculated': "PO Total",
@ -59,9 +57,14 @@ class OrderingBatchView(PurchasingBatchView):
form_fields = [
'id',
'store',
'buyer',
'vendor',
'description',
'workflow',
'order_file',
'order_parser_key',
'buyer',
'department',
'params',
'purchase',
'vendor_email',
'vendor_fax',
@ -132,15 +135,26 @@ class OrderingBatchView(PurchasingBatchView):
return self.enum.PURCHASE_BATCH_MODE_ORDERING
def configure_form(self, f):
super(OrderingBatchView, self).configure_form(f)
super().configure_form(f)
batch = f.model_instance
workflow = self.request.matchdict.get('workflow_key')
# purchase
if self.creating or not batch.executed or not batch.purchase:
f.remove_field('purchase')
# now that all fields are setup, some final tweaks based on workflow
if self.creating and workflow:
if workflow == 'from_scratch':
f.remove('order_file',
'order_parser_key')
elif workflow == 'from_file':
f.set_required('order_file')
def get_batch_kwargs(self, batch, **kwargs):
kwargs = super(OrderingBatchView, self).get_batch_kwargs(batch, **kwargs)
kwargs = super().get_batch_kwargs(batch, **kwargs)
kwargs['ship_method'] = batch.ship_method
kwargs['notes_to_vendor'] = batch.notes_to_vendor
return kwargs
@ -155,7 +169,7 @@ class OrderingBatchView(PurchasingBatchView):
* ``cases_ordered``
* ``units_ordered``
"""
super(OrderingBatchView, self).configure_row_form(f)
super().configure_row_form(f)
# when editing, only certain fields should allow changes
if self.editing:
@ -308,7 +322,7 @@ class OrderingBatchView(PurchasingBatchView):
title = self.get_instance_title(batch)
order_date = batch.date_ordered
if not order_date:
order_date = localtime(self.rattail_config).date()
order_date = self.app.today()
return self.render_to_response('worksheet', {
'batch': batch,
@ -369,6 +383,7 @@ class OrderingBatchView(PurchasingBatchView):
of being updated. If a matching row is not found, it will not be
created.
"""
model = self.app.model
batch = self.get_instance()
try:
@ -478,13 +493,75 @@ class OrderingBatchView(PurchasingBatchView):
return self.file_response(path)
def get_execute_success_url(self, batch, result, **kwargs):
model = self.app.model
if isinstance(result, model.Purchase):
return self.request.route_url('purchases.view', uuid=result.uuid)
return super(OrderingBatchView, self).get_execute_success_url(batch, result, **kwargs)
return super().get_execute_success_url(batch, result, **kwargs)
def configure_get_simple_settings(self):
return [
# workflows
{'section': 'rattail.batch',
'option': 'purchase.allow_ordering_from_scratch',
'type': bool,
'default': True},
{'section': 'rattail.batch',
'option': 'purchase.allow_ordering_from_file',
'type': bool,
'default': True},
# vendors
{'section': 'rattail.batch',
'option': 'purchase.allow_ordering_any_vendor',
'type': bool,
'default': True,
},
]
def configure_get_context(self):
context = super().configure_get_context()
vendor_handler = self.app.get_vendor_handler()
Parsers = vendor_handler.get_all_order_parsers()
Supported = vendor_handler.get_supported_order_parsers()
context['order_parsers'] = Parsers
context['order_parsers_data'] = dict([(Parser.key, Parser in Supported)
for Parser in Parsers])
return context
def configure_gather_settings(self, data):
settings = super().configure_gather_settings(data)
vendor_handler = self.app.get_vendor_handler()
supported = []
for Parser in vendor_handler.get_all_order_parsers():
name = f'order_parser_{Parser.key}'
if data.get(name) == 'true':
supported.append(Parser.key)
settings.append({'name': 'rattail.vendors.supported_order_parsers',
'value': ', '.join(supported)})
return settings
def configure_remove_settings(self):
super().configure_remove_settings()
names = [
'rattail.vendors.supported_order_parsers',
]
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for name in names:
self.app.delete_setting(session, name)
@classmethod
def defaults(cls, config):
cls._ordering_defaults(config)
cls._purchase_batch_defaults(config)
cls._batch_defaults(config)
cls._defaults(config)

View file

@ -108,7 +108,7 @@ class ReceivingBatchView(PurchasingBatchView):
'store',
'vendor',
'description',
'receiving_workflow',
'workflow',
'truck_dump',
'truck_dump_children_first',
'truck_dump_children',
@ -235,135 +235,18 @@ class ReceivingBatchView(PurchasingBatchView):
if not self.handler.allow_truck_dump_receiving():
g.remove('truck_dump')
def create(self, form=None, **kwargs):
"""
Custom view for creating a new receiving batch. We split the process
into two steps, 1) choose and 2) create. This is because the specific
form details for creating a batch will depend on which "type" of batch
creation is to be done, and it's much easier to keep conditional logic
for that in the server instead of client-side etc.
See also
:meth:`tailbone.views.purchasing.costing:CostingBatchView.create()`
which uses similar logic.
"""
model = self.model
route_prefix = self.get_route_prefix()
workflows = self.handler.supported_receiving_workflows()
valid_workflows = [workflow['workflow_key']
for workflow in workflows]
# if user has already identified their desired workflow, then we can
# just farm out to the default logic. we will of course configure our
# form differently, based on workflow, but this create() method at
# least will not need customization for that.
if self.request.matched_route.name.endswith('create_workflow'):
redirect = self.redirect(self.request.route_url('{}.create'.format(route_prefix)))
# however we do have one more thing to check - the workflow
# requested must of course be valid!
workflow_key = self.request.matchdict['workflow_key']
if workflow_key not in valid_workflows:
self.request.session.flash(
"Not a supported workflow: {}".format(workflow_key),
'error')
raise redirect
# also, we require vendor to be correctly identified. if
# someone e.g. navigates to a URL by accident etc. we want
# to gracefully handle and redirect
uuid = self.request.matchdict['vendor_uuid']
vendor = self.Session.get(model.Vendor, uuid)
if not vendor:
self.request.session.flash("Invalid vendor selection. "
"Please choose an existing vendor.",
'warning')
raise redirect
# okay now do the normal thing, per workflow
return super().create(**kwargs)
# on the other hand, if caller provided a form, that means we are in
# the middle of some other custom workflow, e.g. "add child to truck
# dump parent" or some such. in which case we also defer to the normal
# logic, so as to not interfere with that.
if form:
return super().create(form=form, **kwargs)
# okay, at this point we need the user to select a vendor and workflow
self.creating = True
context = {}
# form to accept user choice of vendor/workflow
schema = NewReceivingBatch().bind(valid_workflows=valid_workflows)
form = forms.Form(schema=schema, request=self.request)
# configure vendor field
app = self.get_rattail_app()
vendor_handler = app.get_vendor_handler()
if self.rattail_config.getbool('rattail.batch', 'purchase.supported_vendors_only'):
# only show vendors for which we have dedicated invoice parsers
vendors = {}
for parser in self.batch_handler.get_supported_invoice_parsers():
if parser.vendor_key:
vendor = vendor_handler.get_vendor(self.Session(),
parser.vendor_key)
if vendor:
vendors[vendor.uuid] = vendor
vendors = sorted(vendors.values(), key=lambda v: v.name)
vendor_values = [(vendor.uuid, vendor_handler.render_vendor(vendor))
for vendor in vendors]
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
else:
# user may choose *any* available vendor
use_dropdown = vendor_handler.choice_uses_dropdown()
if use_dropdown:
vendors = self.Session.query(model.Vendor)\
.order_by(model.Vendor.id)\
.all()
vendor_values = [(vendor.uuid, "({}) {}".format(vendor.id, vendor.name))
for vendor in vendors]
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
if len(vendors) == 1:
form.set_default('vendor', vendors[0].uuid)
else:
vendor_display = ""
if self.request.method == 'POST':
if self.request.POST.get('vendor'):
vendor = self.Session.get(model.Vendor, self.request.POST['vendor'])
if vendor:
vendor_display = str(vendor)
vendors_url = self.request.route_url('vendors.autocomplete')
form.set_widget('vendor', forms.widgets.JQueryAutocompleteWidget(
field_display=vendor_display, service_url=vendors_url))
form.set_validator('vendor', self.valid_vendor_uuid)
# configure workflow field
values = [(workflow['workflow_key'], workflow['display'])
for workflow in workflows]
form.set_widget('workflow',
dfwidget.SelectWidget(values=values))
if len(workflows) == 1:
form.set_default('workflow', workflows[0]['workflow_key'])
form.submit_label = "Continue"
form.cancel_url = self.get_index_url()
# if form validates, that means user has chosen a creation type, so we
# just redirect to the appropriate "new batch of type X" page
if form.validate():
workflow_key = form.validated['workflow']
vendor_uuid = form.validated['vendor']
url = self.request.route_url('{}.create_workflow'.format(route_prefix),
workflow_key=workflow_key,
vendor_uuid=vendor_uuid)
raise self.redirect(url)
context['form'] = form
if hasattr(form, 'make_deform_form'):
context['dform'] = form.make_deform_form()
return self.render_to_response('create', context)
def get_supported_vendors(self):
""" """
vendor_handler = self.app.get_vendor_handler()
vendors = {}
for parser in self.batch_handler.get_supported_invoice_parsers():
if parser.vendor_key:
vendor = vendor_handler.get_vendor(self.Session(),
parser.vendor_key)
if vendor:
vendors[vendor.uuid] = vendor
vendors = sorted(vendors.values(), key=lambda v: v.name)
return vendors
def row_deletable(self, row):
@ -404,13 +287,7 @@ class ReceivingBatchView(PurchasingBatchView):
# cancel should take us back to choosing a workflow
f.cancel_url = self.request.route_url('{}.create'.format(route_prefix))
# receiving_workflow
if self.creating and workflow:
f.set_readonly('receiving_workflow')
f.set_renderer('receiving_workflow', self.render_receiving_workflow)
else:
f.remove('receiving_workflow')
# TODO: remove this
# batch_type
if self.creating:
f.set_widget('batch_type', dfwidget.HiddenWidget())
@ -525,7 +402,7 @@ class ReceivingBatchView(PurchasingBatchView):
# multiple invoice files (if applicable)
if (not self.creating
and batch.get_param('receiving_workflow') == 'from_multi_invoice'):
and batch.get_param('workflow') == 'from_multi_invoice'):
if 'invoice_files' not in f:
f.insert_before('invoice_file', 'invoice_files')
@ -624,12 +501,6 @@ class ReceivingBatchView(PurchasingBatchView):
items.append(HTML.tag('li', c=[link]))
return HTML.tag('ul', c=items)
def render_receiving_workflow(self, batch, field):
key = self.request.matchdict['workflow_key']
info = self.handler.receiving_workflow_info(key)
if info:
return info['display']
def get_visible_params(self, batch):
params = super().get_visible_params(batch)
@ -654,42 +525,40 @@ class ReceivingBatchView(PurchasingBatchView):
def get_batch_kwargs(self, batch, **kwargs):
kwargs = super().get_batch_kwargs(batch, **kwargs)
batch_type = self.request.POST['batch_type']
# must pull vendor from URL if it was not in form data
if 'vendor_uuid' not in kwargs and 'vendor' not in kwargs:
if 'vendor_uuid' in self.request.matchdict:
kwargs['vendor_uuid'] = self.request.matchdict['vendor_uuid']
# TODO: ugh should just have workflow and no batch_type
kwargs['receiving_workflow'] = batch_type
if batch_type == 'from_scratch':
workflow = kwargs['workflow']
if workflow == 'from_scratch':
kwargs.pop('truck_dump_batch', None)
kwargs.pop('truck_dump_batch_uuid', None)
elif batch_type == 'from_invoice':
elif workflow == 'from_invoice':
pass
elif batch_type == 'from_multi_invoice':
elif workflow == 'from_multi_invoice':
pass
elif batch_type == 'from_po':
elif workflow == 'from_po':
# TODO: how to best handle this field? this doesn't seem flexible
kwargs['purchase_key'] = batch.purchase_uuid
elif batch_type == 'from_po_with_invoice':
elif workflow == 'from_po_with_invoice':
# TODO: how to best handle this field? this doesn't seem flexible
kwargs['purchase_key'] = batch.purchase_uuid
elif batch_type == 'truck_dump_children_first':
elif workflow == 'truck_dump_children_first':
kwargs['truck_dump'] = True
kwargs['truck_dump_children_first'] = True
kwargs['order_quantities_known'] = True
# TODO: this makes sense in some cases, but all?
# (should just omit that field when not relevant)
kwargs['date_ordered'] = None
elif batch_type == 'truck_dump_children_last':
elif workflow == 'truck_dump_children_last':
kwargs['truck_dump'] = True
kwargs['truck_dump_ready'] = True
# TODO: this makes sense in some cases, but all?
# (should just omit that field when not relevant)
kwargs['date_ordered'] = None
elif batch_type.startswith('truck_dump_child'):
elif workflow.startswith('truck_dump_child'):
truck_dump = self.get_instance()
kwargs['store'] = truck_dump.store
kwargs['vendor'] = truck_dump.vendor
@ -1986,6 +1855,12 @@ class ReceivingBatchView(PurchasingBatchView):
'type': bool},
# vendors
{'section': 'rattail.batch',
'option': 'purchase.allow_receiving_any_vendor',
'type': bool},
# TODO: deprecated; can remove this once all live config
# is updated. but for now it remains so this setting is
# auto-deleted
{'section': 'rattail.batch',
'option': 'purchase.supported_vendors_only',
'type': bool},
@ -2036,6 +1911,7 @@ class ReceivingBatchView(PurchasingBatchView):
@classmethod
def defaults(cls, config):
cls._receiving_defaults(config)
cls._purchase_batch_defaults(config)
cls._batch_defaults(config)
cls._defaults(config)
@ -2043,17 +1919,11 @@ class ReceivingBatchView(PurchasingBatchView):
def _receiving_defaults(cls, config):
rattail_config = config.registry.settings.get('rattail_config')
route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix()
instance_url_prefix = cls.get_instance_url_prefix()
model_key = cls.get_model_key()
model_title = cls.get_model_title()
permission_prefix = cls.get_permission_prefix()
# new receiving batch using workflow X
config.add_route('{}.create_workflow'.format(route_prefix), '{}/new/{{workflow_key}}/{{vendor_uuid}}'.format(url_prefix))
config.add_view(cls, attr='create', route_name='{}.create_workflow'.format(route_prefix),
permission='{}.create'.format(permission_prefix))
# row-level receiving
config.add_route('{}.receive_row'.format(route_prefix), '{}/rows/{{row_uuid}}/receive'.format(instance_url_prefix))
config.add_view(cls, attr='receive_row', route_name='{}.receive_row'.format(route_prefix),
@ -2106,33 +1976,6 @@ class ReceivingBatchView(PurchasingBatchView):
permission='{}.auto_receive'.format(permission_prefix))
@colander.deferred
def valid_workflow(node, kw):
"""
Deferred validator for ``workflow`` field, for new batches.
"""
valid_workflows = kw['valid_workflows']
def validate(node, value):
# we just need to provide possible values, and let stock validator
# handle the rest
oneof = colander.OneOf(valid_workflows)
return oneof(node, value)
return validate
class NewReceivingBatch(colander.Schema):
"""
Schema for choosing which "type" of new receiving batch should be created.
"""
vendor = colander.SchemaNode(colander.String(),
label="Vendor")
workflow = colander.SchemaNode(colander.String(),
validator=valid_workflow)
class ReceiveRowForm(colander.MappingSchema):
mode = colander.SchemaNode(colander.String(),

View file

@ -77,28 +77,85 @@ class AppInfoView(WuttaAppInfoView):
return context
# nb. these email settings require special handling below
configure_profile_key_mismatches = [
'default.subject',
'default.to',
'default.cc',
'default.bcc',
'feedback.subject',
'feedback.to',
]
def configure_get_simple_settings(self):
""" """
simple_settings = super().configure_get_simple_settings()
# TODO: the update home page redirect setting is off by
# default for wuttaweb, but on for tailbone
# TODO:
# there are several email config keys which differ between
# wuttjamaican and rattail. basically all of the "profile" keys
# have a different prefix.
# after wuttaweb has declared its settings, we examine each and
# overwrite the value if one is defined with rattail config key.
# (nb. this happens even if wuttjamaican key has a value!)
# note that we *do* declare the profile mismatch keys for
# rattail, as part of simple settings. this ensures the
# parent logic will always remove them when saving. however
# we must also include them in gather_settings() to ensure
# they are saved to match wuttjamaican values.
# there are also a couple of flags where rattail's default is the
# opposite of wuttjamaican. so we overwrite those too as needed.
for setting in simple_settings:
# nb. the update home page redirect setting is off by
# default for wuttaweb, but on for tailbone
if setting['name'] == 'wuttaweb.home_redirect_to_login':
value = self.config.get_bool('wuttaweb.home_redirect_to_login')
if value is None:
value = self.config.get_bool('tailbone.login_is_home', default=True)
setting['default'] = value
break
setting['value'] = value
# nb. sending email is off by default for wuttjamaican,
# but on for rattail
elif setting['name'] == 'rattail.mail.send_emails':
value = self.config.get_bool('rattail.mail.send_emails', default=True)
setting['value'] = value
# nb. this one is even more special, key is entirely different
elif setting['name'] == 'rattail.email.default.sender':
value = self.config.get('rattail.email.default.sender')
if value is None:
value = self.config.get('rattail.mail.default.from')
setting['value'] = value
else:
# nb. fetch alternate value for profile key mismatch
for key in self.configure_profile_key_mismatches:
if setting['name'] == f'rattail.email.{key}':
value = self.config.get(f'rattail.email.{key}')
if value is None:
value = self.config.get(f'rattail.mail.{key}')
setting['value'] = value
break
# nb. these are no longer used (deprecated), but we keep
# them defined here so the tool auto-deletes them
simple_settings.extend([
{'name': 'tailbone.login_is_home'},
{'name': 'tailbone.buefy_version'},
{'name': 'tailbone.vue_version'},
])
simple_settings.append({'name': 'rattail.mail.default.from'})
for key in self.configure_profile_key_mismatches:
simple_settings.append({'name': f'rattail.mail.{key}'})
for key in self.get_weblibs():
simple_settings.extend([
{'name': f'tailbone.libver.{key}'},
@ -107,6 +164,28 @@ class AppInfoView(WuttaAppInfoView):
return simple_settings
def configure_gather_settings(self, data, simple_settings=None):
""" """
settings = super().configure_gather_settings(data, simple_settings=simple_settings)
# nb. must add legacy rattail profile settings to match new ones
for setting in list(settings):
if setting['name'] == 'rattail.email.default.sender':
value = setting['value']
settings.append({'name': 'rattail.mail.default.from',
'value': value})
else:
for key in self.configure_profile_key_mismatches:
if setting['name'] == f'rattail.email.{key}':
value = setting['value']
settings.append({'name': f'rattail.mail.{key}',
'value': value})
break
return settings
class SettingView(MasterView):
"""

View file

@ -348,56 +348,27 @@ class UpgradeView(MasterView):
commit_hash_pattern = re.compile(r'^.{40}$')
def get_changelog_projects(self):
projects = {
'rattail': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/rattail/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/rattail/files/v{new_version}/CHANGES.rst',
},
'Tailbone': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone/files/v{new_version}/CHANGES.rst',
},
'pyCOREPOS': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/pycorepos/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/pycorepos/files/v{new_version}/CHANGES.rst',
},
'rattail_corepos': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-corepos/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-corepos/files/v{new_version}/CHANGES.rst',
},
'tailbone_corepos': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone-corepos/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone-corepos/files/v{new_version}/CHANGES.rst',
},
'onager': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-restricted/onager/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-restricted/onager/files/v{new_version}/CHANGES.rst',
},
'rattail-onager': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-restricted/rattail-onager/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-restricted/rattail-onager/files/v{new_version}/CHANGELOG.md',
},
'rattail_tempmon': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-tempmon/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-tempmon/files/v{new_version}/CHANGES.rst',
},
'tailbone-onager': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-restricted/tailbone-onager/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-restricted/tailbone-onager/files/v{new_version}/CHANGELOG.md',
},
'rattail_woocommerce': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-woocommerce/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/rattail-woocommerce/files/v{new_version}/CHANGES.rst',
},
'tailbone_woocommerce': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone-woocommerce/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/tailbone-woocommerce/files/v{new_version}/CHANGES.rst',
},
'tailbone_theo': {
'commit_url': 'https://kallithea.rattailproject.org/rattail-project/theo/changelog/{new_version}/?size=10',
'release_url': 'https://kallithea.rattailproject.org/rattail-project/theo/files/v{new_version}/CHANGES.rst',
},
project_map = {
'onager': 'onager',
'pyCOREPOS': 'pycorepos',
'rattail': 'rattail',
'rattail_corepos': 'rattail-corepos',
'rattail-onager': 'rattail-onager',
'rattail_tempmon': 'rattail-tempmon',
'rattail_woocommerce': 'rattail-woocommerce',
'Tailbone': 'tailbone',
'tailbone_corepos': 'tailbone-corepos',
'tailbone-onager': 'tailbone-onager',
'tailbone_theo': 'theo',
'tailbone_woocommerce': 'tailbone-woocommerce',
}
projects = {}
for name, repo in project_map.items():
projects[name] = {
'commit_url': f'https://forgejo.wuttaproject.org/rattail/{repo}/compare/{{old_version}}...{{new_version}}',
'release_url': f'https://forgejo.wuttaproject.org/rattail/{repo}/src/tag/v{{new_version}}/CHANGELOG.md',
}
return projects
def get_changelog_url(self, project, old_version, new_version):

View file

@ -801,4 +801,8 @@ def defaults(config, **kwargs):
def includeme(config):
defaults(config)
wutta_config = config.registry.settings['wutta_config']
if wutta_config.get_bool('tailbone.use_wutta_views', default=False, usedb=False):
config.include('tailbone.views.wutta.users')
else:
defaults(config)

View file

@ -32,6 +32,7 @@ from wuttaweb.views import people as wutta
from tailbone.views import people as tailbone
from tailbone.db import Session
from rattail.db.model import Person
from tailbone.grids import Grid
class PersonView(wutta.PersonView):
@ -44,7 +45,6 @@ class PersonView(wutta.PersonView):
"""
model_class = Person
Session = Session
sort_defaults = 'display_name'
labels = {
'display_name': "Full Name",
@ -59,6 +59,11 @@ class PersonView(wutta.PersonView):
'merge_requested',
]
filter_defaults = {
'display_name': {'active': True, 'verb': 'contains'},
}
sort_defaults = 'display_name'
form_fields = [
'first_name',
'middle_name',
@ -74,6 +79,11 @@ class PersonView(wutta.PersonView):
# CRUD methods
##############################
# TODO: must use older grid for now, to render filters correctly
def make_grid(self, **kwargs):
""" """
return Grid(self.request, **kwargs)
def configure_grid(self, g):
""" """
super().configure_grid(g)

View file

@ -0,0 +1,57 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
User Views
"""
from wuttaweb.views import users as wutta
from tailbone.views import users as tailbone
from tailbone.db import Session
from rattail.db.model import User
from tailbone.grids import Grid
class UserView(wutta.UserView):
"""
This is the first attempt at blending newer Wutta views with
legacy Tailbone config.
So, this is a Wutta-based view but it should be included by a
Tailbone app configurator.
"""
model_class = User
Session = Session
# TODO: must use older grid for now, to render filters correctly
def make_grid(self, **kwargs):
""" """
return Grid(self.request, **kwargs)
def defaults(config, **kwargs):
kwargs.setdefault('UserView', UserView)
tailbone.defaults(config, **kwargs)
def includeme(config):
defaults(config)

View file

@ -5,12 +5,9 @@ from unittest import TestCase
from pyramid.config import Configurator
from wuttjamaican.testing import FileConfigTestCase
from rattail.exceptions import ConfigurationError
from rattail.config import RattailConfig
from rattail.testing import DataTestCase
from tailbone import app as mod
from tests.util import DataTestCase
class TestRattailConfig(TestCase):
@ -30,7 +27,7 @@ class TestRattailConfig(TestCase):
class TestMakePyramidConfig(DataTestCase):
def make_config(self):
def make_config(self, **kwargs):
myconf = self.write_file('web.conf', """
[rattail.db]
default.url = sqlite://