From 8037de7efe61379207072a3fd17e03058e1a595b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 15 Jul 2020 21:19:27 -0500 Subject: [PATCH] Add support for importing product last sold from CORE API --- rattail_corepos/importing/corepos/api.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index 25e2c48..603d0ef 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -37,6 +37,7 @@ from rattail import importing from rattail.db import model from rattail.gpc import GPC from rattail.util import OrderedDict +from rattail.time import localtime, make_utc from rattail.db.util import normalize_full_name from rattail_corepos import importing as corepos_importing from rattail_corepos.corepos.util import get_core_members @@ -61,8 +62,15 @@ class FromCOREPOSToRattail(importing.ToRattailHandler): importers['Subdepartment'] = SubdepartmentImporter importers['Vendor'] = VendorImporter importers['Product'] = ProductImporter + importers['ProductMovement'] = ProductMovementImporter return importers + def get_default_keys(self): + keys = super(FromCOREPOSToRattail, self).get_default_keys() + if 'ProductMovement' in keys: + keys.remove('ProductMovement') + return keys + class FromCOREPOSAPI(importing.Importer): """ @@ -488,6 +496,35 @@ class ProductImporter(FromCOREPOSAPI, corepos_importing.model.ProductImporter): } +class ProductMovementImporter(FromCOREPOSAPI, corepos_importing.model.ProductImporter): + """ + Importer for product movement data from CORE POS API. + """ + key = 'corepos_id' + supported_fields = [ + 'corepos_id', + 'last_sold', + ] + allow_create = False + allow_delete = False + + def get_host_objects(self): + return self.api.get_products() + + def normalize_host_object(self, product): + + last_sold = None + if 'last_sold' in product: + last_sold = datetime.datetime.strptime(product['last_sold'], '%Y-%m-%d %H:%M:%S') + last_sold = localtime(self.config, last_sold) + last_sold = make_utc(last_sold) + + return { + 'corepos_id': int(product['id']), + 'last_sold': last_sold, + } + + class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter): """ Importer for member data from CORE POS API.