diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index a495c79..6b41d24 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -540,7 +540,7 @@ class ProductImporter(FromCOREPOSAPI, corepos_importing.model.ProductImporter): return list(products.values()) def identify_product(self, corepos_product): - model = self.config.get_model() + model = self.app.model corepos_id = int(corepos_product['id']) if hasattr(self, 'core_existing'): @@ -712,7 +712,7 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp def setup(self): super().setup() - model = self.config.get_model() + model = self.app.model query = self.session.query(model.Vendor)\ .join(model.CoreVendor)\ @@ -798,7 +798,7 @@ class ProductCostImporter(FromCOREPOSAPI, corepos_importing.model.ProductCostImp if hasattr(self, 'vendors'): return self.vendors.get(corepos_id) - model = self.config.get_model() + model = self.app.model try: return self.session.query(model.Vendor)\ .join(model.CoreVendor)\ diff --git a/rattail_corepos/importing/corepos/db.py b/rattail_corepos/importing/corepos/db.py index 91d5fe6..0ff5ce5 100644 --- a/rattail_corepos/importing/corepos/db.py +++ b/rattail_corepos/importing/corepos/db.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -32,11 +32,7 @@ from collections import OrderedDict import sqlalchemy as sa from sqlalchemy import orm -from corepos.db.office_op import model as corepos, Session as CoreSession -from corepos.db.office_trans import model as coretrans, Session as CoreTransSession - from rattail import importing -from rattail.gpc import GPC from rattail.db.util import normalize_full_name from rattail_corepos import importing as corepos_importing @@ -58,13 +54,16 @@ class FromCOREPOSToRattail(importing.FromSQLAlchemyHandler, importing.ToRattailH return "CORE-POS (DB/{})".format(self.corepos_dbkey) def make_host_session(self): + corepos = self.app.get_corepos_handler() # session type depends on the --corepos-dbtype arg if self.corepos_dbtype == 'office_trans': - return CoreTransSession(bind=self.config.coretrans_engines[self.corepos_dbkey]) + return corepos.make_session_office_trans( + bind=self.config.coretrans_engines[self.corepos_dbkey]) # assume office_op by default - return CoreSession(bind=self.config.corepos_engines[self.corepos_dbkey]) + return corepos.make_session_office_op( + bind=self.config.corepos_engines[self.corepos_dbkey]) def get_importers(self): importers = OrderedDict() @@ -120,7 +119,13 @@ class StoreImporter(FromCOREPOS, corepos_importing.model.StoreImporter): """ Importer for store data from CORE POS. """ - host_model_class = corepos.Store + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Store + key = 'corepos_id' supported_fields = [ 'corepos_id', @@ -140,7 +145,13 @@ class EmployeeImporter(FromCOREPOS, corepos_importing.model.EmployeeImporter): """ Importer for employee data from CORE POS. """ - host_model_class = corepos.Employee + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Employee + key = 'corepos_number' supported_fields = [ 'corepos_number', @@ -164,7 +175,13 @@ class CustomerImporter(FromCOREPOS, corepos_importing.model.CustomerImporter): """ Importer for customer data from CORE POS. """ - host_model_class = corepos.MemberInfo + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.MemberInfo + key = 'corepos_card_number' supported_fields = [ 'corepos_card_number', @@ -275,7 +292,13 @@ class MemberImporter(FromCOREPOS, corepos_importing.model.MemberImporter): """ Importer for member data from CORE POS. """ - host_model_class = corepos.MemberInfo + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.MemberInfo + # TODO use this key instead #key = 'corepos_card_number' key = 'number' @@ -407,7 +430,13 @@ class TaxImporter(FromCOREPOS, corepos_importing.model.TaxImporter): """ Importer for tax data from CORE POS. """ - host_model_class = corepos.TaxRate + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.TaxRate + key = 'corepos_id' supported_fields = [ 'corepos_id', @@ -429,7 +458,13 @@ class TenderImporter(FromCOREPOS, corepos_importing.model.TenderImporter): """ Importer for tender data from CORE POS. """ - host_model_class = corepos.Tender + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Tender + key = 'corepos_id' supported_fields = [ 'corepos_id', @@ -449,7 +484,13 @@ class VendorImporter(FromCOREPOS, corepos_importing.model.VendorImporter): """ Importer for vendor data from CORE POS. """ - host_model_class = corepos.Vendor + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Vendor + key = 'corepos_id' supported_fields = [ 'corepos_id', @@ -467,7 +508,7 @@ class VendorImporter(FromCOREPOS, corepos_importing.model.VendorImporter): """ # 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() + model = self.app.model # first get default query query = super().cache_query() @@ -502,7 +543,13 @@ class DepartmentImporter(FromCOREPOS, corepos_importing.model.DepartmentImporter """ Importer for department data from CORE POS. """ - host_model_class = corepos.Department + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Department + key = 'corepos_number' supported_fields = [ 'corepos_number', @@ -526,7 +573,13 @@ class SubdepartmentImporter(FromCOREPOS, corepos_importing.model.SubdepartmentIm """ Importer for subdepartment data from CORE POS. """ - host_model_class = corepos.Subdepartment + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Subdepartment + key = 'corepos_number' supported_fields = [ 'corepos_number', @@ -548,7 +601,13 @@ class ProductImporter(FromCOREPOS, corepos_importing.model.ProductImporter): """ Importer for product data from CORE POS. """ - host_model_class = corepos.Product + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.Product + key = 'corepos_id' supported_fields = [ 'corepos_id', @@ -579,6 +638,8 @@ class ProductImporter(FromCOREPOS, corepos_importing.model.ProductImporter): def setup(self): super().setup() + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() if self.fields_active(self.sale_price_fields): self.core_batch_items = {} @@ -588,11 +649,11 @@ class ProductImporter(FromCOREPOS, corepos_importing.model.ProductImporter): # determine which would "win" but not clear what sort # order should be used, e.g. CORE does not seem to use one today = self.app.today() - batches = self.host_session.query(corepos.Batch)\ - .filter(corepos.Batch.start_date <= today)\ - .filter(corepos.Batch.end_date >= today)\ - .filter(corepos.Batch.discount_type > 0)\ - .options(orm.joinedload(corepos.Batch.items))\ + batches = self.host_session.query(op_model.Batch)\ + .filter(op_model.Batch.start_date <= today)\ + .filter(op_model.Batch.end_date >= today)\ + .filter(op_model.Batch.discount_type > 0)\ + .options(orm.joinedload(op_model.Batch.items))\ .all() def cache(batch, i): @@ -620,7 +681,7 @@ class ProductImporter(FromCOREPOS, corepos_importing.model.ProductImporter): def normalize_host_object(self, product): try: - upc = GPC(product.upc, calc_check_digit='upc') + upc = self.app.make_gpc(product.upc, calc_check_digit='upc') except (TypeError, ValueError): log.debug("CORE POS product has invalid UPC: %s", product.upc) if len(self.key) == 1 and self.key[0] == 'upc': @@ -691,7 +752,13 @@ class ProductCostImporter(FromCOREPOS, corepos_importing.model.ProductCostImport """ Importer for product cost data from CORE POS API. """ - host_model_class = corepos.VendorItem + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + op_model = corepos.get_model_office_op() + return op_model.VendorItem + key = ('corepos_vendor_id', 'corepos_sku') supported_fields = [ 'corepos_vendor_id', @@ -731,7 +798,7 @@ class ProductCostImporter(FromCOREPOS, corepos_importing.model.ProductCostImport if hasattr(self, 'vendors_by_corepos_id'): return self.vendors_by_corepos_id.get(corepos_id) - model = self.config.get_model() + model = self.app.model try: return self.session.query(model.Vendor)\ .join(model.CoreVendor)\ @@ -798,7 +865,13 @@ class MemberEquityPaymentImporter(FromCOREPOS, corepos_importing.model.MemberEqu """ Imports equity payment data from CORE-POS """ - host_model_class = coretrans.StockPurchase + + @property + def host_model_class(self): + corepos = self.app.get_corepos_handler() + trans_model = corepos.get_model_office_trans() + return trans_model.StockPurchase + key = 'uuid' supported_fields = [ 'uuid', diff --git a/rattail_corepos/importing/model.py b/rattail_corepos/importing/model.py index bf301e0..0eebabe 100644 --- a/rattail_corepos/importing/model.py +++ b/rattail_corepos/importing/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -27,7 +27,6 @@ Rattail model importer extensions, for CORE-POS integration import decimal from rattail import importing -from rattail.util import pretty_quantity ############################## @@ -44,7 +43,7 @@ class PersonImporter(importing.model.PersonImporter): def cache_query(self): query = super().cache_query() - model = self.config.get_model() + model = self.app.model # we want to ignore people with no CORE ID, if that's (part of) our key if 'corepos_customer_id' in self.key: @@ -177,7 +176,7 @@ class ProductImporter(importing.model.ProductImporter): def cache_query(self): query = super().cache_query() - model = self.config.get_model() + model = self.app.model # we want to ignore products with no CORE ID, if that's (part of) our key if 'corepos_id' in self.key: @@ -219,9 +218,10 @@ class ProductImporter(importing.model.ProductImporter): uom_code = self.get_uom_code(uom_abbrev) or self.enum.UNIT_OF_MEASURE_NONE if unit_size is not None and uom_abbrev is not None: - size = "{} {}".format(pretty_quantity(unit_size), uom_abbrev) + size = self.app.render_quantity(unit_size) + size = f"{size} {uom_abbrev}" elif unit_size is not None: - size = pretty_quantity(unit_size) + size = self.app.render_quantity(unit_size) elif uom_abbrev is not None: size = uom_abbrev else: @@ -247,7 +247,7 @@ class ProductCostImporter(importing.model.ProductCostImporter): def cache_query(self): query = super().cache_query() - model = self.config.get_model() + model = self.app.model # we want to ignore items with no CORE ID, if that's (part of) our key if 'corepos_id' in self.key: diff --git a/rattail_corepos/importing/versions.py b/rattail_corepos/importing/versions.py index 463c2d5..ca1b15c 100644 --- a/rattail_corepos/importing/versions.py +++ b/rattail_corepos/importing/versions.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -51,7 +51,7 @@ class CorePersonImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CorePerson @@ -59,7 +59,7 @@ class CoreEmployeeImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreEmployee @@ -67,7 +67,7 @@ class CoreCustomerImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreCustomer @@ -82,7 +82,7 @@ class CoreMemberImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreMember @@ -90,7 +90,7 @@ class CoreMemberEquityPaymentImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreMemberEquityPayment @@ -98,7 +98,7 @@ class CoreStoreImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreStore @@ -106,7 +106,7 @@ class CoreDepartmentImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreDepartment @@ -114,7 +114,7 @@ class CoreSubdepartmentImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreSubdepartment @@ -122,7 +122,7 @@ class CoreVendorImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreVendor @@ -130,5 +130,5 @@ class CoreProductImporter(base.VersionImporter): @property def host_model_class(self): - model = self.config.get_model() + model = self.app.model return model.CoreProduct