From d00e3b6312cf51e036e99dd2ba17b059446b709c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 31 Mar 2020 23:09:35 -0500 Subject: [PATCH] Provide fall back date when sorting, to avoid `None` --- .../corepos/importing/db/exporters/catapult_inventory.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py index ae378fc..090e16d 100644 --- a/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py +++ b/rattail_corepos/corepos/importing/db/exporters/catapult_inventory.py @@ -24,6 +24,7 @@ CORE-POS -> Catapult Inventory Workbook """ +import datetime import logging from sqlalchemy.exc import ProgrammingError @@ -117,6 +118,9 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo def setup(self): super(InventoryItemImporter, self).setup() + # this is used for sorting, when a value has no date + self.old_date = datetime.date(1900, 1, 1) + self.ignored_upcs = self.config.getlist( 'corepos', 'exporting.catapult_inventory.ignored_upcs') @@ -341,7 +345,7 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo product.upc, len(vendor_items), product) # sort the list so most recently modified is first - vendor_items.sort(key=lambda item: item.modified, + vendor_items.sort(key=lambda item: item.modified or self.old_date, reverse=True) # use the "first" vendor item available