Improve email diff display for exports to CORE API 'Member.customers'
break out each subrecord into separate fields, for easier viewing
This commit is contained in:
parent
46eec6b781
commit
cc517702e1
|
@ -30,6 +30,44 @@ from rattail_corepos.corepos.util import get_core_members
|
|||
from rattail_corepos.corepos.api import make_corepos_api
|
||||
|
||||
|
||||
class ToCOREAPIHandler(importing.ImportHandler):
|
||||
"""
|
||||
Base class for handlers targeting the CORE API.
|
||||
"""
|
||||
local_key = 'corepos_api'
|
||||
generic_local_title = "CORE Office (API)"
|
||||
|
||||
@property
|
||||
def local_title(self):
|
||||
return "CORE-POS (API)"
|
||||
|
||||
def process_changes(self, changes):
|
||||
|
||||
if 'Member' in changes:
|
||||
member_changes = changes['Member']
|
||||
member_importer = self.importers['Member']
|
||||
created, updated, deleted = changes['Member']
|
||||
if updated:
|
||||
|
||||
# explode the 'customers' field so email will show
|
||||
# diffs for each subrecord field
|
||||
for update in updated:
|
||||
local_object, local_data, host_data = update
|
||||
|
||||
local_customers = local_data.pop('customers')
|
||||
for i, customer in enumerate(local_customers, 1):
|
||||
for key in customer:
|
||||
local_data[f'customers.{i}.{key}'] = customer[key]
|
||||
|
||||
host_customers = host_data.pop('customers')
|
||||
for i, customer in enumerate(host_customers, 1):
|
||||
for key in customer:
|
||||
host_data[f'customers.{i}.{key}'] = customer[key]
|
||||
|
||||
# do normal logic for the rest
|
||||
super().process_changes(changes)
|
||||
|
||||
|
||||
class ToCoreAPI(importing.Importer):
|
||||
"""
|
||||
Base class for all CORE "operational" model importers, which use the API.
|
||||
|
|
|
@ -32,26 +32,14 @@ from sqlalchemy import orm
|
|||
from rattail import importing
|
||||
from rattail.db import model
|
||||
from rattail.util import pretty_quantity
|
||||
from rattail_corepos.corepos import importing as corepos_importing
|
||||
from rattail_corepos.corepos.office import importing as corepos_importing
|
||||
from rattail_corepos.corepos.util import get_max_existing_vendor_id
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ToCOREAPIHandler(importing.ImportHandler):
|
||||
"""
|
||||
Base class for handlers targeting the CORE API.
|
||||
"""
|
||||
local_key = 'corepos_api'
|
||||
generic_local_title = "CORE Office (API)"
|
||||
|
||||
@property
|
||||
def local_title(self):
|
||||
return "CORE-POS (API)"
|
||||
|
||||
|
||||
class FromRattailToCore(importing.FromRattailHandler, ToCOREAPIHandler):
|
||||
class FromRattailToCore(importing.FromRattailHandler, corepos_importing.model.ToCOREAPIHandler):
|
||||
"""
|
||||
Rattail -> CORE-POS export handler
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue