Repository navigation
feat(idv): auto-upgrade Bridge-KYC-approved accounts to Level 2 - #80
Merged
Merged
Conversation
Policy (2026-10-06): a Flash account whose Bridge customer has passed KYC has a verified identity, and that is enough for Level 2. A cron job (every 15 min) finds Bridge-linked accounts whose live Bridge status is `active`, individual customers only, at Level 0/1 and active, and for each files an Account Upgrade Request plus an ID Verification (identity_source = bridge_kyc) and approves it through the existing approve_upgrade_request with APPROVE_BRIDGE_KYC. That approval creates or reuses the ERP Customer (flash's required erpParty), stamps the decision, mirrors it to the ID Verification and writes the ledger event, so nothing bypasses the reviewer path. The request has no address, so it is saved with ignore_mandatory; _create_erp_records already treats address and bank as optional. - New switch "Auto-Upgrade Bridge KYC to Level 2" in ID Verification Settings, default off; refused unless Bridge KYC Satisfies Identity is on; changes are ledgered like the other settings. - Skips with reasons: pending request (reviewer owns it), business customer, one Bridge customer on several accounts, inactive account, missing at Bridge, no username/phone/legal name, already upgraded, and an existing erpParty the approval would not find by mobile number (approving would repoint erpParty and strand its bank accounts). - At most 25 upgrades per run; the first run is the backfill. - A failed approval stays Pending for a reviewer and is not retried; failures write an Error Log row. Summary to stdout when anything changed. - preview_bridge_kyc_upgrades() shows candidates and skips, read-only. Needs the flash fix for address-less upgrade requests deployed first: the app's LatestAccountUpgradeRequest selects Address's non-null fields. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Frappe enforces static reqd fields on every save, not just the insert, and only a flags.ignore_mandatory on that exact doc object skips it. The job set the flag on its insert, but approve_upgrade_request reloads the request and saves it after flash has already moved to Level 2, so every auto-upgrade would have failed there and then rolled back the Customer flash's erpParty now names. The same check broke reviewer Reject, request_resubmission, the Account Hub phone sync (it re-saves every request for the user), and flash closing a user's pending requests (frappe.client.bulk_update). - Account Upgrade Request: the address block is no longer reqd. It is required for Level 3 in the desk form only (mandatory_depends_on; frappe does not enforce that on the server). Flash's API still requires an address on every customer-submitted request. ignore_mandatory is gone. - Nothing is committed before the approval commits. On failure, if flash is still below Level 2 everything is rolled back (no request the user never filed, which the app would show as pending, and no orphan Customer) and the account is retried after 24h. If flash moved or can't be read, the records are kept and the request stays Pending for a reviewer. - The Error Log row is written after that rollback and committed on its own, so the next account's rollback can't remove it. - The "why" note moves to the ID Verification's reviewer_note; the reviewer pages render the request's support_note as "Rejection Reason". Tests: the job fixture now enforces each doctype's reqd fields on insert AND save, read from the doctype JSON; restoring the old reqd flags fails 10 tests. New failure-path tests (no trace + backoff, flash moved, flash unreadable, Error Log survives a later rollback). Each new safeguard was mutation-checked. 862 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Policy (2026-10-06): a Flash account whose Bridge customer has passed KYC has a verified identity, and that is enough for Level 2. This adds a scheduled job that applies the policy through the existing reviewer path. Nothing goes around it.
Every 15 minutes, while the new switch is on, for each Flash account that is linked to a Bridge customer, where that customer's live Bridge status is
active, the customer is an individual, and the account is active and at Level 0 or 1:identity_source = bridge_kyc. It keeps Bridge's id, status,updated_atand endorsements only, the same slice flash keeps.approve_upgrade_request(..., reason_code="APPROVE_BRIDGE_KYC"). That creates or reuses the ERP Customer by mobile number (flash's requirederpPartyfor Level 2), stamps the decision, mirrors it to the ID Verification and writes theupgrade_approvedledger event. Flash posts the level change to the ops feed.The request has no address. The request doctype's address block is no longer
reqd; it's required for Level 3 in the desk form only (mandatory_depends_on). Frappe enforcesreqdon every save, not just the insert, so a required address made every later save of these requests fail:lnflash/flash#517 now requires a complete address on every request a customer submits.
_create_erp_recordsalready treats address and bank as optional, and with noaddress_titlethe Customer is created as an Individual. Why each request exists goes on the ID Verification's internalreviewer_note; the reviewer pages showsupport_noteas "Rejection Reason".Switch
idv_settings_changed) like the other settings.Skipped (with a reason), never upgraded
erpPartythat approval wouldn't find by mobile number. Approving would repointerpPartyat a new Customer and strand the old one's bank accounts, so that case goes to a human.Failures
Nothing is committed until the approval commits. If an approval fails:
erpPartymay name the new Customer. The request stays Pending for a reviewer, who can now approve or reject it.Each failure writes an Error Log row, after the rollback and committed on its own. A run that upgraded or failed anything prints a summary line to stdout, using an explicit
setLevelbecausefrappe.logger()drops INFO on the cluster.preview_bridge_kyc_upgrades()(whitelisted, admin-only, read-only) lists candidates and skips. Seedocs/bridge-kyc-auto-upgrade.md.Rollout
LatestAccountUpgradeRequestselectsAddress's non-null fields, so without it an address-less request errors on the upgrade screen. It also takes over requiring a complete address on customer requests, which this PR stops ERP doing.make erp). Migrate adds the setting and the scheduled job.bench --site erp.flashapp.me execute admin_panel.api.bridge_kyc_upgrade.preview_bridge_kyc_upgradesCompanion PRs (ship before switching this on)
bankPayout, so no false "Bank cash-out ✓ On", and a Business request needs a bank on file;Tests
test_bridge_kyc_upgrade.py(49 tests). The eligibility rules are tested pure. The job runs against FakeFrappe with the realapprove_upgrade_request, and the fixture now enforces each doctype'sreqdfields on insert and save, read from the doctype JSON. Restoring the oldreqdflags fails 10 tests.erpPartyguard;setLevel, the reason code, theerpPartyguard).🤖 Generated with Claude Code