Add support for mode, purchase relation for purchase batches

This commit is contained in:
Lance Edgar 2016-11-20 17:48:04 -06:00
parent 1a6bacda6a
commit d46b0cbc70
5 changed files with 84 additions and 5 deletions

View file

@ -47,6 +47,6 @@ from .products import (ProductFieldRenderer, GPCFieldRenderer, BrandFieldRendere
from .stores import StoreFieldRenderer from .stores import StoreFieldRenderer
from .vendors import VendorFieldRenderer from .vendors import VendorFieldRenderer, PurchaseFieldRenderer
from .batch import BatchIDFieldRenderer, HandheldBatchFieldRenderer from .batch import BatchIDFieldRenderer, HandheldBatchFieldRenderer

View file

@ -26,6 +26,7 @@ Vendor Field Renderers
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import formalchemy as fa
from webhelpers.html import tags from webhelpers.html import tags
from tailbone.forms.renderers.common import AutocompleteFieldRenderer from tailbone.forms.renderers.common import AutocompleteFieldRenderer
@ -42,3 +43,15 @@ class VendorFieldRenderer(AutocompleteFieldRenderer):
if not vendor: if not vendor:
return '' return ''
return tags.link_to(vendor, self.request.route_url('vendors.view', uuid=vendor.uuid)) return tags.link_to(vendor, self.request.route_url('vendors.view', uuid=vendor.uuid))
class PurchaseFieldRenderer(fa.FieldRenderer):
"""
Renderer for :class:`rattail.db.model.Purchase` relation fields.
"""
def render_readonly(self, **kwargs):
purchase = self.raw_value
if not purchase:
return ''
return tags.link_to(purchase, self.request.route_url('purchases.view', uuid=purchase.uuid))

View file

@ -0,0 +1,15 @@
## -*- coding: utf-8 -*-
<%inherit file="/newbatch/create.mako" />
<%def name="head_tags()">
${parent.head_tags()}
<script type="text/javascript">
$(function() {
$('.field-wrapper.mode select').selectmenu();
});
</script>
</%def>
${parent.body()}

View file

@ -74,11 +74,13 @@ class PurchaseBatchView(BatchMasterView):
g.filters['complete'].default_verb = 'is_true' g.filters['complete'].default_verb = 'is_true'
g.date_ordered.set(label="Ordered") g.date_ordered.set(label="Ordered")
g.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.PURCHASE_BATCH_MODE))
def configure_grid(self, g): def configure_grid(self, g):
g.configure( g.configure(
include=[ include=[
g.id, g.id,
g.mode,
g.vendor, g.vendor,
g.buyer, g.buyer,
g.date_ordered, g.date_ordered,
@ -90,6 +92,8 @@ class PurchaseBatchView(BatchMasterView):
def _preconfigure_fieldset(self, fs): def _preconfigure_fieldset(self, fs):
super(PurchaseBatchView, self)._preconfigure_fieldset(fs) super(PurchaseBatchView, self)._preconfigure_fieldset(fs)
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.PURCHASE_BATCH_MODE))
fs.purchase.set(renderer=forms.renderers.PurchaseFieldRenderer)
fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer) fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer)
fs.buyer.set(renderer=forms.renderers.EmployeeFieldRenderer) fs.buyer.set(renderer=forms.renderers.EmployeeFieldRenderer)
fs.po_number.set(label="PO Number") fs.po_number.set(label="PO Number")
@ -118,6 +122,8 @@ class PurchaseBatchView(BatchMasterView):
fs.configure( fs.configure(
include=[ include=[
fs.id, fs.id,
fs.mode,
fs.purchase,
fs.store, fs.store,
fs.vendor, fs.vendor,
fs.vendor_email, fs.vendor_email,
@ -136,6 +142,7 @@ class PurchaseBatchView(BatchMasterView):
]) ])
if self.creating: if self.creating:
del fs.purchase
del fs.po_total del fs.po_total
del fs.complete del fs.complete
del fs.vendor_email del fs.vendor_email
@ -159,10 +166,36 @@ class PurchaseBatchView(BatchMasterView):
# default order date is today # default order date is today
fs.model.date_ordered = localtime(self.rattail_config).date() fs.model.date_ordered = localtime(self.rattail_config).date()
# TODO: temp hack until we support more modes
modes = dict(self.enum.PURCHASE_BATCH_MODE)
del modes[self.enum.PURCHASE_BATCH_MODE_RECEIVING]
del modes[self.enum.PURCHASE_BATCH_MODE_COSTING]
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(modes))
elif self.editing: elif self.editing:
fs.mode.set(readonly=True)
fs.store.set(readonly=True) fs.store.set(readonly=True)
fs.vendor.set(readonly=True) fs.vendor.set(readonly=True)
def get_batch_kwargs(self, batch):
kwargs = super(PurchaseBatchView, self).get_batch_kwargs(batch)
kwargs['mode'] = batch.mode
if batch.store:
kwargs['store'] = batch.store
elif batch.store_uuid:
kwargs['store_uuid'] = batch.store_uuid
if batch.vendor:
kwargs['vendor'] = batch.vendor
elif batch.vendor_uuid:
kwargs['vendor_uuid'] = batch.vendor_uuid
if batch.buyer:
kwargs['buyer'] = batch.buyer
elif batch.buyer_uuid:
kwargs['buyer_uuid'] = batch.buyer_uuid
kwargs['date_ordered'] = batch.date_ordered
kwargs['po_number'] = batch.po_number
return kwargs
def template_kwargs_view(self, **kwargs): def template_kwargs_view(self, **kwargs):
kwargs = super(PurchaseBatchView, self).template_kwargs_view(**kwargs) kwargs = super(PurchaseBatchView, self).template_kwargs_view(**kwargs)
vendor = kwargs['batch'].vendor vendor = kwargs['batch'].vendor
@ -289,10 +322,9 @@ class PurchaseBatchView(BatchMasterView):
row.removed = True row.removed = True
return self.redirect(self.get_action_url('view', row.batch)) return self.redirect(self.get_action_url('view', row.batch))
# TODO: redirect to new purchase... def get_execute_success_url(self, batch, result, **kwargs):
# def get_execute_success_url(self, batch, result, **kwargs): # redirect to associated purchase
# # return self.get_action_url('view', batch) return self.request.route_url('purchases.view', uuid=batch.purchase_uuid)
# return
def order_form(self): def order_form(self):
""" """

