Oerhaul the Vendor import/export between Rattail and CORE

also, add new DB schema specific to this integration, to hold PKs etc.
This commit is contained in:
Lance Edgar 2020-03-04 19:05:55 -06:00
parent f9071ac6e9
commit af1e38aa18
10 changed files with 311 additions and 30 deletions

View file

@ -0,0 +1,27 @@
# -*- 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/>.
#
################################################################################
"""
Importing data into Rattail
"""
from . import model

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,18 +24,14 @@
CORE POS -> Rattail data importing
"""
from __future__ import unicode_literals, absolute_import
import decimal
import six
from corepos.db import model as corepos
from corepos.db import Session as CoreSession
from corepos.db.office_op import model as corepos, Session as CoreSession
from rattail import importing
from rattail.gpc import GPC
from rattail.util import OrderedDict
from rattail_corepos import importing as corepos_importing
class FromCOREPOSToRattail(importing.FromSQLAlchemyHandler, importing.ToRattailHandler):
@ -66,14 +62,14 @@ class FromCOREPOS(importing.FromSQLAlchemy):
"""
class VendorImporter(FromCOREPOS, importing.model.VendorImporter):
class VendorImporter(FromCOREPOS, corepos_importing.model.VendorImporter):
"""
Importer for vendor data from CORE POS.
"""
host_model_class = corepos.Vendor
key = 'id'
key = 'corepos_id'
supported_fields = [
'id',
'corepos_id',
'name',
'abbreviation',
'special_discount',
@ -82,6 +78,26 @@ class VendorImporter(FromCOREPOS, importing.model.VendorImporter):
'email_address',
]
def cache_query(self):
"""
Return the query to be used when caching "local" data.
"""
# can't just use rattail.db.model b/c the CoreVendor would normally not
# be in there! this still requires custom model to be configured though.
model = self.config.get_model()
# first get default query
query = super(VendorImporter, self).cache_query()
# maybe filter a bit, to ensure only "relevant" records are involved
if 'corepos_id' in self.key:
# note, the filter is probably redundant since we INNER JOIN on the
# extension table, and it doesn't allow null ID values. but clarity.
query = query.join(model.CoreVendor)\
.filter(model.CoreVendor.corepos_id != None)
return query
def normalize_host_object(self, vendor):
special_discount = None
@ -89,9 +105,9 @@ class VendorImporter(FromCOREPOS, importing.model.VendorImporter):
special_discount = decimal.Decimal('{:0.3f}'.format(vendor.discount_rate))
return {
'id': six.text_type(vendor.id),
'corepos_id': vendor.id,
'name': vendor.name,
'abbreviation': vendor.abbreviation,
'abbreviation': vendor.abbreviation or None,
'special_discount': special_discount,
'phone_number': vendor.phone or None,
'fax_number': vendor.fax or None,

View file

@ -0,0 +1,39 @@
# -*- 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/>.
#
################################################################################
"""
Rattail model importer extensions, for CORE-POS integration
"""
from rattail import importing
##############################
# core importer overrides
##############################
class VendorImporter(importing.model.VendorImporter):
extension_attr = '_corepos'
extension_fields = [
'corepos_id',
]