Allow override of products query when making batch from it
also, invoke handler properly when populating the batch (i.e. to include setup/teardown)
This commit is contained in:
parent
3b54ab3e0b
commit
d773043429
|
@ -1008,7 +1008,7 @@ class ProductsView(MasterView):
|
|||
params[name] = None
|
||||
|
||||
handler = supported[batch_key]
|
||||
products = self.get_effective_data()
|
||||
products = self.get_products_for_batch(batch_key)
|
||||
progress = SessionProgress(self.request, 'products.batch')
|
||||
thread = Thread(target=self.make_batch_thread,
|
||||
args=(handler, self.request.user.uuid, products, params, progress))
|
||||
|
@ -1024,6 +1024,14 @@ class ProductsView(MasterView):
|
|||
'params_forms': params_forms,
|
||||
})
|
||||
|
||||
def get_products_for_batch(self, batch_key):
|
||||
"""
|
||||
Returns the products query to be used when making a batch (of type
|
||||
``batch_key``) with the user's current filters in effect. You can
|
||||
override this to add eager joins for certain batch types, etc.
|
||||
"""
|
||||
return self.get_effective_data()
|
||||
|
||||
def make_batch_params_schema_pricing(self):
|
||||
"""
|
||||
Return params schema for making a pricing batch.
|
||||
|
@ -1049,7 +1057,7 @@ class ProductsView(MasterView):
|
|||
params['created_by'] = user
|
||||
batch = handler.make_batch(session, **params)
|
||||
batch.products = products.with_session(session).all()
|
||||
handler.populate(batch, progress=progress)
|
||||
handler.do_populate(batch, user, progress=progress)
|
||||
|
||||
session.commit()
|
||||
session.refresh(batch)
|
||||
|
|
Loading…
Reference in a new issue