Add very basic support for CORE -> Catapult Inventory Workbook export
more fields to come
This commit is contained in:
parent
4f300f1036
commit
3d145d0314
|
@ -0,0 +1,103 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 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 -> Catapult Inventory Workbook
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy import orm
|
||||
|
||||
from corepos.db.office_op import model as corepos
|
||||
|
||||
from rattail.util import OrderedDict
|
||||
from rattail.importing.handlers import ToFileHandler
|
||||
from rattail_corepos.corepos.importing.db.corepos import FromCoreHandler, FromCore
|
||||
from rattail_onager.catapult.importing import inventory as catapult_importing
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FromCoreToCatapult(FromCoreHandler, ToFileHandler):
|
||||
"""
|
||||
Handler for CORE -> Catapult (Inventory Workbook)
|
||||
"""
|
||||
host_title = "CORE-POS"
|
||||
local_title = "Catapult (Inventory Workbook)"
|
||||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['InventoryItem'] = InventoryItemImporter
|
||||
return importers
|
||||
|
||||
|
||||
class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImporter):
|
||||
"""
|
||||
Inventory Item data importer.
|
||||
"""
|
||||
host_model_class = corepos.Product
|
||||
supported_fields = [
|
||||
'item_id',
|
||||
'dept_id',
|
||||
'dept_name',
|
||||
'receipt_alias',
|
||||
'brand',
|
||||
'item_name',
|
||||
'size',
|
||||
]
|
||||
|
||||
def query(self):
|
||||
query = self.host_session.query(corepos.Product)\
|
||||
.order_by(corepos.Product.upc)\
|
||||
.options(orm.joinedload(corepos.Product.department))
|
||||
return query
|
||||
|
||||
def normalize_host_object(self, product):
|
||||
item_id = product.upc
|
||||
|
||||
if not item_id:
|
||||
log.warning("item_id could not be determined for product %s: %s",
|
||||
product.uuid, product)
|
||||
return
|
||||
|
||||
if not item_id.isdigit():
|
||||
log.debug("item_id '%s' is not numeric for product %s: %s",
|
||||
item_id, product.uuid, product)
|
||||
return
|
||||
|
||||
department = product.department
|
||||
if not department:
|
||||
log.warning("item_id %s has no department: %s",
|
||||
item_id, product)
|
||||
return
|
||||
|
||||
return {
|
||||
'item_id': item_id,
|
||||
'dept_id': department.number,
|
||||
'dept_name': department.name,
|
||||
'receipt_alias': None, # TODO
|
||||
'brand': product.brand,
|
||||
'item_name': product.description,
|
||||
'size': product.size,
|
||||
}
|
Loading…
Reference in a new issue