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,13 +364,115 @@ class ProductsView(MasterView):
f.set_label('upc', "UPC") f.set_label('upc', "UPC")
# department # department
f.set_renderer('department', self.render_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)
# subdepartment # subdepartment
f.set_renderer('subdepartment', self.render_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)
# category # category
f.set_renderer('category', self.render_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)
# 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,19 +482,28 @@ class ProductsView(MasterView):
f.set_label('unit_of_measure', "Unit of Measure") f.set_label('unit_of_measure', "Unit of Measure")
# unit # unit
f.set_renderer('unit', self.render_unit) if self.creating:
f.set_label('unit', "Unit Item") f.remove_field('unit')
else:
f.set_renderer('unit', self.render_unit)
f.set_label('unit', "Unit Item")
# pack_size # pack_size
f.set_type('pack_size', 'quantity') f.set_type('pack_size', 'quantity')
# regular_price # regular_price
f.set_readonly('regular_price') if self.creating:
f.set_renderer('regular_price', self.render_price) f.remove_field('regular_price')
else:
f.set_readonly('regular_price')
f.set_renderer('regular_price', self.render_price)
# current_price # current_price
f.set_readonly('current_price') if self.creating:
f.set_renderer('current_price', self.render_price) f.remove_field('current_price')
else:
f.set_readonly('current_price')
f.set_renderer('current_price', self.render_price)
# last_sold # last_sold
f.set_readonly('last_sold') f.set_readonly('last_sold')
@ -404,18 +515,27 @@ 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
f.set_readonly('current_price_ends') if self.creating:
f.set_renderer('current_price_ends', self.render_current_price_ends) f.remove_field('current_price_ends')
else:
f.set_readonly('current_price_ends')
f.set_renderer('current_price_ends', self.render_current_price_ends)
# inventory_on_hand # inventory_on_hand
f.set_readonly('inventory_on_hand') if self.creating:
f.set_renderer('inventory_on_hand', self.render_inventory_on_hand) f.remove_field('inventory_on_hand')
f.set_label('inventory_on_hand', "On Hand") else:
f.set_readonly('inventory_on_hand')
f.set_renderer('inventory_on_hand', self.render_inventory_on_hand)
f.set_label('inventory_on_hand', "On Hand")
# inventory_on_order # inventory_on_order
f.set_readonly('inventory_on_order') if self.creating:
f.set_renderer('inventory_on_order', self.render_inventory_on_order) f.remove_field('inventory_on_order')
f.set_label('inventory_on_order', "On Order") else:
f.set_readonly('inventory_on_order')
f.set_renderer('inventory_on_order', self.render_inventory_on_order)
f.set_label('inventory_on_order', "On Order")
if not self.request.has_perm('products.view_deleted'): if not self.request.has_perm('products.view_deleted'):
f.remove('deleted') f.remove('deleted')

View file

@ -104,8 +104,12 @@ 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 '')
f.set_readonly('contact') # contact
f.set_renderer('contact', self.render_contact) if self.creating:
f.remove_field('contact')
else:
f.set_readonly('contact')
f.set_renderer('contact', self.render_contact)
def objectify(self, form, data): def objectify(self, form, data):
vendor = super(VendorsView, self).objectify(form, data) vendor = super(VendorsView, self).objectify(form, data)