Add basic support for receiving from multiple invoice files
This commit is contained in:
parent
2b7ebedb22
commit
dfa4178204
10 changed files with 295 additions and 40 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -26,6 +26,7 @@ Views for 'receiving' (purchasing) batches
|
|||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
import re
|
||||
import decimal
|
||||
import logging
|
||||
|
@ -551,6 +552,15 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
if not self.editing:
|
||||
f.remove_field('order_quantities_known')
|
||||
|
||||
# multiple invoice files (if applicable)
|
||||
if (not self.creating
|
||||
and batch.get_param('receiving_workflow') == 'from_multi_invoice'):
|
||||
|
||||
if 'invoice_files' not in f:
|
||||
f.insert_before('invoice_file', 'invoice_files')
|
||||
f.set_renderer('invoice_files', self.render_invoice_files)
|
||||
f.set_readonly('invoice_files', True)
|
||||
|
||||
# invoice totals
|
||||
f.set_label('invoice_total', "Invoice Total (Orig.)")
|
||||
f.set_label('invoice_total_calculated', "Invoice Total (Calc.)")
|
||||
|
@ -584,6 +594,17 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'invoice_date',
|
||||
'invoice_number')
|
||||
|
||||
elif workflow == 'from_multi_invoice':
|
||||
if 'invoice_files' not in f:
|
||||
f.insert_before('invoice_file', 'invoice_files')
|
||||
f.set_type('invoice_files', 'multi_file')
|
||||
f.set_required('invoice_parser_key')
|
||||
f.remove('truck_dump_batch_uuid',
|
||||
'po_number',
|
||||
'invoice_file',
|
||||
'invoice_date',
|
||||
'invoice_number')
|
||||
|
||||
elif workflow == 'from_po':
|
||||
f.remove('truck_dump_batch_uuid',
|
||||
'date_ordered',
|
||||
|
@ -620,12 +641,31 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'invoice_date',
|
||||
'invoice_number')
|
||||
|
||||
def render_invoice_files(self, batch, field):
|
||||
datadir = self.batch_handler.datadir(batch)
|
||||
items = []
|
||||
for filename in batch.get_param('invoice_files', []):
|
||||
path = os.path.join(datadir, filename)
|
||||
url = self.get_action_url('download', batch,
|
||||
_query={'filename': filename})
|
||||
link = self.render_file_field(path, url)
|
||||
items.append(HTML.tag('li', c=[link]))
|
||||
return HTML.tag('ul', c=items)
|
||||
|
||||
def render_receiving_workflow(self, batch, field):
|
||||
key = self.request.matchdict['workflow_key']
|
||||
info = self.handler.receiving_workflow_info(key)
|
||||
if info:
|
||||
return info['display']
|
||||
|
||||
def get_visible_params(self, batch):
|
||||
params = super(ReceivingBatchView, self).get_visible_params(batch)
|
||||
|
||||
# remove this since we show it separately
|
||||
params.pop('invoice_files', None)
|
||||
|
||||
return params
|
||||
|
||||
def template_kwargs_create(self, **kwargs):
|
||||
kwargs = super(ReceivingBatchView, self).template_kwargs_create(**kwargs)
|
||||
if self.handler.allow_truck_dump_receiving():
|
||||
|
@ -655,6 +695,8 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
kwargs.pop('truck_dump_batch_uuid', None)
|
||||
elif batch_type == 'from_invoice':
|
||||
pass
|
||||
elif batch_type == 'from_multi_invoice':
|
||||
pass
|
||||
elif batch_type == 'from_po':
|
||||
# TODO: how to best handle this field? this doesn't seem flexible
|
||||
kwargs['purchase_key'] = batch.purchase_uuid
|
||||
|
@ -1952,6 +1994,9 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_invoice',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_multi_invoice',
|
||||
'type': bool},
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_purchase_order',
|
||||
'type': bool},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue