Add base master4 batch view

This commit is contained in:
Lance Edgar 2018-02-03 16:24:54 -06:00
parent 63290154eb
commit 410ee8eb65
2 changed files with 128 additions and 0 deletions

View file

@ -29,3 +29,4 @@ from __future__ import unicode_literals, absolute_import
from .core import BatchMasterView, FileBatchMasterView
from .core2 import BatchMasterView2, FileBatchMasterView2
from .core3 import BatchMasterView3, FileBatchMasterView3
from .core4 import BatchMasterView4, FileBatchMasterView4

View file

@ -0,0 +1,127 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Base views for maintaining batches
"""
from __future__ import unicode_literals, absolute_import
from tailbone.views import MasterView4
from tailbone.views.batch import BatchMasterView3, FileBatchMasterView3
class BatchMasterView4(MasterView4, BatchMasterView3):
"""
Base class for all "batch master" views
"""
row_labels = {
'status_code': "Status",
}
def configure_mobile_form(self, f):
super(BatchMasterView4, self).configure_mobile_form(f)
batch = f.model_instance
if self.creating:
f.remove_fields('id',
'rowcount',
'created',
'created_by',
'cognized',
'cognized_by',
'executed',
'executed_by',
'purge')
else: # not creating
if not batch.executed:
f.remove_fields('executed',
'executed_by')
if not batch.complete:
f.remove_field('complete')
def save_mobile_create_form(self, form):
self.before_create(form)
session = self.Session()
with session.no_autoflush:
# transfer form data to batch instance
batch = self.objectify(form, self.form_deserialized)
# current user is batch creator
batch.created_by = self.request.user
# TODO: is this still necessary with colander?
# destroy initial batch and re-make using handler
kwargs = self.get_batch_kwargs(batch)
if batch in session:
session.expunge(batch)
batch = self.handler.make_batch(session, **kwargs)
session.flush()
return batch
def configure_row_form(self, f):
super(BatchMasterView4, self).configure_row_form(f)
# sequence
f.set_readonly('sequence')
# status_code
if self.model_row_class:
f.set_enum('status_code', self.model_row_class.STATUS)
f.set_renderer('status_code', self.render_row_status)
f.set_readonly('status_code')
f.set_label('status_code', "Status")
def configure_mobile_row_form(self, f):
super(BatchMasterView4, self).configure_mobile_row_form(f)
# sequence
f.set_readonly('sequence')
# status_code
if self.model_row_class:
f.set_enum('status_code', self.model_row_class.STATUS)
f.set_renderer('status_code', self.render_row_status)
f.set_readonly('status_code')
f.set_label('status_code', "Status")
# NOTE: must override default logic here, by doing nothing
def before_create_row(self, form):
pass
def save_create_row_form(self, form):
batch = self.get_instance()
row = self.objectify(form, self.form_deserialized)
self.handler.add_row(batch, row)
self.Session.flush()
return row
class FileBatchMasterView4(BatchMasterView4, FileBatchMasterView3):
"""
Base class for all file-based "batch master" views
"""