Tweak how purchase batch is created via mobile

to let custom apps override args etc.
This commit is contained in:
Lance Edgar 2017-05-18 11:33:01 -05:00
parent 9e0e21399b
commit f0feefc7e5
2 changed files with 14 additions and 10 deletions

View file

@ -277,7 +277,7 @@ class BatchMasterView(MasterView):
# return this object to replace the original # return this object to replace the original
return batch return batch
def get_batch_kwargs(self, batch): def get_batch_kwargs(self, batch, mobile=False):
""" """
Return a kwargs dict for use with ``self.handler.make_batch()``, using Return a kwargs dict for use with ``self.handler.make_batch()``, using
the given batch as a template. the given batch as a template.

View file

@ -43,7 +43,7 @@ import formalchemy as fa
import formencode as fe import formencode as fe
from pyramid import httpexceptions from pyramid import httpexceptions
from tailbone import forms from tailbone import forms, newgrids as grids
from tailbone.db import Session from tailbone.db import Session
from tailbone.views.batch import BatchMasterView from tailbone.views.batch import BatchMasterView
@ -97,6 +97,8 @@ class PurchaseBatchView(BatchMasterView):
def _preconfigure_grid(self, g): def _preconfigure_grid(self, g):
super(PurchaseBatchView, self)._preconfigure_grid(g) super(PurchaseBatchView, self)._preconfigure_grid(g)
g.filters['mode'].set_value_renderer(grids.filters.EnumValueRenderer(self.enum.PURCHASE_BATCH_MODE))
g.joiners['vendor'] = lambda q: q.join(model.Vendor) g.joiners['vendor'] = lambda q: q.join(model.Vendor)
g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name, g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name,
default_active=True, default_verb='contains') default_active=True, default_verb='contains')
@ -289,8 +291,8 @@ class PurchaseBatchView(BatchMasterView):
total = purchase.invoice_total total = purchase.invoice_total
return '{} for ${:0,.2f} ({})'.format(date, total, purchase.department or purchase.buyer) return '{} for ${:0,.2f} ({})'.format(date, total, purchase.department or purchase.buyer)
def get_batch_kwargs(self, batch): def get_batch_kwargs(self, batch, mobile=False):
kwargs = super(PurchaseBatchView, self).get_batch_kwargs(batch) kwargs = super(PurchaseBatchView, self).get_batch_kwargs(batch, mobile=mobile)
kwargs['mode'] = batch.mode kwargs['mode'] = batch.mode
if batch.store: if batch.store:
kwargs['store'] = batch.store kwargs['store'] = batch.store
@ -933,12 +935,14 @@ class PurchaseBatchView(BatchMasterView):
if self.request.POST.get('purchase'): if self.request.POST.get('purchase'):
purchase = self.get_purchase(self.request.POST['purchase']) purchase = self.get_purchase(self.request.POST['purchase'])
if purchase: if purchase:
# TODO: these kwargs need help! batch = self.model_class()
batch = self.handler.make_batch(self.Session(), batch.mode = mode
mode=mode, vendor=vendor, batch.vendor = vendor
store=self.rattail_config.get_store(self.Session()), batch.store = self.rattail_config.get_store(self.Session())
buyer=self.request.user.employee, batch.buyer = self.request.user.employee
created_by=self.request.user) batch.created_by = self.request.user
kwargs = self.get_batch_kwargs(batch, mobile=True)
batch = self.handler.make_batch(self.Session(), **kwargs)
self.request.session.flash("Created new purchasing batch: {}".format(batch)) self.request.session.flash("Created new purchasing batch: {}".format(batch))
return self.redirect(self.request.route_url('purchases.batch.mobile_create')) return self.redirect(self.request.route_url('purchases.batch.mobile_create'))