Allow editing the Department field for a Subdepartment
This commit is contained in:
parent
320aaab4b3
commit
eddbfcab36
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,10 +24,12 @@
|
|||
Subdepartment Views
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
from deform import widget as dfwidget
|
||||
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView
|
||||
|
||||
|
@ -104,9 +106,34 @@ class SubdepartmentView(MasterView):
|
|||
super(SubdepartmentView, self).configure_form(f)
|
||||
f.remove_field('products')
|
||||
|
||||
# TODO: figure out this dang department situation..
|
||||
f.remove_field('department_uuid')
|
||||
# department
|
||||
if self.creating or self.editing:
|
||||
if 'department' in f.fields:
|
||||
f.replace('department', 'department_uuid')
|
||||
departments = self.get_departments()
|
||||
dept_values = [(d.uuid, "{} {}".format(d.number, d.name))
|
||||
for d in departments]
|
||||
require_department = False
|
||||
if not require_department:
|
||||
dept_values.insert(0, ('', "(none)"))
|
||||
f.set_widget('department_uuid',
|
||||
dfwidget.SelectWidget(values=dept_values))
|
||||
f.set_label('department_uuid', "Department")
|
||||
else:
|
||||
f.set_readonly('department')
|
||||
f.set_renderer('department', self.render_department)
|
||||
|
||||
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 get_merge_data(self, subdept):
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue