diff --git a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py index ccabcc2..2b363dc 100644 --- a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py +++ b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py @@ -26,6 +26,7 @@ CORE-POS -> Catapult Inventory Workbook import logging +from sqlalchemy.exc import ProgrammingError from sqlalchemy import orm from corepos import enum as corepos_enum @@ -85,7 +86,7 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo 'spec_tend_1', 'spec_tend_2', 'age_required', - # 'location', + 'location', # 'family_line', 'alt_id', 'alt_receipt_alias', @@ -138,6 +139,16 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo 'corepos', 'exporting.catapult_inventory.warn_truncated_memo', default=True) + try: + self.host_session.query(corepos.FloorSection).count() + except ProgrammingError as error: + if "doesn't exist" in str(error): + self.floor_sections_exist = False + else: + raise + else: + self.floor_sections_exist = True + def query(self): query = self.host_session.query(corepos.Product)\ .order_by(corepos.Product.upc)\ @@ -148,6 +159,9 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo .options(orm.joinedload(corepos.Product.default_vendor))\ .options(orm.joinedload(corepos.Product.scale_item))\ .options(orm.joinedload(corepos.Product.user_info)) + if self.floor_sections_exist: + query = query.options(orm.joinedload(corepos.Product.physical_location)\ + .joinedload(corepos.ProductPhysicalLocation.floor_section)) return query def normalize_host_object(self, product): @@ -230,6 +244,14 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo # if tax_rate_ids_2 and rate.id in tax_rate_ids_2: # tax_2 += rate.rate + location = None + if self.floor_sections_exist and product.physical_location and product.physical_location.floor_section: + location = product.physical_location.floor_section.name + if len(location) > 30: + log.warning("product %s has location length %s; will truncate: %s", + product.upc, len(location), location) + location = location[:30] + # no alt item (or auto discount) by default alt_id = None alt_receipt_alias = None @@ -361,9 +383,9 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo 'spec_tend_1': 'EBT' if product.foodstamp else None, 'spec_tend_2': 'WIC' if product.wicable else None, 'age_required': product.id_enforced or None, + 'location': location, # TODO: does CORE have these? - # 'location': None, # 'family_line': None, 'alt_id': alt_id,