Tweak how purchase batch is created via mobile
to let custom apps override args etc.
This commit is contained in:
parent
9e0e21399b
commit
f0feefc7e5
|
@ -277,7 +277,7 @@ class BatchMasterView(MasterView):
|
|||
# return this object to replace the original
|
||||
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
|
||||
the given batch as a template.
|
||||
|
|
|
@ -43,7 +43,7 @@ import formalchemy as fa
|
|||
import formencode as fe
|
||||
from pyramid import httpexceptions
|
||||
|
||||
from tailbone import forms
|
||||
from tailbone import forms, newgrids as grids
|
||||
from tailbone.db import Session
|
||||
from tailbone.views.batch import BatchMasterView
|
||||
|
||||
|
@ -97,6 +97,8 @@ class PurchaseBatchView(BatchMasterView):
|
|||
def _preconfigure_grid(self, 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.filters['vendor'] = g.make_filter('vendor', model.Vendor.name,
|
||||
default_active=True, default_verb='contains')
|
||||
|
@ -289,8 +291,8 @@ class PurchaseBatchView(BatchMasterView):
|
|||
total = purchase.invoice_total
|
||||
return '{} for ${:0,.2f} ({})'.format(date, total, purchase.department or purchase.buyer)
|
||||
|
||||
def get_batch_kwargs(self, batch):
|
||||
kwargs = super(PurchaseBatchView, self).get_batch_kwargs(batch)
|
||||
def get_batch_kwargs(self, batch, mobile=False):
|
||||
kwargs = super(PurchaseBatchView, self).get_batch_kwargs(batch, mobile=mobile)
|
||||
kwargs['mode'] = batch.mode
|
||||
if batch.store:
|
||||
kwargs['store'] = batch.store
|
||||
|
@ -933,12 +935,14 @@ class PurchaseBatchView(BatchMasterView):
|
|||
if self.request.POST.get('purchase'):
|
||||
purchase = self.get_purchase(self.request.POST['purchase'])
|
||||
if purchase:
|
||||
# TODO: these kwargs need help!
|
||||
batch = self.handler.make_batch(self.Session(),
|
||||
mode=mode, vendor=vendor,
|
||||
store=self.rattail_config.get_store(self.Session()),
|
||||
buyer=self.request.user.employee,
|
||||
created_by=self.request.user)
|
||||
batch = self.model_class()
|
||||
batch.mode = mode
|
||||
batch.vendor = vendor
|
||||
batch.store = self.rattail_config.get_store(self.Session())
|
||||
batch.buyer = self.request.user.employee
|
||||
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))
|
||||
return self.redirect(self.request.route_url('purchases.batch.mobile_create'))
|
||||
|
||||
|
|
Loading…
Reference in a new issue