Add some CORE-specific things to vendor catalog batch view
also show vendor items as "rows" when viewing vendor
This commit is contained in:
parent
7c4edfa45f
commit
b0d6d6f2c1
81
tailbone_corepos/views/batch/vendorcatalog.py
Normal file
81
tailbone_corepos/views/batch/vendorcatalog.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Vendor Catalog batch views for CORE-POS
|
||||
"""
|
||||
|
||||
from corepos.db.office_op import model as corepos
|
||||
|
||||
from deform import widget as dfwidget
|
||||
|
||||
from tailbone.views.batch import vendorcatalog as base
|
||||
from tailbone_corepos.db import CoreOfficeSession
|
||||
|
||||
|
||||
class VendorCatalogView(base.VendorCatalogView):
|
||||
"""
|
||||
Master view for vendor catalog batches.
|
||||
"""
|
||||
|
||||
def configure_form(self, f):
|
||||
super(VendorCatalogView, self).configure_form(f)
|
||||
model = self.model
|
||||
|
||||
# replace stock 'vendor' field with id/name combo
|
||||
f.remove('vendor', 'vendor_uuid')
|
||||
f.insert_after('parser_key', 'vendor_id')
|
||||
f.insert_after('vendor_id', 'vendor_name')
|
||||
|
||||
# vendor_id
|
||||
if self.creating:
|
||||
vendors = CoreOfficeSession.query(corepos.Vendor)\
|
||||
.order_by(corepos.Vendor.name)\
|
||||
.all()
|
||||
values = [(str(vendor.id), vendor.name)
|
||||
for vendor in vendors]
|
||||
f.set_widget('vendor_id', dfwidget.SelectWidget(values=values))
|
||||
f.set_required('vendor_id')
|
||||
f.set_label('vendor_id', "Vendor")
|
||||
|
||||
# vendor_name
|
||||
if self.creating:
|
||||
f.remove('vendor_name')
|
||||
|
||||
def get_batch_kwargs(self, batch):
|
||||
kwargs = super(VendorCatalogView, self).get_batch_kwargs(batch)
|
||||
|
||||
if 'vendor_name' not in kwargs and batch.vendor_id:
|
||||
vendor = CoreOfficeSession.query(corepos.Vendor).get(batch.vendor_id)
|
||||
if vendor:
|
||||
kwargs['vendor_name'] = vendor.name
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
def defaults(config, **kwargs):
|
||||
kwargs.setdefault('VendorCatalogView', VendorCatalogView)
|
||||
base.defaults(config, **kwargs)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
defaults(config)
|
|
@ -37,7 +37,6 @@ def includeme(config):
|
|||
config.include('tailbone_corepos.views.corepos.subdepartments')
|
||||
config.include('tailbone_corepos.views.corepos.superdepartments')
|
||||
config.include('tailbone_corepos.views.corepos.vendors')
|
||||
config.include('tailbone_corepos.views.corepos.vendoritems')
|
||||
config.include('tailbone_corepos.views.corepos.origins')
|
||||
config.include('tailbone_corepos.views.corepos.products')
|
||||
config.include('tailbone_corepos.views.corepos.likecodes')
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
CORE-POS vendor item views
|
||||
"""
|
||||
|
||||
from corepos.db.office_op import model as corepos
|
||||
|
||||
from .master import CoreOfficeMasterView
|
||||
|
||||
|
||||
class VendorItemView(CoreOfficeMasterView):
|
||||
"""
|
||||
Base class for vendor iem views.
|
||||
"""
|
||||
model_class = corepos.VendorItem
|
||||
model_title = "CORE-POS Vendor Item"
|
||||
url_prefix = '/core-pos/vendor-items'
|
||||
route_prefix = 'corepos.vendor_items'
|
||||
|
||||
labels = {
|
||||
'vendor_item_id': "ID",
|
||||
'sku': "SKU",
|
||||
'vendor_id': "Vendor ID",
|
||||
'upc': "UPC",
|
||||
'vendor_department_id': "Vendor Department ID",
|
||||
'srp': "SRP",
|
||||
}
|
||||
|
||||
grid_columns = [
|
||||
'vendor_item_id',
|
||||
'sku',
|
||||
'vendor',
|
||||
'upc',
|
||||
'brand',
|
||||
'description',
|
||||
'size',
|
||||
'cost',
|
||||
'units',
|
||||
'modified',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
'vendor_item_id',
|
||||
'sku',
|
||||
'vendor_id',
|
||||
'vendor',
|
||||
'upc',
|
||||
'brand',
|
||||
'description',
|
||||
'size',
|
||||
'units',
|
||||
'cost',
|
||||
'sale_cost',
|
||||
'vendor_department_id',
|
||||
'srp',
|
||||
'modified',
|
||||
]
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(VendorItemView, self).configure_grid(g)
|
||||
|
||||
g.filters['upc'].default_active = True
|
||||
g.filters['upc'].default_verb = 'contains'
|
||||
|
||||
g.set_type('units', 'quantity')
|
||||
|
||||
g.set_sort_defaults('modified', 'desc')
|
||||
|
||||
g.set_link('vendor_item_id')
|
||||
g.set_link('sku')
|
||||
g.set_link('vendor')
|
||||
g.set_link('upc')
|
||||
g.set_link('brand')
|
||||
g.set_link('description')
|
||||
|
||||
def configure_form(self, f):
|
||||
super(VendorItemView, self).configure_form(f)
|
||||
|
||||
f.set_type('units', 'quantity')
|
||||
f.set_type('srp', 'currency')
|
||||
|
||||
f.set_readonly('vendor')
|
||||
|
||||
if self.creating:
|
||||
f.remove('vendor_item_id')
|
||||
else:
|
||||
f.set_readonly('vendor_item_id')
|
||||
|
||||
if self.creating or self.editing:
|
||||
f.remove('modified')
|
||||
else:
|
||||
f.set_readonly('modified')
|
||||
|
||||
|
||||
def defaults(config, **kwargs):
|
||||
base = globals()
|
||||
|
||||
VendorItemView = kwargs.get('VendorItemView', base['VendorItemView'])
|
||||
VendorItemView.defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
defaults(config)
|
|
@ -66,6 +66,27 @@ class VendorView(CoreOfficeMasterView):
|
|||
'notes',
|
||||
]
|
||||
|
||||
has_rows = True
|
||||
model_row_class = corepos.VendorItem
|
||||
|
||||
row_labels = {
|
||||
'vendor_item_id': "Vendor Item ID",
|
||||
'sku': "SKU",
|
||||
'upc': "UPC",
|
||||
}
|
||||
|
||||
row_grid_columns = [
|
||||
'vendor_item_id',
|
||||
'sku',
|
||||
'upc',
|
||||
'brand',
|
||||
'description',
|
||||
'size',
|
||||
'cost',
|
||||
'units',
|
||||
'modified',
|
||||
]
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(VendorView, self).configure_grid(g)
|
||||
|
||||
|
@ -90,6 +111,108 @@ class VendorView(CoreOfficeMasterView):
|
|||
return '{}/item/vendors/VendorIndexPage.php?vid={}'.format(
|
||||
office_url, vendor.id)
|
||||
|
||||
def get_row_data(self, vendor):
|
||||
return self.Session.query(corepos.VendorItem)\
|
||||
.filter(corepos.VendorItem.vendor == vendor)
|
||||
|
||||
def get_parent(self, item):
|
||||
return item.vendor
|
||||
|
||||
def configure_row_grid(self, g):
|
||||
super(VendorView, self).configure_row_grid(g)
|
||||
|
||||
g.set_type('units', 'quantity')
|
||||
g.set_sort_defaults('sku')
|
||||
|
||||
def row_view_action_url(self, item, i):
|
||||
return self.request.route_url('corepos.vendor_items.view',
|
||||
**{'vendor_id': item.vendor.id,
|
||||
'sku': item.sku})
|
||||
|
||||
|
||||
class VendorItemView(CoreOfficeMasterView):
|
||||
"""
|
||||
Base class for vendor iem views.
|
||||
"""
|
||||
model_class = corepos.VendorItem
|
||||
model_title = "CORE-POS Vendor Item"
|
||||
url_prefix = '/core-pos/vendor-items'
|
||||
route_prefix = 'corepos.vendor_items'
|
||||
|
||||
labels = {
|
||||
'vendor_item_id': "ID",
|
||||
'sku': "SKU",
|
||||
'vendor_id': "Vendor ID",
|
||||
'upc': "UPC",
|
||||
'vendor_department_id': "Vendor Department ID",
|
||||
'srp': "SRP",
|
||||
}
|
||||
|
||||
grid_columns = [
|
||||
'vendor_item_id',
|
||||
'sku',
|
||||
'vendor',
|
||||
'upc',
|
||||
'brand',
|
||||
'description',
|
||||
'size',
|
||||
'cost',
|
||||
'units',
|
||||
'modified',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
'vendor_item_id',
|
||||
'sku',
|
||||
'vendor_id',
|
||||
'vendor',
|
||||
'upc',
|
||||
'brand',
|
||||
'description',
|
||||
'size',
|
||||
'units',
|
||||
'cost',
|
||||
'sale_cost',
|
||||
'vendor_department_id',
|
||||
'srp',
|
||||
'modified',
|
||||
]
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(VendorItemView, self).configure_grid(g)
|
||||
|
||||
g.filters['upc'].default_active = True
|
||||
g.filters['upc'].default_verb = 'contains'
|
||||
|
||||
g.set_type('units', 'quantity')
|
||||
|
||||
g.set_sort_defaults('modified', 'desc')
|
||||
|
||||
g.set_link('vendor_item_id')
|
||||
g.set_link('sku')
|
||||
g.set_link('vendor')
|
||||
g.set_link('upc')
|
||||
g.set_link('brand')
|
||||
g.set_link('description')
|
||||
|
||||
def configure_form(self, f):
|
||||
super(VendorItemView, self).configure_form(f)
|
||||
|
||||
f.set_type('units', 'quantity')
|
||||
f.set_type('srp', 'currency')
|
||||
|
||||
f.set_readonly('vendor')
|
||||
|
||||
if self.creating:
|
||||
f.remove('vendor_item_id')
|
||||
else:
|
||||
f.set_readonly('vendor_item_id')
|
||||
|
||||
if self.creating or self.editing:
|
||||
f.remove('modified')
|
||||
else:
|
||||
f.set_readonly('modified')
|
||||
|
||||
|
||||
def defaults(config, **kwargs):
|
||||
base = globals()
|
||||
|
@ -97,6 +220,9 @@ def defaults(config, **kwargs):
|
|||
VendorView = kwargs.get('VendorView', base['VendorView'])
|
||||
VendorView.defaults(config)
|
||||
|
||||
VendorItemView = kwargs.get('VendorItemView', base['VendorItemView'])
|
||||
VendorItemView.defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
defaults(config)
|
||||
|
|
Loading…
Reference in a new issue