View file

@ -30,12 +30,29 @@ from rattail import enum
from rattail.db import model from rattail.db import model
import formalchemy as fa import formalchemy as fa
from webhelpers.html import HTML, tags
from tailbone import forms from tailbone import forms
from tailbone.db import Session from tailbone.db import Session
from tailbone.views import MasterView from tailbone.views import MasterView
class BatchesFieldRenderer(fa.FieldRenderer):
def render_readonly(self, **kwargs):
batches = self.raw_value
if not batches:
return ''
def render(batch):
return tags.link_to('{} ({})'.format(batch.id_str, enum.PURCHASE_BATCH_MODE[batch.mode]),
self.request.route_url('purchases.batch.view', uuid=batch.uuid))
enum = self.request.rattail_config.get_enum()
items = [HTML.tag('li', c=render(batch)) for batch in batches]
return HTML.tag('ul', c=items)
class PurchaseView(MasterView): class PurchaseView(MasterView):
""" """
Master view for purchase orders. Master view for purchase orders.
@ -90,6 +107,7 @@ class PurchaseView(MasterView):
readonly=True) readonly=True)
fs.po_number.set(label="PO Number") fs.po_number.set(label="PO Number")
fs.po_total.set(label="PO Total") fs.po_total.set(label="PO Total")
fs.batches.set(renderer=BatchesFieldRenderer)
def configure_fieldset(self, fs): def configure_fieldset(self, fs):
fs.configure( fs.configure(
@ -103,6 +121,7 @@ class PurchaseView(MasterView):
fs.status, fs.status,
fs.created, fs.created,
fs.created_by, fs.created_by,
fs.batches,
]) ])
def get_parent(self, item): def get_parent(self, item):