From 234fd8b2e1310963f57355e9269c42d2dd603050 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 14 Jan 2020 11:54:00 -0600 Subject: [PATCH] Add support for Row Status Breakdown, for Import/Export batches --- docs/conf.py | 2 +- setup.py | 2 +- tailbone/views/batch/core.py | 11 +++++++---- tailbone/views/batch/importer.py | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7d3e5831..87de553a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -58,7 +58,7 @@ master_doc = 'index' # General information about the project. project = u'Tailbone' -copyright = u'2010 - 2018, Lance Edgar' +copyright = u'2010 - 2020, Lance Edgar' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/setup.py b/setup.py index 922f9f88..59c3ef9e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 169796f8..276bb167 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -166,19 +166,22 @@ class BatchMasterView(MasterView): kwargs['status_breakdown'] = self.make_status_breakdown(batch) return kwargs - def make_status_breakdown(self, batch): + def make_status_breakdown(self, batch, rows=None, status_enum=None): """ Returns a simple list of 2-tuples, each of which has the status display title as first member, and number of rows with that status as second member. """ breakdown = {} - for row in batch.active_rows(): + if rows is None: + rows = batch.active_rows() + for row in rows: if row.status_code is not None: if row.status_code not in breakdown: + status = status_enum or row.STATUS breakdown[row.status_code] = { 'code': row.status_code, - 'title': row.STATUS[row.status_code], + 'title': status[row.status_code], 'count': 0, } breakdown[row.status_code]['count'] += 1 diff --git a/tailbone/views/batch/importer.py b/tailbone/views/batch/importer.py index b2803183..77ebd6b4 100644 --- a/tailbone/views/batch/importer.py +++ b/tailbone/views/batch/importer.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -103,9 +103,19 @@ class ImporterBatchView(BatchMasterView): f.set_readonly('importer_key') f.set_readonly('row_table') - def make_status_breakdown(self, batch): - # TODO: should implement this, just can't use batch.data_rows apparently - pass + def make_status_breakdown(self, batch, **kwargs): + """ + Returns a simple list of 2-tuples, each of which has the status display + title as first member, and number of rows with that status as second + member. + """ + if kwargs.get('rows') is None: + self.make_row_table(batch.row_table) + kwargs['rows'] = self.Session.query(self.current_row_table).all() + kwargs.setdefault('status_enum', self.enum.IMPORTER_BATCH_ROW_STATUS) + breakdown = super(ImporterBatchView, self).make_status_breakdown( + batch, **kwargs) + return breakdown def delete_instance(self, batch): self.make_row_table(batch.row_table)