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
This commit is contained in:
Lance Edgar 2020-03-30 00:07:56 -05:00
parent 06f40f350e
commit 4cb42d06ea

View file

@ -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