From f0feefc7e5391742cd4804e4e8de29c625934de6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 18 May 2017 11:33:01 -0500 Subject: [PATCH] Tweak how purchase batch is created via mobile to let custom apps override args etc. --- tailbone/views/batch/core.py | 2 +- tailbone/views/purchases/batch.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index a5556c25..3ca566d3 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -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. diff --git a/tailbone/views/purchases/batch.py b/tailbone/views/purchases/batch.py index 77bda352..7b4673f8 100644 --- a/tailbone/views/purchases/batch.py +++ b/tailbone/views/purchases/batch.py @@ -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'))