Improve basic support for adding new product

This commit is contained in:
Lance Edgar 2018-06-28 12:26:22 -05:00
parent b9d699df84
commit 1342d67746

View file

@ -377,6 +377,9 @@ class ProductsView(MasterView):
.order_by(model.Department.number)
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:
@ -391,6 +394,9 @@ class ProductsView(MasterView):
.order_by(model.Subdepartment.number)
subdept_values = [(s.uuid, "{} {}".format(s.number, s.name))
for s in subdepartments]
require_subdepartment = False
if not require_subdepartment:
subdept_values.insert(0, ('', "(none)"))
f.set_widget('subdepartment_uuid', dfwidget.SelectWidget(values=subdept_values))
f.set_label('subdepartment_uuid', "Subdepartment")
else:
@ -405,6 +411,9 @@ class ProductsView(MasterView):
.order_by(model.Category.code)
category_values = [(c.uuid, "{} {}".format(c.code, c.name))
for c in categories]
require_category = False
if not require_category:
category_values.insert(0, ('', "(none)"))
f.set_widget('category_uuid', dfwidget.SelectWidget(values=category_values))
f.set_label('category_uuid', "Category")
else:
@ -417,7 +426,10 @@ class ProductsView(MasterView):
f.replace('family', 'family_uuid')
families = self.Session.query(model.Family)\
.order_by(model.Family.name)
family_values = [(f.uuid, f.name) for f in families]
family_values = [(fam.uuid, fam.name) for fam in families]
require_family = False
if not require_family:
family_values.insert(0, ('', "(none)"))
f.set_widget('family_uuid', dfwidget.SelectWidget(values=family_values))
f.set_label('family_uuid', "Family")
else:
@ -432,6 +444,9 @@ class ProductsView(MasterView):
.order_by(model.ReportCode.code)
report_code_values = [(rc.uuid, "{} {}".format(rc.code, rc.name))
for rc in report_codes]
require_report_code = False
if not require_report_code:
report_code_values.insert(0, ('', "(none)"))
f.set_widget('report_code_uuid', dfwidget.SelectWidget(values=report_code_values))
f.set_label('report_code_uuid', "Report_Code")
else:
@ -446,6 +461,9 @@ class ProductsView(MasterView):
.order_by(model.DepositLink.code)
deposit_link_values = [(dl.uuid, "{} {}".format(dl.code, dl.description))
for dl in deposit_links]
require_deposit_link = False
if not require_deposit_link:
deposit_link_values.insert(0, ('', "(none)"))
f.set_widget('deposit_link_uuid', dfwidget.SelectWidget(values=deposit_link_values))
f.set_label('deposit_link_uuid', "Deposit_Link")
else:
@ -460,6 +478,9 @@ class ProductsView(MasterView):
.order_by(model.Tax.code)
tax_values = [(tax.uuid, "{} {}".format(tax.code, tax.description))
for tax in taxes]
require_tax = False
if not require_tax:
tax_values.insert(0, ('', "(none)"))
f.set_widget('tax_uuid', dfwidget.SelectWidget(values=tax_values))
f.set_label('tax_uuid', "Tax")
else:
@ -512,11 +533,17 @@ class ProductsView(MasterView):
f.set_renderer('current_price', self.render_price)
# last_sold
if self.creating:
f.remove_field('last_sold')
else:
f.set_readonly('last_sold')
# status_code
f.set_label('status_code', "Status")
# ingredients
f.set_widget('ingredients', dfwidget.TextAreaWidget(cols=80, rows=10))
# notes
f.set_widget('notes', dfwidget.TextAreaWidget(cols=80, rows=10))