Use Grid.make_sorter()
instead of legacy code
b/c multi-column sorting relies on this
This commit is contained in:
parent
659f5a8fe1
commit
919d8d109f
14 changed files with 198 additions and 176 deletions
|
@ -175,9 +175,10 @@ class PurchasingBatchView(BatchMasterView):
|
|||
g.set_filter('vendor', model.Vendor.name,
|
||||
default_active=True, default_verb='contains')
|
||||
|
||||
g.joiners['department'] = lambda q: q.join(model.Department)
|
||||
g.filters['department'] = g.make_filter('department', model.Department.name)
|
||||
g.sorters['department'] = g.make_sorter(model.Department.name)
|
||||
# department
|
||||
g.set_joiner('department', lambda q: q.join(model.Department))
|
||||
g.set_filter('department', model.Department.name)
|
||||
g.set_sorter('department', model.Department.name)
|
||||
|
||||
g.set_joiner('buyer', lambda q: q.join(model.Employee).join(model.Person))
|
||||
g.set_filter('buyer', model.Person.display_name)
|
||||
|
@ -212,7 +213,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
# return form
|
||||
|
||||
def configure_common_form(self, f):
|
||||
super(PurchasingBatchView, self).configure_common_form(f)
|
||||
super().configure_common_form(f)
|
||||
|
||||
# po_total
|
||||
if self.creating:
|
||||
|
@ -225,7 +226,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
f.set_type('po_total_calculated', 'currency')
|
||||
|
||||
def configure_form(self, f):
|
||||
super(PurchasingBatchView, self).configure_form(f)
|
||||
super().configure_form(f)
|
||||
model = self.model
|
||||
batch = f.model_instance
|
||||
app = self.get_rattail_app()
|
||||
|
@ -598,7 +599,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
# return query.options(orm.joinedload(model.PurchaseBatchRow.credits))
|
||||
|
||||
def configure_row_grid(self, g):
|
||||
super(PurchasingBatchView, self).configure_row_grid(g)
|
||||
super().configure_row_grid(g)
|
||||
|
||||
g.set_type('upc', 'gpc')
|
||||
g.set_type('cases_ordered', 'quantity')
|
||||
|
@ -685,7 +686,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
return 'notice'
|
||||
|
||||
def configure_row_form(self, f):
|
||||
super(PurchasingBatchView, self).configure_row_form(f)
|
||||
super().configure_row_form(f)
|
||||
row = f.model_instance
|
||||
if self.creating:
|
||||
batch = self.get_instance()
|
||||
|
@ -894,7 +895,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
batch.invoice_total -= row.invoice_total
|
||||
|
||||
# do the "normal" save logic...
|
||||
row = super(PurchasingBatchView, self).save_edit_row_form(form)
|
||||
row = super().save_edit_row_form(form)
|
||||
|
||||
# TODO: is this needed?
|
||||
# self.handler.refresh_row(row)
|
||||
|
|
|
@ -233,7 +233,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return self.enum.PURCHASE_BATCH_MODE_RECEIVING
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(ReceivingBatchView, self).configure_grid(g)
|
||||
super().configure_grid(g)
|
||||
|
||||
if not self.handler.allow_truck_dump_receiving():
|
||||
g.remove('truck_dump')
|
||||
|
@ -285,14 +285,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
raise redirect
|
||||
|
||||
# okay now do the normal thing, per workflow
|
||||
return super(ReceivingBatchView, self).create(**kwargs)
|
||||
return super().create(**kwargs)
|
||||
|
||||
# on the other hand, if caller provided a form, that means we are in
|
||||
# the middle of some other custom workflow, e.g. "add child to truck
|
||||
# dump parent" or some such. in which case we also defer to the normal
|
||||
# logic, so as to not interfere with that.
|
||||
if form:
|
||||
return super(ReceivingBatchView, self).create(form=form, **kwargs)
|
||||
return super().create(form=form, **kwargs)
|
||||
|
||||
# okay, at this point we need the user to select a vendor and workflow
|
||||
self.creating = True
|
||||
|
@ -372,14 +372,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
# first run it through the normal logic, if that doesn't like
|
||||
# it then we won't either
|
||||
if not super(ReceivingBatchView, self).row_deletable(row):
|
||||
if not super().row_deletable(row):
|
||||
return False
|
||||
|
||||
# otherwise let handler decide
|
||||
return self.batch_handler.is_row_deletable(row)
|
||||
|
||||
def get_instance_title(self, batch):
|
||||
title = super(ReceivingBatchView, self).get_instance_title(batch)
|
||||
title = super().get_instance_title(batch)
|
||||
if batch.is_truck_dump_parent():
|
||||
title = "{} (TRUCK DUMP PARENT)".format(title)
|
||||
elif batch.is_truck_dump_child():
|
||||
|
@ -633,7 +633,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return info['display']
|
||||
|
||||
def get_visible_params(self, batch):
|
||||
params = super(ReceivingBatchView, self).get_visible_params(batch)
|
||||
params = super().get_visible_params(batch)
|
||||
|
||||
# remove this since we show it separately
|
||||
params.pop('invoice_files', None)
|
||||
|
@ -655,7 +655,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return kwargs
|
||||
|
||||
def get_batch_kwargs(self, batch, **kwargs):
|
||||
kwargs = super(ReceivingBatchView, self).get_batch_kwargs(batch, **kwargs)
|
||||
kwargs = super().get_batch_kwargs(batch, **kwargs)
|
||||
batch_type = self.request.POST['batch_type']
|
||||
|
||||
# must pull vendor from URL if it was not in form data
|
||||
|
@ -769,7 +769,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return True
|
||||
|
||||
def template_kwargs_view(self, **kwargs):
|
||||
kwargs = super(ReceivingBatchView, self).template_kwargs_view(**kwargs)
|
||||
kwargs = super().template_kwargs_view(**kwargs)
|
||||
batch = kwargs['instance']
|
||||
|
||||
if self.handler.has_purchase_order(batch) and self.handler.has_invoice_file(batch):
|
||||
|
@ -810,7 +810,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return credits_data
|
||||
|
||||
def template_kwargs_view_row(self, **kwargs):
|
||||
kwargs = super(ReceivingBatchView, self).template_kwargs_view_row(**kwargs)
|
||||
kwargs = super().template_kwargs_view_row(**kwargs)
|
||||
app = self.get_rattail_app()
|
||||
products_handler = app.get_products_handler()
|
||||
row = kwargs['instance']
|
||||
|
@ -847,7 +847,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if batch.is_truck_dump_parent():
|
||||
for child in batch.truck_dump_children:
|
||||
self.delete_instance(child)
|
||||
super(ReceivingBatchView, self).delete_instance(batch)
|
||||
super().delete_instance(batch)
|
||||
if truck_dump:
|
||||
self.handler.refresh(truck_dump)
|
||||
|
||||
|
@ -1010,7 +1010,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
.group_by(model.PurchaseBatchCredit.row_uuid)\
|
||||
.subquery()
|
||||
g.set_joiner('credits', lambda q: q.outerjoin(Credits))
|
||||
g.sorters['credits'] = lambda q, d: q.order_by(getattr(Credits.c.credit_count, d)())
|
||||
g.set_sorter('credits', Credits.c.credit_count)
|
||||
|
||||
show_ordered = self.rattail_config.getbool(
|
||||
'rattail.batch', 'purchase.receiving.show_ordered_column_in_grid',
|
||||
|
@ -1083,7 +1083,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
})
|
||||
|
||||
def row_grid_extra_class(self, row, i):
|
||||
css_class = super(ReceivingBatchView, self).row_grid_extra_class(row, i)
|
||||
css_class = super().row_grid_extra_class(row, i)
|
||||
|
||||
if row.catalog_cost_confirmed:
|
||||
css_class = '{} catalog_cost_confirmed'.format(css_class or '')
|
||||
|
@ -1098,7 +1098,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return str(row.product)
|
||||
if row.upc:
|
||||
return row.upc.pretty()
|
||||
return super(ReceivingBatchView, self).get_row_instance_title(row)
|
||||
return super().get_row_instance_title(row)
|
||||
|
||||
def transform_unit_url(self, row, i):
|
||||
# grid action is shown only when we return a URL here
|
||||
|
@ -1110,7 +1110,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
def make_row_credits_grid(self, row):
|
||||
|
||||
# first make grid like normal
|
||||
g = super(ReceivingBatchView, self).make_row_credits_grid(row)
|
||||
g = super().make_row_credits_grid(row)
|
||||
|
||||
if (self.has_perm('edit_row')
|
||||
and self.row_editable(row)):
|
||||
|
@ -1616,7 +1616,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
def validate_row_form(self, form):
|
||||
|
||||
# if normal validation fails, stop there
|
||||
if not super(ReceivingBatchView, self).validate_row_form(form):
|
||||
if not super().validate_row_form(form):
|
||||
return False
|
||||
|
||||
# if user is editing row from truck dump child, then we must further
|
||||
|
@ -2097,7 +2097,7 @@ class ReceiveRowForm(colander.MappingSchema):
|
|||
quick_receive = colander.SchemaNode(colander.Boolean())
|
||||
|
||||
def deserialize(self, *args):
|
||||
result = super(ReceiveRowForm, self).deserialize(*args)
|
||||
result = super().deserialize(*args)
|
||||
|
||||
if result['mode'] == 'expired' and not result['expiration_date']:
|
||||
msg = "Expiration date is required for items with 'expired' mode."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue