Fix default create logic for vendors, products

online demo triggered errors for this.  might as well have basic support
This commit is contained in:
Lance Edgar 2018-03-05 20:20:35 -06:00
parent 90f0fcfea6
commit aeccf5c5f6
2 changed files with 143 additions and 19 deletions

View file

@ -364,14 +364,116 @@ class ProductsView(MasterView):
f.set_label('upc', "UPC") f.set_label('upc', "UPC")
# department # department
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)
dept_values = [(d.uuid, "{} {}".format(d.number, d.name))
for d in departments]
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) f.set_renderer('department', self.render_department)
# subdepartment # subdepartment
if self.creating or self.editing:
if 'subdepartment' in f.fields:
f.replace('subdepartment', 'subdepartment_uuid')
subdepartments = self.Session.query(model.Subdepartment)\
.order_by(model.Subdepartment.number)
subdept_values = [(s.uuid, "{} {}".format(s.number, s.name))
for s in subdepartments]
f.set_widget('subdepartment_uuid', dfwidget.SelectWidget(values=subdept_values))
f.set_label('subdepartment_uuid', "Subdepartment")
else:
f.set_readonly('subdepartment')
f.set_renderer('subdepartment', self.render_subdepartment) f.set_renderer('subdepartment', self.render_subdepartment)
# category # category
if self.creating or self.editing:
if 'category' in f.fields:
f.replace('category', 'category_uuid')
categories = self.Session.query(model.Category)\
.order_by(model.Category.code)
category_values = [(c.uuid, "{} {}".format(c.code, c.name))
for c in categories]
f.set_widget('category_uuid', dfwidget.SelectWidget(values=category_values))
f.set_label('category_uuid', "Category")
else:
f.set_readonly('category')
f.set_renderer('category', self.render_category) f.set_renderer('category', self.render_category)
# family
if self.creating or self.editing:
if 'family' in f.fields:
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]
f.set_widget('family_uuid', dfwidget.SelectWidget(values=family_values))
f.set_label('family_uuid', "Family")
else:
f.set_readonly('family')
# f.set_renderer('family', self.render_family)
# report_code
if self.creating or self.editing:
if 'report_code' in f.fields:
f.replace('report_code', 'report_code_uuid')
report_codes = self.Session.query(model.ReportCode)\
.order_by(model.ReportCode.code)
report_code_values = [(rc.uuid, "{} {}".format(rc.code, rc.name))
for rc in report_codes]
f.set_widget('report_code_uuid', dfwidget.SelectWidget(values=report_code_values))
f.set_label('report_code_uuid', "Report_Code")
else:
f.set_readonly('report_code')
# f.set_renderer('report_code', self.render_report_code)
# deposit_link
if self.creating or self.editing:
if 'deposit_link' in f.fields:
f.replace('deposit_link', 'deposit_link_uuid')
deposit_links = self.Session.query(model.DepositLink)\
.order_by(model.DepositLink.code)
deposit_link_values = [(dl.uuid, "{} {}".format(dl.code, dl.description))
for dl in deposit_links]
f.set_widget('deposit_link_uuid', dfwidget.SelectWidget(values=deposit_link_values))
f.set_label('deposit_link_uuid', "Deposit_Link")
else:
f.set_readonly('deposit_link')
# f.set_renderer('deposit_link', self.render_deposit_link)
# tax
if self.creating or self.editing:
if 'tax' in f.fields:
f.replace('tax', 'tax_uuid')
taxes = self.Session.query(model.Tax)\
.order_by(model.Tax.code)
tax_values = [(tax.uuid, "{} {}".format(tax.code, tax.description))
for tax in taxes]
f.set_widget('tax_uuid', dfwidget.SelectWidget(values=tax_values))
f.set_label('tax_uuid', "Tax")
else:
f.set_readonly('tax')
# f.set_renderer('tax', self.render_tax)
# brand
if self.creating:
f.replace('brand', 'brand_uuid')
brand_display = ""
if self.request.method == 'POST':
if self.request.POST.get('brand_uuid'):
brand = self.Session.query(model.Brand).get(self.request.POST['brand_uuid'])
if brand:
brand_display = six.text_type(brand)
brands_url = self.request.route_url('brands.autocomplete')
f.set_widget('brand_uuid', forms.widgets.JQueryAutocompleteWidget(
field_display=brand_display, service_url=brands_url))
f.set_label('brand_uuid', "Brand")
# unit_size # unit_size
f.set_type('unit_size', 'quantity') f.set_type('unit_size', 'quantity')
@ -380,6 +482,9 @@ class ProductsView(MasterView):
f.set_label('unit_of_measure', "Unit of Measure") f.set_label('unit_of_measure', "Unit of Measure")
# unit # unit
if self.creating:
f.remove_field('unit')
else:
f.set_renderer('unit', self.render_unit) f.set_renderer('unit', self.render_unit)
f.set_label('unit', "Unit Item") f.set_label('unit', "Unit Item")
@ -387,10 +492,16 @@ class ProductsView(MasterView):
f.set_type('pack_size', 'quantity') f.set_type('pack_size', 'quantity')
# regular_price # regular_price
if self.creating:
f.remove_field('regular_price')
else:
f.set_readonly('regular_price') f.set_readonly('regular_price')
f.set_renderer('regular_price', self.render_price) f.set_renderer('regular_price', self.render_price)
# current_price # current_price
if self.creating:
f.remove_field('current_price')
else:
f.set_readonly('current_price') f.set_readonly('current_price')
f.set_renderer('current_price', self.render_price) f.set_renderer('current_price', self.render_price)
@ -404,15 +515,24 @@ class ProductsView(MasterView):
f.set_widget('notes', dfwidget.TextAreaWidget(cols=80, rows=10)) f.set_widget('notes', dfwidget.TextAreaWidget(cols=80, rows=10))
# current_price_ends # current_price_ends
if self.creating:
f.remove_field('current_price_ends')
else:
f.set_readonly('current_price_ends') f.set_readonly('current_price_ends')
f.set_renderer('current_price_ends', self.render_current_price_ends) f.set_renderer('current_price_ends', self.render_current_price_ends)
# inventory_on_hand # inventory_on_hand
if self.creating:
f.remove_field('inventory_on_hand')
else:
f.set_readonly('inventory_on_hand') f.set_readonly('inventory_on_hand')
f.set_renderer('inventory_on_hand', self.render_inventory_on_hand) f.set_renderer('inventory_on_hand', self.render_inventory_on_hand)
f.set_label('inventory_on_hand', "On Hand") f.set_label('inventory_on_hand', "On Hand")
# inventory_on_order # inventory_on_order
if self.creating:
f.remove_field('inventory_on_order')
else:
f.set_readonly('inventory_on_order') f.set_readonly('inventory_on_order')
f.set_renderer('inventory_on_order', self.render_inventory_on_order) f.set_renderer('inventory_on_order', self.render_inventory_on_order)
f.set_label('inventory_on_order', "On Order") f.set_label('inventory_on_order', "On Order")

View file

@ -104,6 +104,10 @@ class VendorsView(MasterView):
if not self.creating and vendor.emails: if not self.creating and vendor.emails:
f.set_default('orders_email', vendor.get_email_address(type_='Orders') or '') f.set_default('orders_email', vendor.get_email_address(type_='Orders') or '')
# contact
if self.creating:
f.remove_field('contact')
else:
f.set_readonly('contact') f.set_readonly('contact')
f.set_renderer('contact', self.render_contact) f.set_renderer('contact', self.render_contact)