Track merchant subfields (officers, bank accounts) in activity diffs

Repo: · Issue: #1069 Status: Open · Priority: P2 Assignee: Sparsh

Description

Summary

Merchant subfields (officers, bank accounts) are not included in the activity diff when a merchant is updated. Only top-level merchant columns are compared and stored in activity.meta_data["changes"]. As a result:

  • Officers: Adding, removing, or editing officers does not appear in the activity feed (no diff entries, and if no other merchant fields change, no activity is created at all).
  • Bank accounts: Same for mutable bank accounts (add/update/remove).
  • MCA: Updates to MCA data in the same update_merchant flow are also not reflected in the diff (only merchant table columns are considered).

Current behavior

In app/api/merchants_helpers.py, update_merchant():

  1. Splits the payload via MerchantUpdate.to_update_dicts() into:
    • merchant_updates (flat dict of merchant columns)
    • officers_dicts, bas_dicts (lists of officer / bank account dicts)
    • mca_data
  2. Updates the DB for merchant (1), then officers (2), then bank accounts (3), then MCA (4).
  3. Activity diff is computed only from merchant_updates (lines 817–838):
if existing_merchant and merchant_updates:
    changes = []
    for key, new_value in merchant_updates.items():
        if not hasattr(existing_merchant, key):
            continue
        old_value = getattr(existing_merchant, key)
        if old_value != new_value:
            changes.append({"field": key, "from": ..., "to": ...})

So:

  • Only keys in merchant_updates (i.e. DbMerchant columns) are compared; officers and bank accounts are never added to changes.
  • When the only updates are officers and/or bank accounts, merchant_updates may be empty, so the condition existing_merchant and merchant_updates is false and no activity is created.

Relevant code:

  • Diff and activity: app/api/merchants_helpers.py ~817–869 (diff calculation and track_activity_on_change with meta_data={"changes": changes}).
  • Officers update: same file ~612–691 (`ex

Implementation Notes

Dash adds notes here while working

Link to people, meetings, dependent tickets