From cc517702e14c9f03094334aeaaee57f4c55b1e25 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 12 Jun 2023 16:39:32 -0500 Subject: [PATCH] Improve email diff display for exports to CORE API 'Member.customers' break out each subrecord into separate fields, for easier viewing --- .../corepos/office/importing/model.py | 38 +++++++++++++++++++ .../corepos/office/importing/rattail.py | 16 +------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/rattail_corepos/corepos/office/importing/model.py b/rattail_corepos/corepos/office/importing/model.py index 864ec7f..4d03801 100644 --- a/rattail_corepos/corepos/office/importing/model.py +++ b/rattail_corepos/corepos/office/importing/model.py @@ -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. diff --git a/rattail_corepos/corepos/office/importing/rattail.py b/rattail_corepos/corepos/office/importing/rattail.py index adaa82c..327d9d8 100644 --- a/rattail_corepos/corepos/office/importing/rattail.py +++ b/rattail_corepos/corepos/office/importing/rattail.py @@ -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 """