Fix some basic product editing features

mostly for sake of online demo
This commit is contained in:
Lance Edgar 2020-02-28 18:11:54 -06:00
parent 815cdbdd0a
commit 86617e410f
3 changed files with 96 additions and 15 deletions

View file

@ -786,11 +786,17 @@ class ProductsView(MasterView):
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")
f.set_label('report_code_uuid', "Report Code")
else:
f.set_readonly('report_code')
# f.set_renderer('report_code', self.render_report_code)
# regular_price_amount
if self.editing:
f.set_node('regular_price_amount', colander.Decimal())
f.set_default('regular_price_amount', product.regular_price.price if product.regular_price else None)
f.set_label('regular_price_amount', "Regular Price")
# deposit_link
if self.creating or self.editing:
if 'deposit_link' in f.fields:
@ -803,7 +809,7 @@ class ProductsView(MasterView):
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")
f.set_label('deposit_link_uuid', "Deposit Link")
else:
f.set_readonly('deposit_link')
# f.set_renderer('deposit_link', self.render_deposit_link)
@ -831,18 +837,24 @@ class ProductsView(MasterView):
f.set_readonly('tax3')
# 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")
if self.creating or self.editing:
if 'brand' in f.fields:
f.replace('brand', 'brand_uuid')
f.set_node('brand_uuid', colander.String(), missing=colander.null)
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)
elif self.editing:
brand_display = six.text_type(product.brand or '')
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")
else:
f.set_readonly('brand')
# status_code
f.set_label('status_code', "Status")
@ -856,6 +868,17 @@ class ProductsView(MasterView):
if not self.request.has_perm('products.view_deleted'):
f.remove('deleted')
def objectify(self, form, data=None):
if data is None:
data = form.validated
product = super(ProductsView, self).objectify(form, data=data)
# regular_price_amount
if (self.creating or self.editing) and 'regular_price_amount' in form.fields:
api.set_regular_price(product, data['regular_price_amount'])
return product
def render_department(self, product, field):
department = product.department
if not department: