Add support for importing product last sold from CORE API
This commit is contained in:
parent
9f3cfa0d8e
commit
8037de7efe
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue