Only expose "product" departments within product view dropdowns
This commit is contained in:
parent
ae27c110ab
commit
db3cd4ec6e
|
@ -211,6 +211,18 @@ class ProductView(MasterView):
|
|||
|
||||
return query
|
||||
|
||||
def get_departments(self):
|
||||
"""
|
||||
Returns the list of departments to be exposed in a drop-down.
|
||||
"""
|
||||
model = self.model
|
||||
return self.Session.query(model.Department)\
|
||||
.filter(sa.or_(
|
||||
model.Department.product == True,
|
||||
model.Department.product == None))\
|
||||
.order_by(model.Department.name)\
|
||||
.all()
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(ProductView, self).configure_grid(g)
|
||||
app = self.get_rattail_app()
|
||||
|
@ -247,12 +259,9 @@ class ProductView(MasterView):
|
|||
# department
|
||||
g.set_joiner('department', lambda q: q.outerjoin(model.Department))
|
||||
g.set_sorter('department', model.Department.name)
|
||||
department_choices = app.cache_model(self.Session(), model.Department,
|
||||
order_by=model.Department.name,
|
||||
normalizer=lambda d: d.name)
|
||||
departments = self.get_departments()
|
||||
department_choices = OrderedDict([('', "(any)")]
|
||||
+ sorted(six.iteritems(department_choices),
|
||||
key=lambda itm: itm[1]))
|
||||
+ [(d.uuid, d.name) for d in departments])
|
||||
if not use_buefy:
|
||||
department_choices = [tags.Option(name, uuid)
|
||||
for uuid, name in six.iteritems(department_choices)]
|
||||
|
@ -824,8 +833,7 @@ class ProductView(MasterView):
|
|||
if self.creating or self.editing:
|
||||
if 'department' in f.fields:
|
||||
f.replace('department', 'department_uuid')
|
||||
departments = self.Session.query(model.Department)\
|
||||
.order_by(model.Department.number)
|
||||
departments = self.get_departments()
|
||||
dept_values = [(d.uuid, "{} {}".format(d.number, d.name))
|
||||
for d in departments]
|
||||
require_department = False
|
||||
|
|
Loading…
Reference in a new issue