Try to be smarter about the "size" column for Catapult export

This commit is contained in:
Lance Edgar 2020-04-15 17:47:33 -05:00
parent 190ba506e5
commit 20e8aa97ca

View file

@ -26,6 +26,7 @@ CORE-POS -> Catapult Inventory Workbook
import re import re
import datetime import datetime
import decimal
import logging import logging
from sqlalchemy.exc import ProgrammingError from sqlalchemy.exc import ProgrammingError
@ -407,13 +408,25 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo
if self.exclude_missing_department: if self.exclude_missing_department:
return return
size = "{} {}".format((product.size or '').strip(), # size may come from one of two fields, or combination thereof
(product.unit_of_measure or '').strip()) pack_size = (product.size or '').strip()
size = size.strip() uom = (product.unit_of_measure or '').strip()
numeric_pack = False
if pack_size:
try:
decimal.Decimal(pack_size)
except decimal.InvalidOperation:
pass
else:
numeric_pack = True
if numeric_pack:
size = "{} {}".format(pack_size, uom).strip()
else:
size = pack_size or uom or None
# TODO: this logic may actually be client-specific? i just happened to # TODO: this logic may actually be client-specific? i just happened to
# find some of these chars in a client DB and needed to avoid them, b/c # find some null chars in a client DB and needed to avoid them, b/c the
# the openpyxl lib said IllegalCharacterError # openpyxl lib said IllegalCharacterError
if '\x00' in size: if size is not None and '\x00' in size:
logger = log.warning if self.warn_size_null_byte else log.debug logger = log.warning if self.warn_size_null_byte else log.debug
logger("product %s has null byte in size field: %s", logger("product %s has null byte in size field: %s",
product.upc, product) product.upc, product)