From 4cb42d06eaca163186135b552453ffd3209e94b4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 30 Mar 2020 00:07:56 -0500 Subject: [PATCH] Add support for 'alt_id' and friends, in Catapult export just the basic support here, for e.g. Zevia sodas where the single barcode matches the pack --- .../db/exporters/catapult_inventory.py | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py index d5954c1..17c2b5e 100644 --- a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py +++ b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py @@ -28,6 +28,7 @@ import logging from sqlalchemy import orm +from corepos import enum as corepos_enum from corepos.db.office_op import model as corepos from rattail.gpc import GPC @@ -86,10 +87,10 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo 'age_required', # 'location', # 'family_line', - # 'alt_id', - # 'alt_receipt_alias', - # 'alt_pkg_qty', - # 'alt_pkg_price', + 'alt_id', + 'alt_receipt_alias', + 'alt_pkg_qty', + 'alt_pkg_price', # 'auto_discount', # 'supplier_unit_id', # 'supplier_id', @@ -121,6 +122,10 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo 'corepos', 'exporting.catapult_inventory.warn_missing_department', default=True) + self.warn_truncated_receipt_alias = self.config.getbool( + 'corepos', 'exporting.catapult_inventory.warn_truncated_receipt_alias', + default=True) + def query(self): query = self.host_session.query(corepos.Product)\ .order_by(corepos.Product.upc)\ @@ -199,6 +204,30 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo # if tax_rate_ids_2 and rate.id in tax_rate_ids_2: # tax_2 += rate.rate + # no alt item by default + alt_id = None + alt_receipt_alias = None + alt_pkg_qty = None + alt_pkg_price = None + + # make an alt item, when main item has pack pricing (e.g. Zevia sodas) + # note that in this case the main item_id and alt_id are the same + if (product.quantity and product.group_price and + product.price_method == corepos_enum.PRODUCT_PRICE_METHOD_FULL_SETS): + alt_id = item_id + suffix = "{}-PK".format(product.quantity) + alt_receipt_alias = "{} {}".format(product.description, suffix) + if len(alt_receipt_alias) > 32: + logger = log.warning if self.warn_truncated_receipt_alias else log.debug + logger("alt receipt alias for %s is %s chars; must truncate: %s", + alt_id, len(alt_receipt_alias), alt_receipt_alias) + overage = len(alt_receipt_alias) - 32 + alt_receipt_alias = "{} {}".format( + product.description[:-overage], suffix) + assert len(alt_receipt_alias) == 32 + alt_pkg_qty = product.quantity + alt_pkg_price = product.group_price + return { 'item_id': item_id, 'dept_id': department.number, @@ -238,11 +267,12 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo # 'location': None, # 'family_line': None, - # TODO: does CORE have these? - # 'alt_id': None, - # 'alt_receipt_alias': None, - # 'alt_pkg_qty': None, - # 'alt_pkg_price': None, + 'alt_id': alt_id, + 'alt_receipt_alias': alt_receipt_alias, + 'alt_pkg_qty': alt_pkg_qty, + 'alt_pkg_price': alt_pkg_price, + + # TODO: does CORE have this? # 'auto_discount': None, # TODO: pretty sure CORE has these, but i'm not sure where