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:
Lance Edgar 2023-06-12 16:39:32 -05:00
parent 46eec6b781
commit cc517702e1
2 changed files with 40 additions and 14 deletions

View file

@ -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.

View file

@ -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
"""