Add "most of" support for truck dump receiving
still not complete, but conceptually it sort of is...
This commit is contained in:
parent
805a1afa3f
commit
cd7922f204
8 changed files with 368 additions and 76 deletions
|
@ -48,6 +48,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
model_row_class = model.PurchaseBatchRow
|
||||
default_handler_spec = 'rattail.batch.purchase:PurchaseBatchHandler'
|
||||
supports_new_product = False
|
||||
cloneable = True
|
||||
|
||||
grid_columns = [
|
||||
'id',
|
||||
|
@ -513,22 +514,33 @@ class PurchasingBatchView(BatchMasterView):
|
|||
kwargs = super(PurchasingBatchView, self).get_batch_kwargs(batch, mobile=mobile)
|
||||
kwargs['mode'] = self.batch_mode
|
||||
kwargs['truck_dump'] = batch.truck_dump
|
||||
kwargs['invoice_parser_key'] = batch.invoice_parser_key
|
||||
|
||||
if batch.store:
|
||||
kwargs['store'] = batch.store
|
||||
elif batch.store_uuid:
|
||||
kwargs['store_uuid'] = batch.store_uuid
|
||||
|
||||
if batch.truck_dump_batch:
|
||||
kwargs['truck_dump_batch'] = batch.truck_dump_batch
|
||||
elif batch.truck_dump_batch_uuid:
|
||||
kwargs['truck_dump_batch_uuid'] = batch.truck_dump_batch_uuid
|
||||
|
||||
if batch.vendor:
|
||||
kwargs['vendor'] = batch.vendor
|
||||
elif batch.vendor_uuid:
|
||||
kwargs['vendor_uuid'] = batch.vendor_uuid
|
||||
|
||||
if batch.department:
|
||||
kwargs['department'] = batch.department
|
||||
elif batch.department_uuid:
|
||||
kwargs['department_uuid'] = batch.department_uuid
|
||||
|
||||
if batch.buyer:
|
||||
kwargs['buyer'] = batch.buyer
|
||||
elif batch.buyer_uuid:
|
||||
kwargs['buyer_uuid'] = batch.buyer_uuid
|
||||
|
||||
kwargs['po_number'] = batch.po_number
|
||||
kwargs['po_total'] = batch.po_total
|
||||
|
||||
|
@ -600,7 +612,9 @@ class PurchasingBatchView(BatchMasterView):
|
|||
def row_grid_extra_class(self, row, i):
|
||||
if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
|
||||
return 'warning'
|
||||
if row.status_code in (row.STATUS_INCOMPLETE, row.STATUS_ORDERED_RECEIVED_DIFFER):
|
||||
if row.status_code in (row.STATUS_INCOMPLETE,
|
||||
row.STATUS_ORDERED_RECEIVED_DIFFER,
|
||||
row.STATUS_TRUCKDUMP_UNCLAIMED):
|
||||
return 'notice'
|
||||
|
||||
def configure_row_form(self, f):
|
||||
|
|
|
@ -28,17 +28,19 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
import re
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail import pod
|
||||
from rattail.db import model, api
|
||||
from rattail.gpc import GPC
|
||||
from rattail.util import pretty_quantity, prettify
|
||||
from rattail.vendors.invoices import iter_invoice_parsers, require_invoice_parser
|
||||
|
||||
import colander
|
||||
from deform import widget as dfwidget
|
||||
from pyramid import httpexceptions
|
||||
from webhelpers2.html import tags
|
||||
from webhelpers2.html import tags, HTML
|
||||
|
||||
from tailbone import forms, grids
|
||||
from tailbone.views.purchasing import PurchasingBatchView
|
||||
|
@ -96,9 +98,8 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
model_title = "Receiving Batch"
|
||||
model_title_plural = "Receiving Batches"
|
||||
index_title = "Receiving"
|
||||
creatable = False
|
||||
downloadable = True
|
||||
rows_editable = True
|
||||
rows_deletable = False
|
||||
mobile_creatable = True
|
||||
mobile_rows_filterable = True
|
||||
mobile_rows_creatable = True
|
||||
|
@ -107,6 +108,11 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
allow_from_scratch = True
|
||||
allow_truck_dump = False
|
||||
|
||||
labels = {
|
||||
'truck_dump_batch': "Truck Dump Parent",
|
||||
'invoice_parser_key': "Invoice Parser",
|
||||
}
|
||||
|
||||
grid_columns = [
|
||||
'id',
|
||||
'vendor',
|
||||
|
@ -123,9 +129,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
form_fields = [
|
||||
'id',
|
||||
'batch_type',
|
||||
'store',
|
||||
'vendor',
|
||||
'truck_dump',
|
||||
'truck_dump_children',
|
||||
'truck_dump_batch',
|
||||
'invoice_file',
|
||||
'invoice_parser_key',
|
||||
'department',
|
||||
'purchase',
|
||||
'vendor_email',
|
||||
|
@ -143,6 +154,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'created',
|
||||
'created_by',
|
||||
'status_code',
|
||||
'rowcount',
|
||||
'complete',
|
||||
'executed',
|
||||
'executed_by',
|
||||
|
@ -203,12 +215,166 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
def batch_mode(self):
|
||||
return self.enum.PURCHASE_BATCH_MODE_RECEIVING
|
||||
|
||||
def row_editable(self, row):
|
||||
batch = row.batch
|
||||
if batch.truck_dump_batch:
|
||||
return False
|
||||
return True
|
||||
|
||||
def row_deletable(self, row):
|
||||
batch = row.batch
|
||||
if batch.truck_dump:
|
||||
return True
|
||||
return False
|
||||
|
||||
def configure_form(self, f):
|
||||
super(ReceivingBatchView, self).configure_form(f)
|
||||
batch = f.model_instance
|
||||
|
||||
# truck_dump
|
||||
if self.editing:
|
||||
f.set_readonly('truck_dump')
|
||||
# batch_type
|
||||
if self.creating:
|
||||
batch_type_values = [
|
||||
('from_scratch', "New from Scratch"),
|
||||
]
|
||||
if self.allow_truck_dump:
|
||||
batch_type_values.append(('truck_dump', "Invoice for Truck Dump"))
|
||||
f.set_widget('batch_type', forms.widgets.JQuerySelectWidget(values=batch_type_values))
|
||||
else:
|
||||
f.remove_field('batch_type')
|
||||
|
||||
# truck_dump*
|
||||
if self.allow_truck_dump:
|
||||
|
||||
# truck_dump
|
||||
if self.creating:
|
||||
f.remove_field('truck_dump')
|
||||
elif batch.truck_dump_batch:
|
||||
f.remove_field('truck_dump')
|
||||
else:
|
||||
f.set_readonly('truck_dump')
|
||||
|
||||
# truck_dump_children
|
||||
if self.viewing:
|
||||
if batch.truck_dump:
|
||||
f.set_renderer('truck_dump_children', self.render_truck_dump_children)
|
||||
else:
|
||||
f.remove_field('truck_dump_children')
|
||||
else:
|
||||
f.remove_field('truck_dump_children')
|
||||
|
||||
# truck_dump_batch
|
||||
if self.creating:
|
||||
f.replace('truck_dump_batch', 'truck_dump_batch_uuid')
|
||||
batches = self.Session.query(model.PurchaseBatch)\
|
||||
.filter(model.PurchaseBatch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING)\
|
||||
.filter(model.PurchaseBatch.truck_dump == True)\
|
||||
.filter(model.PurchaseBatch.complete == True)\
|
||||
.filter(model.PurchaseBatch.executed == None)\
|
||||
.order_by(model.PurchaseBatch.id)
|
||||
batch_values = [(b.uuid, six.text_type(b)) for b in batches]
|
||||
batch_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('truck_dump_batch_uuid', forms.widgets.JQuerySelectWidget(values=batch_values))
|
||||
f.set_label('truck_dump_batch_uuid', "Truck Dump Parent")
|
||||
elif batch.truck_dump:
|
||||
f.remove_field('truck_dump_batch')
|
||||
elif batch.truck_dump_batch:
|
||||
f.set_readonly('truck_dump_batch')
|
||||
f.set_renderer('truck_dump_batch', self.render_truck_dump_batch)
|
||||
else:
|
||||
f.remove_field('truck_dump_batch')
|
||||
|
||||
else:
|
||||
f.remove_fields('truck_dump',
|
||||
'truck_dump_children',
|
||||
'truck_dump_batch')
|
||||
|
||||
# invoice_file
|
||||
if self.creating:
|
||||
f.set_type('invoice_file', 'file')
|
||||
else:
|
||||
f.set_readonly('invoice_file')
|
||||
f.set_renderer('invoice_file', self.render_downloadable_file)
|
||||
|
||||
# invoice_parser_key
|
||||
if self.creating:
|
||||
parsers = sorted(iter_invoice_parsers(), key=lambda p: p.display)
|
||||
parser_values = [(p.key, p.display) for p in parsers]
|
||||
parser_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('invoice_parser_key', forms.widgets.JQuerySelectWidget(values=parser_values))
|
||||
else:
|
||||
f.remove_field('invoice_parser_key')
|
||||
|
||||
# store
|
||||
if self.creating:
|
||||
store = self.rattail_config.get_store(self.Session())
|
||||
f.set_widget('store_uuid', forms.widgets.ReadonlyWidget())
|
||||
f.set_default('store_uuid', store.uuid)
|
||||
f.set_hidden('store_uuid')
|
||||
|
||||
# purchase
|
||||
if self.creating:
|
||||
f.remove_field('purchase')
|
||||
|
||||
# department
|
||||
if self.creating:
|
||||
f.remove_field('department_uuid')
|
||||
|
||||
def template_kwargs_create(self, **kwargs):
|
||||
kwargs = super(ReceivingBatchView, self).template_kwargs_create(**kwargs)
|
||||
if self.allow_truck_dump:
|
||||
vmap = {}
|
||||
batches = self.Session.query(model.PurchaseBatch)\
|
||||
.filter(model.PurchaseBatch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING)\
|
||||
.filter(model.PurchaseBatch.truck_dump == True)\
|
||||
.filter(model.PurchaseBatch.complete == True)
|
||||
for batch in batches:
|
||||
vmap[batch.uuid] = batch.vendor_uuid
|
||||
kwargs['batch_vendor_map'] = vmap
|
||||
return kwargs
|
||||
|
||||
def get_batch_kwargs(self, batch, mobile=False):
|
||||
kwargs = super(ReceivingBatchView, self).get_batch_kwargs(batch, mobile=mobile)
|
||||
if not mobile:
|
||||
batch_type = self.request.POST['batch_type']
|
||||
if batch_type == 'from_scratch':
|
||||
kwargs.pop('truck_dump_batch', None)
|
||||
kwargs.pop('truck_dump_batch_uuid', None)
|
||||
elif batch_type == 'truck_dump':
|
||||
pass
|
||||
else:
|
||||
raise NotImplementedError
|
||||
return kwargs
|
||||
|
||||
def delete_instance(self, batch):
|
||||
"""
|
||||
Delete all data (files etc.) for the batch.
|
||||
"""
|
||||
truck_dump = batch.truck_dump_batch
|
||||
if batch.truck_dump:
|
||||
for child in batch.truck_dump_children:
|
||||
self.delete_instance(child)
|
||||
super(ReceivingBatchView, self).delete_instance(batch)
|
||||
if truck_dump:
|
||||
self.handler.refresh(truck_dump)
|
||||
|
||||
def render_truck_dump_batch(self, batch, field):
|
||||
truck_dump = batch.truck_dump_batch
|
||||
if not truck_dump:
|
||||
return ""
|
||||
text = six.text_type(truck_dump)
|
||||
url = self.request.route_url('receiving.view', uuid=truck_dump.uuid)
|
||||
return tags.link_to(text, url)
|
||||
|
||||
def render_truck_dump_children(self, batch, field):
|
||||
children = batch.truck_dump_children
|
||||
if not children:
|
||||
return ""
|
||||
items = []
|
||||
for child in children:
|
||||
text = six.text_type(child)
|
||||
url = self.request.route_url('receiving.view', uuid=child.uuid)
|
||||
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
|
||||
return HTML.tag('ul', c=items)
|
||||
|
||||
def render_mobile_listitem(self, batch, i):
|
||||
title = "({}) {} for ${:0,.2f} - {}, {}".format(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue