Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/connector_onboarding.py +124 -0
- api/main.py +22 -8
- api/odoo_purchasing.py +186 -0
- api/odoo_relational.py +32 -4
- api/routes_admin.py +2 -2
- api/routes_connectors.py +2 -0
- api/routes_keychain.py +17 -0
- api/routes_odoo_tables.py +6 -1
- platform/core/store_pg.py +7 -13
- platform/core/users.py +4 -1
- platform/harness/datastore.py +33 -9
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
- web/src/connectors/ConnectTutorial.tsx +29 -9
- web/src/connectors/connectors.css +13 -0
- web/src/shell/Shell.tsx +2 -0
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "9c715fa4b",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
9c715fa4b
|
api/connector_onboarding.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""First-connection choices, stored before a credential can dispatch a sync."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def choices(provider):
|
| 6 |
+
if provider == "odoo":
|
| 7 |
+
import odoo_relational as rel
|
| 8 |
+
defaults = {"invoices", "orders", "order_lines", "stock_moves", "stock_valuation", "stock_quant"}
|
| 9 |
+
return ([{"key": "customer_data", "label": "Customers", "selected": True},
|
| 10 |
+
{"key": "product_data", "label": "Products", "selected": True}]
|
| 11 |
+
+ [{"key": key, "label": label, "selected": bucket in defaults}
|
| 12 |
+
for bucket, key, label, _ in rel.TABLES])
|
| 13 |
+
if provider == "amazon_sp":
|
| 14 |
+
from harness import amazon_store
|
| 15 |
+
return [{"key": "ut_amzn_" + key, "label": key.replace("_", " ").capitalize(),
|
| 16 |
+
"selected": key in {"orders", "order_items", "inventory", "settlements"}}
|
| 17 |
+
for key in amazon_store.TABLES]
|
| 18 |
+
return []
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def install_selection(rt, provider, selected, *, existing=False):
|
| 22 |
+
"""Explicit first-save intent only; preserve every pre-existing connector configuration.
|
| 23 |
+
|
| 24 |
+
This runs before add_entry, so an automatic runner cannot see a credential with all-on defaults.
|
| 25 |
+
A failed credential save leaves a safe, resumable choice document, never an unselected sync.
|
| 26 |
+
"""
|
| 27 |
+
offered = {row["key"] for row in choices(provider)}
|
| 28 |
+
if not offered or not isinstance(selected, list) or any(type(key) is not str for key in selected):
|
| 29 |
+
raise ValueError("Choose databases from this connector's setup list.")
|
| 30 |
+
if len(set(selected)) != len(selected) or not set(selected) <= offered:
|
| 31 |
+
raise ValueError("The database selection contains an unknown or duplicate database.")
|
| 32 |
+
if existing:
|
| 33 |
+
raise ValueError("This connection already exists. Change its databases in Settings.")
|
| 34 |
+
if provider == "odoo":
|
| 35 |
+
import odoo_relational as rel
|
| 36 |
+
key, member = rel.CONFIG_KEY, "grids"
|
| 37 |
+
else:
|
| 38 |
+
import connectors_amazon as amazon
|
| 39 |
+
key, member = amazon.ENABLEMENT_KEY, "databases"
|
| 40 |
+
|
| 41 |
+
def install(current):
|
| 42 |
+
if current is None:
|
| 43 |
+
current = {}
|
| 44 |
+
if not isinstance(current, dict):
|
| 45 |
+
raise ValueError("The stored connector settings are unavailable.")
|
| 46 |
+
# Only our own incomplete setup can be retried. Older selections are never repurposed.
|
| 47 |
+
if current and current.get("initialSetup") != "selected":
|
| 48 |
+
raise ValueError("This workspace already has database choices. Use Settings to change them.")
|
| 49 |
+
return {**current, member: {name: name in selected for name in sorted(offered)},
|
| 50 |
+
"initialSetup": "selected"}
|
| 51 |
+
|
| 52 |
+
rt.update(key, install, flush="sync")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def seal_selection(rt, provider):
|
| 56 |
+
from odoo_relational import CONFIG_KEY
|
| 57 |
+
from connectors_amazon import ENABLEMENT_KEY
|
| 58 |
+
key = CONFIG_KEY if provider == "odoo" else ENABLEMENT_KEY
|
| 59 |
+
|
| 60 |
+
def seal(current):
|
| 61 |
+
if not isinstance(current, dict) or current.get("initialSetup") != "selected":
|
| 62 |
+
raise ValueError("The first-connection selection was not saved.")
|
| 63 |
+
return {**current, "initialSetup": "configured"}
|
| 64 |
+
|
| 65 |
+
rt.update(key, seal, flush="sync")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def selected_mirror_entities(rt):
|
| 69 |
+
"""None preserves old sync policy; an explicit setup limits source pulls to selected dependencies."""
|
| 70 |
+
import odoo_relational as rel
|
| 71 |
+
config = rt.get(rel.CONFIG_KEY)
|
| 72 |
+
if not isinstance(config, dict) or config.get("initialSetup") not in {"selected", "configured"}:
|
| 73 |
+
return None
|
| 74 |
+
grids = config.get("grids")
|
| 75 |
+
if not isinstance(grids, dict) or any(type(v) is not bool for v in grids.values()):
|
| 76 |
+
raise ValueError("The first-connection database selection is unavailable.")
|
| 77 |
+
import routes_odoo_tables as route
|
| 78 |
+
from harness import datastore
|
| 79 |
+
sources = route._odoo_sources()
|
| 80 |
+
entities = set()
|
| 81 |
+
for key, enabled in grids.items():
|
| 82 |
+
if not enabled:
|
| 83 |
+
continue
|
| 84 |
+
if key in {"customer_data", "product_data"}:
|
| 85 |
+
entities.add({"customer_data": "res_partner", "product_data": "product_product"}[key])
|
| 86 |
+
continue
|
| 87 |
+
if key not in sources:
|
| 88 |
+
continue
|
| 89 |
+
source = sources[key]
|
| 90 |
+
if source.get("table"):
|
| 91 |
+
entities.add(source["table"])
|
| 92 |
+
entities.update(source.get("tables", {}).values())
|
| 93 |
+
if source.get("needs_excluded"):
|
| 94 |
+
entities.add("res_partner")
|
| 95 |
+
return sorted(entities & set(datastore.ENTITIES))
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def mirror_cursor(rt, table_key=None):
|
| 99 |
+
"""A selected source waits for its dependencies, without declaring the entire mirror ready."""
|
| 100 |
+
from harness import datastore
|
| 101 |
+
if rt is None:
|
| 102 |
+
return datastore.ro_con()
|
| 103 |
+
rt.assert_datastore_matches()
|
| 104 |
+
entities = selected_mirror_entities(rt)
|
| 105 |
+
if entities is None:
|
| 106 |
+
return datastore.ro_con()
|
| 107 |
+
if table_key is not None:
|
| 108 |
+
import odoo_relational as rel
|
| 109 |
+
import routes_odoo_tables as route
|
| 110 |
+
config = rt.get(rel.CONFIG_KEY)
|
| 111 |
+
if not config.get("grids", {}).get(table_key, False):
|
| 112 |
+
raise RuntimeError("Enable this database in connection settings before reading it.")
|
| 113 |
+
source = route._odoo_sources().get(table_key)
|
| 114 |
+
if source is None:
|
| 115 |
+
return datastore.ro_con()
|
| 116 |
+
entities = set(source.get("tables", {}).values())
|
| 117 |
+
if source.get("table"):
|
| 118 |
+
entities.add(source["table"])
|
| 119 |
+
if source.get("needs_excluded"):
|
| 120 |
+
entities.add("res_partner")
|
| 121 |
+
if any(not datastore.entity_live(key) for key in entities):
|
| 122 |
+
raise RuntimeError("The selected database is completing its first sync. Try again shortly.")
|
| 123 |
+
# An empty first selection has no readers to run and need not create a mirror file.
|
| 124 |
+
return datastore.ro_cursor() if entities else None
|
api/main.py
CHANGED
|
@@ -669,9 +669,10 @@ def _seed_and_sync_store():
|
|
| 669 |
_odoo._tlocal.client = _odoo.OdooClient()
|
| 670 |
except Exception:
|
| 671 |
pass
|
|
|
|
| 672 |
res = {}
|
| 673 |
for i in range(12):
|
| 674 |
-
res = _ds.sync_all(log=lambda *a, **k: None)
|
| 675 |
print(f"[aios-api] datastore sync pass {i + 1}: "
|
| 676 |
+ ", ".join(f"{k}={v.get('phase')}" for k, v in sorted(res.items())))
|
| 677 |
if all(v.get("phase") == "live" for v in res.values()):
|
|
@@ -682,7 +683,7 @@ def _seed_and_sync_store():
|
|
| 682 |
# measure is served. MEASURED 2026-08-05: five deleted sale_order_line rows = $284.25 of
|
| 683 |
# phantom YTD revenue, stable across re-syncs, zero the moment reconcile ran.
|
| 684 |
try:
|
| 685 |
-
_ds.reconcile_deletes(log=lambda *a, **k: None)
|
| 686 |
except Exception:
|
| 687 |
pass
|
| 688 |
print(f"[aios-api] datastore sync done in {_t.time() - t0:.1f}s "
|
|
@@ -1007,11 +1008,14 @@ def _run_sync_requests(outcome=None):
|
|
| 1007 |
# transport. Do not borrow a request's cached XML-RPC client.
|
| 1008 |
odoo._tlocal.client = odoo.OdooClient(creds=source._creds)
|
| 1009 |
odoo._tlocal.tenant_ctx = None
|
| 1010 |
-
|
|
|
|
|
|
|
|
|
|
| 1011 |
finally:
|
| 1012 |
odoo._tlocal.client = previous_client
|
| 1013 |
odoo._tlocal.tenant_ctx = previous_context
|
| 1014 |
-
if not report:
|
| 1015 |
raise _SyncNowRefused(
|
| 1016 |
"Odoo did not run a sync. Check whether the connection is paused.")
|
| 1017 |
if any(row.get("phase") != "live" for row in report.values()):
|
|
@@ -1844,7 +1848,13 @@ _neon_usage.set_guards(STORE_GUARDS)
|
|
| 1844 |
_startup_notes()
|
| 1845 |
|
| 1846 |
|
| 1847 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1848 |
"""ONE bounded mirror pass: DuckDB and the Odoo XML-RPC client, and nothing else.
|
| 1849 |
|
| 1850 |
⛔⛔ NO `Store`, NO `store_kv`, NO `user_tables` IN THIS BODY, AND THAT IS A CONTRACT RATHER
|
|
@@ -1873,7 +1883,7 @@ def _resync_mirror_pass(manual, passes):
|
|
| 1873 |
# relational rebuild, which `manual` says nothing about.
|
| 1874 |
if manual:
|
| 1875 |
return None, None, None
|
| 1876 |
-
sync_report = _ds.sync_all(log=lambda *a, **k: None)
|
| 1877 |
# Wave 21: purge hard-deleted rows the cursor sync cannot see (the boot pass's comment has
|
| 1878 |
# the measured case); without it deleted Odoo lines inflate every sum on the mirror FOREVER.
|
| 1879 |
# ⚠ INSIDE the non-manual branch: a reconcile is a pass over the mirror this loop was
|
|
@@ -1881,7 +1891,7 @@ def _resync_mirror_pass(manual, passes):
|
|
| 1881 |
# HOTFIX 2026-09-29: EVERY pass, not every fourth. At a daily cadence a fourth pass is four
|
| 1882 |
# days, and the first pass after a reseed never reconciled at all. `reconcile_deletes`
|
| 1883 |
# compares counts first and walks ids only for an entity whose count moved.
|
| 1884 |
-
delete_report = _ds.reconcile_deletes(log=lambda *a, **k: None)
|
| 1885 |
return sync_report, delete_report, None
|
| 1886 |
except Exception as e: # noqa: BLE001
|
| 1887 |
# A partial report must never be mistaken for a confirmed zero-change pass.
|
|
@@ -2156,7 +2166,11 @@ def _store_resync_loop():
|
|
| 2156 |
RESYNC_STATE["passes"] = passes
|
| 2157 |
if _odoo_requested is None:
|
| 2158 |
_odoo_requested = _run_sync_requests()
|
| 2159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2160 |
source_fingerprints = _resync_source_fingerprints(sync_report)
|
| 2161 |
RESYNC_STATE["lastPassAt"] = _t.strftime("%Y-%m-%dT%H:%M:%SZ", _t.gmtime())
|
| 2162 |
RESYNC_STATE["lastPassOk"] = _err is None
|
|
|
|
| 669 |
_odoo._tlocal.client = _odoo.OdooClient()
|
| 670 |
except Exception:
|
| 671 |
pass
|
| 672 |
+
selected_entities = _configured_mirror_entities()
|
| 673 |
res = {}
|
| 674 |
for i in range(12):
|
| 675 |
+
res = _ds.sync_all(entities=selected_entities, log=lambda *a, **k: None)
|
| 676 |
print(f"[aios-api] datastore sync pass {i + 1}: "
|
| 677 |
+ ", ".join(f"{k}={v.get('phase')}" for k, v in sorted(res.items())))
|
| 678 |
if all(v.get("phase") == "live" for v in res.values()):
|
|
|
|
| 683 |
# measure is served. MEASURED 2026-08-05: five deleted sale_order_line rows = $284.25 of
|
| 684 |
# phantom YTD revenue, stable across re-syncs, zero the moment reconcile ran.
|
| 685 |
try:
|
| 686 |
+
_ds.reconcile_deletes(entities=selected_entities, log=lambda *a, **k: None)
|
| 687 |
except Exception:
|
| 688 |
pass
|
| 689 |
print(f"[aios-api] datastore sync done in {_t.time() - t0:.1f}s "
|
|
|
|
| 1008 |
# transport. Do not borrow a request's cached XML-RPC client.
|
| 1009 |
odoo._tlocal.client = odoo.OdooClient(creds=source._creds)
|
| 1010 |
odoo._tlocal.tenant_ctx = None
|
| 1011 |
+
from connector_onboarding import selected_mirror_entities
|
| 1012 |
+
selected_entities = selected_mirror_entities(rt)
|
| 1013 |
+
report = datastore.sync_all(entities=selected_entities,
|
| 1014 |
+
log=lambda *a, **k: None)
|
| 1015 |
finally:
|
| 1016 |
odoo._tlocal.client = previous_client
|
| 1017 |
odoo._tlocal.tenant_ctx = previous_context
|
| 1018 |
+
if not report and selected_entities != []:
|
| 1019 |
raise _SyncNowRefused(
|
| 1020 |
"Odoo did not run a sync. Check whether the connection is paused.")
|
| 1021 |
if any(row.get("phase") != "live" for row in report.values()):
|
|
|
|
| 1848 |
_startup_notes()
|
| 1849 |
|
| 1850 |
|
| 1851 |
+
def _configured_mirror_entities(tenant=None):
|
| 1852 |
+
from harness import runtime
|
| 1853 |
+
from connector_onboarding import selected_mirror_entities
|
| 1854 |
+
return selected_mirror_entities(runtime.get_runtime(tenant or _resync_tenant()[0]))
|
| 1855 |
+
|
| 1856 |
+
|
| 1857 |
+
def _resync_mirror_pass(manual, passes, entities=None):
|
| 1858 |
"""ONE bounded mirror pass: DuckDB and the Odoo XML-RPC client, and nothing else.
|
| 1859 |
|
| 1860 |
⛔⛔ NO `Store`, NO `store_kv`, NO `user_tables` IN THIS BODY, AND THAT IS A CONTRACT RATHER
|
|
|
|
| 1883 |
# relational rebuild, which `manual` says nothing about.
|
| 1884 |
if manual:
|
| 1885 |
return None, None, None
|
| 1886 |
+
sync_report = _ds.sync_all(entities=entities, log=lambda *a, **k: None)
|
| 1887 |
# Wave 21: purge hard-deleted rows the cursor sync cannot see (the boot pass's comment has
|
| 1888 |
# the measured case); without it deleted Odoo lines inflate every sum on the mirror FOREVER.
|
| 1889 |
# ⚠ INSIDE the non-manual branch: a reconcile is a pass over the mirror this loop was
|
|
|
|
| 1891 |
# HOTFIX 2026-09-29: EVERY pass, not every fourth. At a daily cadence a fourth pass is four
|
| 1892 |
# days, and the first pass after a reseed never reconciled at all. `reconcile_deletes`
|
| 1893 |
# compares counts first and walks ids only for an entity whose count moved.
|
| 1894 |
+
delete_report = _ds.reconcile_deletes(entities=entities, log=lambda *a, **k: None)
|
| 1895 |
return sync_report, delete_report, None
|
| 1896 |
except Exception as e: # noqa: BLE001
|
| 1897 |
# A partial report must never be mistaken for a confirmed zero-change pass.
|
|
|
|
| 2166 |
RESYNC_STATE["passes"] = passes
|
| 2167 |
if _odoo_requested is None:
|
| 2168 |
_odoo_requested = _run_sync_requests()
|
| 2169 |
+
try:
|
| 2170 |
+
selected_entities = _configured_mirror_entities(_cad["tenant"])
|
| 2171 |
+
sync_report, delete_report, _err = _resync_mirror_pass(_manual, passes, selected_entities)
|
| 2172 |
+
except Exception as exc:
|
| 2173 |
+
sync_report, delete_report, _err = None, None, _classify_resync_error(exc)
|
| 2174 |
source_fingerprints = _resync_source_fingerprints(sync_report)
|
| 2175 |
RESYNC_STATE["lastPassAt"] = _t.strftime("%Y-%m-%dT%H:%M:%SZ", _t.gmtime())
|
| 2176 |
RESYNC_STATE["lastPassOk"] = _err is None
|
api/odoo_purchasing.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-only purchasing projections and source reconciliation for the Odoo connector."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import datetime as dt
|
| 5 |
+
import math
|
| 6 |
+
|
| 7 |
+
ORDERS_KEY = "ut_odoo_purchase_orders"
|
| 8 |
+
LINES_KEY = "ut_odoo_purchase_lines"
|
| 9 |
+
CONFIRMED = "po.state IN ('purchase','done')"
|
| 10 |
+
|
| 11 |
+
MIRROR_ENTITIES = {
|
| 12 |
+
"purchase_order": {
|
| 13 |
+
"model": "purchase.order", "archivable": False, "optional": True,
|
| 14 |
+
"fields": ["name", "partner_id", "date_approve", "date_order", "state",
|
| 15 |
+
"amount_untaxed", "amount_total", "currency_id", "write_date"],
|
| 16 |
+
},
|
| 17 |
+
"purchase_order_line": {
|
| 18 |
+
"model": "purchase.order.line", "archivable": False, "optional": True,
|
| 19 |
+
"fields": ["order_id", "product_id", "product_uom", "product_uom_qty", "product_qty",
|
| 20 |
+
"qty_received", "price_unit", "price_subtotal", "date_planned", "write_date"],
|
| 21 |
+
},
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _text(value):
|
| 26 |
+
return str(value or "")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _id(value):
|
| 30 |
+
return "" if value in (None, False, "") else int(value)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _number(value):
|
| 34 |
+
return float(value or 0)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _date(value):
|
| 38 |
+
return str(value or "")[:10]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _fields(items):
|
| 42 |
+
return [{"source": "overlay", "default": True,
|
| 43 |
+
"automation": {"flowId": "odoo_relational", "preset": True}, **field} for field in items]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def order_fields():
|
| 47 |
+
return _fields([
|
| 48 |
+
{"key": "order_no", "label": "Purchase order", "type": "text", "pinned": True},
|
| 49 |
+
{"key": "odoo_id", "label": "Odoo ID", "type": "int", "default": False},
|
| 50 |
+
{"key": "vendor", "label": "Vendor", "type": "text"},
|
| 51 |
+
{"key": "vendor_id", "label": "Odoo vendor id", "type": "int", "default": False},
|
| 52 |
+
{"key": "confirmation_date", "label": "Confirmation date", "type": "date"},
|
| 53 |
+
{"key": "order_date", "label": "Order date", "type": "date"},
|
| 54 |
+
{"key": "state", "label": "State", "type": "text"},
|
| 55 |
+
{"key": "currency", "label": "Currency", "type": "text"},
|
| 56 |
+
{"key": "amount_untaxed", "label": "Untaxed amount", "type": "currency", "agg": "sum"},
|
| 57 |
+
{"key": "amount_total", "label": "Total amount", "type": "currency", "agg": "sum"},
|
| 58 |
+
])
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def line_fields():
|
| 62 |
+
return _fields([
|
| 63 |
+
{"key": "order_no", "label": "Purchase order", "type": "text", "pinned": True},
|
| 64 |
+
{"key": "odoo_id", "label": "Odoo ID", "type": "int", "default": False},
|
| 65 |
+
{"key": "order_id", "label": "Odoo order id", "type": "int", "default": False},
|
| 66 |
+
{"key": "vendor", "label": "Vendor", "type": "text"},
|
| 67 |
+
{"key": "vendor_id", "label": "Odoo vendor id", "type": "int", "default": False},
|
| 68 |
+
{"key": "confirmation_date", "label": "Confirmation date", "type": "date"},
|
| 69 |
+
{"key": "state", "label": "State", "type": "text"},
|
| 70 |
+
{"key": "currency", "label": "Currency", "type": "text"},
|
| 71 |
+
{"key": "product", "label": "Product", "type": "text"},
|
| 72 |
+
{"key": "product_id", "label": "Odoo product id", "type": "int", "default": False},
|
| 73 |
+
{"key": "sku", "label": "SKU", "type": "text"},
|
| 74 |
+
{"key": "uom", "label": "Product unit of measure", "type": "text"},
|
| 75 |
+
{"key": "purchase_uom", "label": "Purchase unit of measure", "type": "text"},
|
| 76 |
+
{"key": "standard_price", "label": "Standard cost", "type": "currency"},
|
| 77 |
+
{"key": "category", "label": "Category", "type": "text"},
|
| 78 |
+
{"key": "qty", "label": "Quantity in product units", "type": "int", "agg": "sum"},
|
| 79 |
+
{"key": "purchase_qty", "label": "Quantity in purchase units", "type": "int", "agg": "sum"},
|
| 80 |
+
{"key": "received_qty", "label": "Received in purchase units", "type": "int", "agg": "sum"},
|
| 81 |
+
{"key": "price_unit", "label": "Unit price", "type": "currency"},
|
| 82 |
+
{"key": "price_subtotal", "label": "Untaxed amount", "type": "currency", "agg": "sum"},
|
| 83 |
+
{"key": "planned_date", "label": "Planned date", "type": "date"},
|
| 84 |
+
])
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def source_specs():
|
| 88 |
+
common = {
|
| 89 |
+
"order_no": ("po.name", _text), "vendor": ("po.partner_name", _text),
|
| 90 |
+
"vendor_id": ("po.partner_id", _id), "confirmation_date": ("po.date_approve", _date),
|
| 91 |
+
"state": ("po.state", _text), "currency": ("po.currency_name", _text),
|
| 92 |
+
}
|
| 93 |
+
return {
|
| 94 |
+
ORDERS_KEY: {
|
| 95 |
+
"from_sql": "purchase_order po", "tables": {"po": "purchase_order"},
|
| 96 |
+
"where": CONFIRMED, "id": "po.id",
|
| 97 |
+
"cols": {**common, "odoo_id": ("po.id", _id), "order_date": ("po.date_order", _date),
|
| 98 |
+
"amount_untaxed": ("po.amount_untaxed", _number),
|
| 99 |
+
"amount_total": ("po.amount_total", _number)},
|
| 100 |
+
},
|
| 101 |
+
LINES_KEY: {
|
| 102 |
+
"from_sql": "(purchase_order_line pol JOIN purchase_order po ON po.id = pol.order_id "
|
| 103 |
+
"LEFT JOIN product_product pp ON pp.id = pol.product_id)",
|
| 104 |
+
"tables": {"pol": "purchase_order_line", "po": "purchase_order", "pp": "product_product"},
|
| 105 |
+
"where": CONFIRMED, "id": "pol.id",
|
| 106 |
+
"cols": {**common, "odoo_id": ("pol.id", _id), "order_id": ("pol.order_id", _id),
|
| 107 |
+
"product": ("pol.product_name", _text), "product_id": ("pol.product_id", _id),
|
| 108 |
+
"sku": ("pp.default_code", _text), "uom": ("pp.uom_name", _text),
|
| 109 |
+
"purchase_uom": ("pol.product_uom_name", _text),
|
| 110 |
+
"standard_price": ("pp.standard_price", _number), "category": ("pp.categ_name", _text),
|
| 111 |
+
"qty": ("pol.product_uom_qty", _number), "purchase_qty": ("pol.product_qty", _number),
|
| 112 |
+
"received_qty": ("pol.qty_received", _number), "price_unit": ("pol.price_unit", _number),
|
| 113 |
+
"price_subtotal": ("pol.price_subtotal", _number), "planned_date": ("pol.date_planned", _date)},
|
| 114 |
+
},
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _row_totals(client, model, domain, field):
|
| 119 |
+
last, count, total = 0, 0, 0.0
|
| 120 |
+
while True:
|
| 121 |
+
rows = client.search_read(model, domain + [("id", ">", last)], ["id", field],
|
| 122 |
+
limit=2000, order="id asc")
|
| 123 |
+
if not rows:
|
| 124 |
+
return count, total
|
| 125 |
+
values = []
|
| 126 |
+
for row in rows:
|
| 127 |
+
rid = int(row["id"])
|
| 128 |
+
value = float(row.get(field) or 0)
|
| 129 |
+
if rid <= last or not math.isfinite(value):
|
| 130 |
+
raise ValueError("purchasing validation source did not advance or returned a non-finite amount")
|
| 131 |
+
last = rid
|
| 132 |
+
values.append(value)
|
| 133 |
+
count += len(rows)
|
| 134 |
+
total = math.fsum([total, *values])
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def validate(client, cur=None, month="2026-06"):
|
| 138 |
+
"""Tie a closed confirmation month to independent Odoo line aggregates, without printing totals.
|
| 139 |
+
|
| 140 |
+
A supplied cursor must be admitted for the same tenant/connection as the read-only client.
|
| 141 |
+
Without it, this validates live row totals only and makes no production-mirror claim.
|
| 142 |
+
"""
|
| 143 |
+
start = dt.date.fromisoformat(month + "-01")
|
| 144 |
+
end = (start.replace(day=28) + dt.timedelta(days=4)).replace(day=1)
|
| 145 |
+
if end > dt.date.today().replace(day=1):
|
| 146 |
+
raise ValueError("purchasing validation requires a closed month")
|
| 147 |
+
checks, totals = [], {}
|
| 148 |
+
plane = "mirror" if cur is not None else "live_rows"
|
| 149 |
+
periods = [("date_approve", ">=", start.isoformat()), ("date_approve", "<", end.isoformat())]
|
| 150 |
+
for key, model, field in ((ORDERS_KEY, "purchase.order", "amount_untaxed"),
|
| 151 |
+
(LINES_KEY, "purchase.order.line", "price_subtotal")):
|
| 152 |
+
prefix = "order_id." if key == LINES_KEY else ""
|
| 153 |
+
domain = [(prefix + "state", "in", ["purchase", "done"])]
|
| 154 |
+
domain += [(prefix + f, op, value) for f, op, value in periods]
|
| 155 |
+
try:
|
| 156 |
+
if cur is None:
|
| 157 |
+
count, total = _row_totals(client, model, domain, field)
|
| 158 |
+
else:
|
| 159 |
+
spec = source_specs()[key]
|
| 160 |
+
count, distinct, total = cur.execute(
|
| 161 |
+
"SELECT COUNT(*), COUNT(DISTINCT " + spec["id"] + "), COALESCE(SUM("
|
| 162 |
+
+ spec["cols"][field][0] + "), 0) FROM " + spec["from_sql"] + " WHERE "
|
| 163 |
+
+ spec["where"] + " AND po.date_approve >= ? AND po.date_approve < ?",
|
| 164 |
+
[start.isoformat(), end.isoformat()]).fetchone()
|
| 165 |
+
if count != distinct:
|
| 166 |
+
raise ValueError("purchasing projection duplicated identities")
|
| 167 |
+
expected = int(client.search_count(model, domain))
|
| 168 |
+
groups = client.read_group(model, domain, [field + ":sum"],
|
| 169 |
+
["order_id" if key == LINES_KEY else "partner_id"], lazy=False)
|
| 170 |
+
summary = math.fsum(float(row.get(field) or 0) for row in groups)
|
| 171 |
+
checks.append({"check": key + " complete population", "ok": count == expected,
|
| 172 |
+
"observation": plane, "observed_rows": count, "source_rows": expected})
|
| 173 |
+
checks.append({"check": key + " vs Odoo read_group",
|
| 174 |
+
"ok": math.isfinite(total) and math.isfinite(summary)
|
| 175 |
+
and abs(total - summary) <= 0.01,
|
| 176 |
+
"observation": plane})
|
| 177 |
+
totals[key] = (total, summary, count)
|
| 178 |
+
except Exception as exc:
|
| 179 |
+
checks.append({"check": key + " reconciliation", "ok": False,
|
| 180 |
+
"error_type": type(exc).__name__, "observation": plane})
|
| 181 |
+
if len(totals) == 2:
|
| 182 |
+
checks.append({"check": "confirmed purchase orders vs independent Odoo line total",
|
| 183 |
+
"ok": totals[ORDERS_KEY][2] > 0 and totals[LINES_KEY][2] > 0
|
| 184 |
+
and abs(totals[ORDERS_KEY][0] - totals[LINES_KEY][1]) <= 0.01,
|
| 185 |
+
"observation": plane})
|
| 186 |
+
return checks
|
api/odoo_relational.py
CHANGED
|
@@ -94,6 +94,11 @@ GL_LINES_KEY = "ut_odoo_gl_lines"
|
|
| 94 |
STOCK_MOVES_KEY = "ut_odoo_stock_moves"
|
| 95 |
STOCK_VALUATION_KEY = "ut_odoo_stock_valuation"
|
| 96 |
STOCK_QUANT_KEY = "ut_odoo_stock_quant"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
#: The join column the partner-grain tables carry. Derived links resolve through it (`on`/`from`).
|
| 99 |
JOIN_KEY = "partner_id"
|
|
@@ -1957,6 +1962,8 @@ TABLES = (
|
|
| 1957 |
("stock_moves", STOCK_MOVES_KEY, "Odoo stock moves", stock_move_fields),
|
| 1958 |
("stock_valuation", STOCK_VALUATION_KEY, "Odoo stock valuation", stock_valuation_fields),
|
| 1959 |
("stock_quant", STOCK_QUANT_KEY, "Odoo stock on hand", stock_quant_fields),
|
|
|
|
|
|
|
| 1960 |
)
|
| 1961 |
|
| 1962 |
# The grid declarations above are the stable mirror contract, not Odoo's schema. T03 snapshots
|
|
@@ -1968,6 +1975,7 @@ ODOO_TABLE_MODELS = {
|
|
| 1968 |
ORDER_LINES_KEY: "sale.order.line", GL_LINES_KEY: "account.move.line",
|
| 1969 |
STOCK_MOVES_KEY: "stock.move", STOCK_VALUATION_KEY: "stock.valuation.layer",
|
| 1970 |
STOCK_QUANT_KEY: "stock.quant",
|
|
|
|
| 1971 |
}
|
| 1972 |
# Shipments deliberately stay outside this map and TABLES: its consumers route mapped models
|
| 1973 |
# through the DuckDB refresh and suppress their discovered-model reads. There is no picking
|
|
@@ -2651,6 +2659,11 @@ ODOO_SPEC = (
|
|
| 2651 |
"pinned": "odoo_id", "identity": (_ROW_ID_COL, "odoo_id"), "links": ()},
|
| 2652 |
{"key": STOCK_QUANT_KEY, "source": "stock_quant", "label": "Odoo stock on hand",
|
| 2653 |
"pinned": "odoo_id", "identity": (_ROW_ID_COL, "odoo_id"), "links": ()},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2654 |
)
|
| 2655 |
|
| 2656 |
|
|
@@ -2941,6 +2954,8 @@ TABLE_SUBJECTS = {
|
|
| 2941 |
STOCK_MOVES_KEY: "odoo:stock.move",
|
| 2942 |
STOCK_VALUATION_KEY: "odoo:stock.valuation.layer",
|
| 2943 |
STOCK_QUANT_KEY: "odoo:stock.quant.internal",
|
|
|
|
|
|
|
| 2944 |
}
|
| 2945 |
|
| 2946 |
# One receipt identity per curated database. The model is not enough: invoices/bills share
|
|
@@ -2958,6 +2973,8 @@ TABLE_TOPICS = {
|
|
| 2958 |
STOCK_MOVES_KEY: "odoo_stock_moves",
|
| 2959 |
STOCK_VALUATION_KEY: "odoo_stock_valuation",
|
| 2960 |
STOCK_QUANT_KEY: "odoo_stock_quant",
|
|
|
|
|
|
|
| 2961 |
}
|
| 2962 |
|
| 2963 |
_SOURCE_COUNT_SPECS = {
|
|
@@ -2982,6 +2999,10 @@ _SOURCE_COUNT_SPECS = {
|
|
| 2982 |
"stock_valuation": {"model": "stock.valuation.layer", "mode": "count", "domain": []},
|
| 2983 |
"stock_quant": {"model": "stock.quant", "mode": "count", "domain": [
|
| 2984 |
("location_id.usage", "=", "internal")]},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2985 |
}
|
| 2986 |
|
| 2987 |
# The two canonical registry databases replaced the retired ``ut_odoo_customers`` and
|
|
@@ -5384,6 +5405,13 @@ def refresh_curated(rt, cur, buckets, *, connection_id=None, username="automatio
|
|
| 5384 |
return built, written, errors, receipts, report
|
| 5385 |
|
| 5386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5387 |
def refresh(rt, tenant, username="automation", cur=None, today=None, connection_id=None,
|
| 5388 |
all_connections=False, table_keys=None, on_apply=None):
|
| 5389 |
"""THE entry point — the store-resync path and the route both call this.
|
|
@@ -5475,8 +5503,8 @@ def refresh(rt, tenant, username="automation", cur=None, today=None, connection_
|
|
| 5475 |
if ns is not None:
|
| 5476 |
cur = None
|
| 5477 |
elif cur is None:
|
| 5478 |
-
from
|
| 5479 |
-
cur =
|
| 5480 |
requested = set(table_keys) if table_keys is not None else None
|
| 5481 |
if requested is not None:
|
| 5482 |
for key in requested:
|
|
@@ -5500,7 +5528,7 @@ def refresh(rt, tenant, username="automation", cur=None, today=None, connection_
|
|
| 5500 |
built, written, database_errors, database_receipts, plan_report = refresh_curated(
|
| 5501 |
rt, cur, keep, connection_id=ns, username=username, today=today,
|
| 5502 |
retire=requested is None, on_apply=on_apply)
|
| 5503 |
-
if ns is None and requested is None and cur is not None:
|
| 5504 |
canonical_receipts = canonical_reconciliation_receipts(cur)
|
| 5505 |
else:
|
| 5506 |
# The binding selects this connection's verified read-only client. Authentication failure
|
|
@@ -5514,7 +5542,7 @@ def refresh(rt, tenant, username="automation", cur=None, today=None, connection_
|
|
| 5514 |
built, written, database_errors, database_receipts, plan_report = refresh_curated(
|
| 5515 |
rt, cur, keep, connection_id=ns, username=username, today=today,
|
| 5516 |
retire=requested is None, on_apply=on_apply, source_client=source_client)
|
| 5517 |
-
if ns is None and requested is None and cur is not None:
|
| 5518 |
canonical_receipts = canonical_reconciliation_receipts(
|
| 5519 |
cur, source_client=source_client)
|
| 5520 |
# ⭐ W33-T44: a table this pass REMOVED is reported, not inferred from a grid going missing.
|
|
|
|
| 94 |
STOCK_MOVES_KEY = "ut_odoo_stock_moves"
|
| 95 |
STOCK_VALUATION_KEY = "ut_odoo_stock_valuation"
|
| 96 |
STOCK_QUANT_KEY = "ut_odoo_stock_quant"
|
| 97 |
+
from odoo_purchasing import (ORDERS_KEY as PURCHASE_ORDERS_KEY, LINES_KEY as PURCHASE_LINES_KEY,
|
| 98 |
+
order_fields as purchase_order_fields,
|
| 99 |
+
line_fields as purchase_line_fields,
|
| 100 |
+
source_specs as purchase_source_specs,
|
| 101 |
+
validate as validate_purchasing)
|
| 102 |
|
| 103 |
#: The join column the partner-grain tables carry. Derived links resolve through it (`on`/`from`).
|
| 104 |
JOIN_KEY = "partner_id"
|
|
|
|
| 1962 |
("stock_moves", STOCK_MOVES_KEY, "Odoo stock moves", stock_move_fields),
|
| 1963 |
("stock_valuation", STOCK_VALUATION_KEY, "Odoo stock valuation", stock_valuation_fields),
|
| 1964 |
("stock_quant", STOCK_QUANT_KEY, "Odoo stock on hand", stock_quant_fields),
|
| 1965 |
+
("purchase_orders", PURCHASE_ORDERS_KEY, "Odoo purchase orders", purchase_order_fields),
|
| 1966 |
+
("purchase_lines", PURCHASE_LINES_KEY, "Odoo purchase order lines", purchase_line_fields),
|
| 1967 |
)
|
| 1968 |
|
| 1969 |
# The grid declarations above are the stable mirror contract, not Odoo's schema. T03 snapshots
|
|
|
|
| 1975 |
ORDER_LINES_KEY: "sale.order.line", GL_LINES_KEY: "account.move.line",
|
| 1976 |
STOCK_MOVES_KEY: "stock.move", STOCK_VALUATION_KEY: "stock.valuation.layer",
|
| 1977 |
STOCK_QUANT_KEY: "stock.quant",
|
| 1978 |
+
PURCHASE_ORDERS_KEY: "purchase.order", PURCHASE_LINES_KEY: "purchase.order.line",
|
| 1979 |
}
|
| 1980 |
# Shipments deliberately stay outside this map and TABLES: its consumers route mapped models
|
| 1981 |
# through the DuckDB refresh and suppress their discovered-model reads. There is no picking
|
|
|
|
| 2659 |
"pinned": "odoo_id", "identity": (_ROW_ID_COL, "odoo_id"), "links": ()},
|
| 2660 |
{"key": STOCK_QUANT_KEY, "source": "stock_quant", "label": "Odoo stock on hand",
|
| 2661 |
"pinned": "odoo_id", "identity": (_ROW_ID_COL, "odoo_id"), "links": ()},
|
| 2662 |
+
{"key": PURCHASE_ORDERS_KEY, "source": "purchase_order", "label": "Odoo purchase orders",
|
| 2663 |
+
"pinned": "order_no", "identity": (_ROW_ID_COL, "odoo_id"), "links": ()},
|
| 2664 |
+
{"key": PURCHASE_LINES_KEY, "source": "purchase_order_line", "label": "Odoo purchase order lines",
|
| 2665 |
+
"pinned": "order_no", "identity": (_ROW_ID_COL, "odoo_id"),
|
| 2666 |
+
"links": (("order_id", PURCHASE_ORDERS_KEY, _ROW_ID_COL, _M2O),)},
|
| 2667 |
)
|
| 2668 |
|
| 2669 |
|
|
|
|
| 2954 |
STOCK_MOVES_KEY: "odoo:stock.move",
|
| 2955 |
STOCK_VALUATION_KEY: "odoo:stock.valuation.layer",
|
| 2956 |
STOCK_QUANT_KEY: "odoo:stock.quant.internal",
|
| 2957 |
+
PURCHASE_ORDERS_KEY: "odoo:purchase.order.confirmed",
|
| 2958 |
+
PURCHASE_LINES_KEY: "odoo:purchase.order.line.confirmed",
|
| 2959 |
}
|
| 2960 |
|
| 2961 |
# One receipt identity per curated database. The model is not enough: invoices/bills share
|
|
|
|
| 2973 |
STOCK_MOVES_KEY: "odoo_stock_moves",
|
| 2974 |
STOCK_VALUATION_KEY: "odoo_stock_valuation",
|
| 2975 |
STOCK_QUANT_KEY: "odoo_stock_quant",
|
| 2976 |
+
PURCHASE_ORDERS_KEY: "odoo_purchase_orders",
|
| 2977 |
+
PURCHASE_LINES_KEY: "odoo_purchase_lines",
|
| 2978 |
}
|
| 2979 |
|
| 2980 |
_SOURCE_COUNT_SPECS = {
|
|
|
|
| 2999 |
"stock_valuation": {"model": "stock.valuation.layer", "mode": "count", "domain": []},
|
| 3000 |
"stock_quant": {"model": "stock.quant", "mode": "count", "domain": [
|
| 3001 |
("location_id.usage", "=", "internal")]},
|
| 3002 |
+
"purchase_orders": {"model": "purchase.order", "mode": "count", "domain": [
|
| 3003 |
+
("state", "in", ["purchase", "done"])]},
|
| 3004 |
+
"purchase_lines": {"model": "purchase.order.line", "mode": "count", "domain": [
|
| 3005 |
+
("order_id.state", "in", ["purchase", "done"])]},
|
| 3006 |
}
|
| 3007 |
|
| 3008 |
# The two canonical registry databases replaced the retired ``ut_odoo_customers`` and
|
|
|
|
| 5405 |
return built, written, errors, receipts, report
|
| 5406 |
|
| 5407 |
|
| 5408 |
+
def _canonical_mirror_ready(rt):
|
| 5409 |
+
# Initial source selection does not make unrelated canonical totals authoritative.
|
| 5410 |
+
from connector_onboarding import selected_mirror_entities
|
| 5411 |
+
from harness import datastore
|
| 5412 |
+
return rt is None or selected_mirror_entities(rt) is None or datastore.ready()
|
| 5413 |
+
|
| 5414 |
+
|
| 5415 |
def refresh(rt, tenant, username="automation", cur=None, today=None, connection_id=None,
|
| 5416 |
all_connections=False, table_keys=None, on_apply=None):
|
| 5417 |
"""THE entry point — the store-resync path and the route both call this.
|
|
|
|
| 5503 |
if ns is not None:
|
| 5504 |
cur = None
|
| 5505 |
elif cur is None:
|
| 5506 |
+
from connector_onboarding import mirror_cursor
|
| 5507 |
+
cur = mirror_cursor(rt)
|
| 5508 |
requested = set(table_keys) if table_keys is not None else None
|
| 5509 |
if requested is not None:
|
| 5510 |
for key in requested:
|
|
|
|
| 5528 |
built, written, database_errors, database_receipts, plan_report = refresh_curated(
|
| 5529 |
rt, cur, keep, connection_id=ns, username=username, today=today,
|
| 5530 |
retire=requested is None, on_apply=on_apply)
|
| 5531 |
+
if ns is None and requested is None and cur is not None and _canonical_mirror_ready(rt):
|
| 5532 |
canonical_receipts = canonical_reconciliation_receipts(cur)
|
| 5533 |
else:
|
| 5534 |
# The binding selects this connection's verified read-only client. Authentication failure
|
|
|
|
| 5542 |
built, written, database_errors, database_receipts, plan_report = refresh_curated(
|
| 5543 |
rt, cur, keep, connection_id=ns, username=username, today=today,
|
| 5544 |
retire=requested is None, on_apply=on_apply, source_client=source_client)
|
| 5545 |
+
if ns is None and requested is None and cur is not None and _canonical_mirror_ready(rt):
|
| 5546 |
canonical_receipts = canonical_reconciliation_receipts(
|
| 5547 |
cur, source_client=source_client)
|
| 5548 |
# ⭐ W33-T44: a table this pass REMOVED is reported, not inferred from a grid going missing.
|
api/routes_admin.py
CHANGED
|
@@ -115,7 +115,7 @@ def _view(uname, rec, governed=None, st=None, surface_keys=None):
|
|
| 115 |
resolved once for the whole request; the single-record routes pass neither, because their
|
| 116 |
caller fetches the editor payload separately and `GET /perms` is the authority there.
|
| 117 |
"""
|
| 118 |
-
return {"username": uname,
|
| 119 |
"name": rec.get("name") or uname,
|
| 120 |
"role": rec.get("role", "user"),
|
| 121 |
"bus": rec.get("bus", "all"),
|
|
@@ -339,7 +339,7 @@ def create_user(body: dict = Body(default=None), session: Session = Depends(admi
|
|
| 339 |
_require_store()
|
| 340 |
requested_username = _clean_username(body.get("username"))
|
| 341 |
# core.users.create_user and every account lookup below use a canonical key. Keep
|
| 342 |
-
# collision checks and readback on that same key
|
| 343 |
uname = requested_username.lower()
|
| 344 |
name = str(body.get("name") or "").strip() or uname
|
| 345 |
email = str(body.get("email") or "").strip() or None
|
|
|
|
| 115 |
resolved once for the whole request; the single-record routes pass neither, because their
|
| 116 |
caller fetches the editor payload separately and `GET /perms` is the authority there.
|
| 117 |
"""
|
| 118 |
+
return {"username": rec.get("username_original") or uname,
|
| 119 |
"name": rec.get("name") or uname,
|
| 120 |
"role": rec.get("role", "user"),
|
| 121 |
"bus": rec.get("bus", "all"),
|
|
|
|
| 339 |
_require_store()
|
| 340 |
requested_username = _clean_username(body.get("username"))
|
| 341 |
# core.users.create_user and every account lookup below use a canonical key. Keep
|
| 342 |
+
# collision checks and readback on that same key; _view exposes original spelling.
|
| 343 |
uname = requested_username.lower()
|
| 344 |
name = str(body.get("name") or "").strip() or uname
|
| 345 |
email = str(body.get("email") or "").strip() or None
|
api/routes_connectors.py
CHANGED
|
@@ -3364,7 +3364,9 @@ def _detail_connect(entry_type, is_admin):
|
|
| 3364 |
if token.get("entry") == entry_type), "")
|
| 3365 |
except Exception: # A failed token registry must not take away Odoo's setup descriptor.
|
| 3366 |
pass
|
|
|
|
| 3367 |
return {"type": entry_type,
|
|
|
|
| 3368 |
"fields": [dict(field) for field in fields],
|
| 3369 |
"hint": hint,
|
| 3370 |
"tutorial": _CONNECT_TUTORIALS.get(entry_type),
|
|
|
|
| 3364 |
if token.get("entry") == entry_type), "")
|
| 3365 |
except Exception: # A failed token registry must not take away Odoo's setup descriptor.
|
| 3366 |
pass
|
| 3367 |
+
from connector_onboarding import choices
|
| 3368 |
return {"type": entry_type,
|
| 3369 |
+
"initialDatabases": choices(entry_type),
|
| 3370 |
"fields": [dict(field) for field in fields],
|
| 3371 |
"hint": hint,
|
| 3372 |
"tutorial": _CONNECT_TUTORIALS.get(entry_type),
|
api/routes_keychain.py
CHANGED
|
@@ -939,6 +939,16 @@ def add_key(body: dict = Body(default=None), session: Session = Depends(require_
|
|
| 939 |
f"a {etype} connection is what this whole workspace's databases are read "
|
| 940 |
f"through, so it is always business-wide and cannot be a personal connection. "
|
| 941 |
f"An administrator can add it for everyone.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
try:
|
| 943 |
row = kc.add_entry(session.runtime, body.get("label"), body.get("type"),
|
| 944 |
body.get("fields"), session.uname)
|
|
@@ -949,6 +959,13 @@ def add_key(body: dict = Body(default=None), session: Session = Depends(require_
|
|
| 949 |
raise err(400, "bad_entry", str(e))
|
| 950 |
except Exception:
|
| 951 |
raise err(503, "store_unavailable", "the entry was not saved; try again")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 952 |
# ⛔⛔ A PERSONAL ENTRY THAT LOSES ITS SCOPE ROW READS AS BUSINESS-WIDE — i.e. the failure mode
|
| 953 |
# of a side bucket is to publish a credential, not to hide one. So the second write is not
|
| 954 |
# best-effort: if it does not land, the entry is REMOVED and the caller is told nothing was
|
|
|
|
| 939 |
f"a {etype} connection is what this whole workspace's databases are read "
|
| 940 |
f"through, so it is always business-wide and cannot be a personal connection. "
|
| 941 |
f"An administrator can add it for everyone.")
|
| 942 |
+
if "initialDatabases" in body:
|
| 943 |
+
from connector_onboarding import install_selection
|
| 944 |
+
try:
|
| 945 |
+
existing = any(entry.get("type") == etype for entry in kc.list_entries(session.runtime))
|
| 946 |
+
existing = existing or (etype == "odoo" and env_odoo_available(session.runtime))
|
| 947 |
+
install_selection(session.runtime, etype, body["initialDatabases"], existing=existing)
|
| 948 |
+
except ValueError as exc:
|
| 949 |
+
raise err(400, "bad_initial_selection", str(exc))
|
| 950 |
+
except Exception:
|
| 951 |
+
raise err(503, "store_unavailable", "The database choices were not saved. Try again.")
|
| 952 |
try:
|
| 953 |
row = kc.add_entry(session.runtime, body.get("label"), body.get("type"),
|
| 954 |
body.get("fields"), session.uname)
|
|
|
|
| 959 |
raise err(400, "bad_entry", str(e))
|
| 960 |
except Exception:
|
| 961 |
raise err(503, "store_unavailable", "the entry was not saved; try again")
|
| 962 |
+
if "initialDatabases" in body:
|
| 963 |
+
from connector_onboarding import seal_selection
|
| 964 |
+
try:
|
| 965 |
+
seal_selection(session.runtime, etype)
|
| 966 |
+
except Exception:
|
| 967 |
+
raise err(503, "store_unavailable",
|
| 968 |
+
"The key was saved, but setup did not finish. Open Settings before trying again.")
|
| 969 |
# ⛔⛔ A PERSONAL ENTRY THAT LOSES ITS SCOPE ROW READS AS BUSINESS-WIDE — i.e. the failure mode
|
| 970 |
# of a side bucket is to publish a credential, not to hide one. So the second write is not
|
| 971 |
# best-effort: if it does not land, the entry is REMOVED and the caller is told nothing was
|
api/routes_odoo_tables.py
CHANGED
|
@@ -112,7 +112,10 @@ def _table_cursor(rt, table_key=None):
|
|
| 112 |
if rt is not None:
|
| 113 |
rt.assert_datastore_matches()
|
| 114 |
return datastore.ro_cursor()
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
@router.post("/odoo-tables/refresh")
|
|
@@ -1096,6 +1099,8 @@ def _odoo_sources():
|
|
| 1096 |
"move_type": ("move_type", _s),
|
| 1097 |
},
|
| 1098 |
}
|
|
|
|
|
|
|
| 1099 |
return GRID_SOURCES
|
| 1100 |
|
| 1101 |
|
|
|
|
| 112 |
if rt is not None:
|
| 113 |
rt.assert_datastore_matches()
|
| 114 |
return datastore.ro_cursor()
|
| 115 |
+
if rt is not None:
|
| 116 |
+
from connector_onboarding import mirror_cursor
|
| 117 |
+
return mirror_cursor(rt, table_key)
|
| 118 |
+
return datastore.ro_con()
|
| 119 |
|
| 120 |
|
| 121 |
@router.post("/odoo-tables/refresh")
|
|
|
|
| 1099 |
"move_type": ("move_type", _s),
|
| 1100 |
},
|
| 1101 |
}
|
| 1102 |
+
GRID_SOURCES.update(rel.stock_source_specs())
|
| 1103 |
+
GRID_SOURCES.update(rel.purchase_source_specs())
|
| 1104 |
return GRID_SOURCES
|
| 1105 |
|
| 1106 |
|
platform/core/store_pg.py
CHANGED
|
@@ -655,21 +655,15 @@ class StoreDocumentTooLarge(RuntimeError):
|
|
| 655 |
|
| 656 |
def _payload(name, data, con=None, tenant_slug=None):
|
| 657 |
"""Serialize `data` for `name` through the byte budget and the ceiling. Raises when refused."""
|
| 658 |
-
payload = json.dumps(data)
|
| 659 |
if str(name) == 'user_tables' and isinstance(data, dict):
|
| 660 |
from core import user_tables as _ut
|
| 661 |
-
#
|
| 662 |
-
|
| 663 |
-
if
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
payload = json.dumps(data)
|
| 669 |
-
if report['evicted']:
|
| 670 |
-
print('[store_pg] user_tables byte budget: stored no rows for '
|
| 671 |
-
+ ', '.join(f'{k} ({v / 1048576:.1f} MB)'
|
| 672 |
-
for k, v in sorted(report['evicted'].items())))
|
| 673 |
if len(payload) > DOCUMENT_CEILING_BYTES:
|
| 674 |
before = None
|
| 675 |
if con is not None:
|
|
|
|
| 655 |
|
| 656 |
def _payload(name, data, con=None, tenant_slug=None):
|
| 657 |
"""Serialize `data` for `name` through the byte budget and the ceiling. Raises when refused."""
|
|
|
|
| 658 |
if str(name) == 'user_tables' and isinstance(data, dict):
|
| 659 |
from core import user_tables as _ut
|
| 660 |
+
# Read-through copies must never persist, even below the size budget.
|
| 661 |
+
report = _ut.enforce_byte_budget(data)
|
| 662 |
+
if report['evicted']:
|
| 663 |
+
print('[store_pg] user_tables byte budget: stored no rows for '
|
| 664 |
+
+ ', '.join(f'{k} ({v / 1048576:.1f} MB)'
|
| 665 |
+
for k, v in sorted(report['evicted'].items())))
|
| 666 |
+
payload = json.dumps(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
if len(payload) > DOCUMENT_CEILING_BYTES:
|
| 668 |
before = None
|
| 669 |
if con is not None:
|
platform/core/users.py
CHANGED
|
@@ -747,7 +747,8 @@ def create_user(username, pw, name, role='user', bus='all', modules='all',
|
|
| 747 |
the carry-and-bump lives here rather than in each caller: an overwrite is at least as
|
| 748 |
session-invalidating as a password change, and it usually IS one.
|
| 749 |
"""
|
| 750 |
-
|
|
|
|
| 751 |
if not username:
|
| 752 |
raise ValueError('username and password are required')
|
| 753 |
# Refuse before the update so even an empty password names its broken rules and writes nothing.
|
|
@@ -769,6 +770,8 @@ def create_user(username, pw, name, role='user', bus='all', modules='all',
|
|
| 769 |
# their own plane. None = leave as it was; True/False = set it deliberately.
|
| 770 |
platform_admin=(prior.get('platform_admin') is True
|
| 771 |
if platform_admin is None else platform_admin is True))
|
|
|
|
|
|
|
| 772 |
if prior:
|
| 773 |
rec['epoch'] = int(prior.get('epoch') or 0) + 1
|
| 774 |
reg[username] = rec
|
|
|
|
| 747 |
the carry-and-bump lives here rather than in each caller: an overwrite is at least as
|
| 748 |
session-invalidating as a password change, and it usually IS one.
|
| 749 |
"""
|
| 750 |
+
original_username = (username or '').strip()
|
| 751 |
+
username = original_username.lower()
|
| 752 |
if not username:
|
| 753 |
raise ValueError('username and password are required')
|
| 754 |
# Refuse before the update so even an empty password names its broken rules and writes nothing.
|
|
|
|
| 770 |
# their own plane. None = leave as it was; True/False = set it deliberately.
|
| 771 |
platform_admin=(prior.get('platform_admin') is True
|
| 772 |
if platform_admin is None else platform_admin is True))
|
| 773 |
+
# Display spelling is separate from the key used by auth, grants and workspaces.
|
| 774 |
+
rec['username_original'] = prior.get('username_original') or original_username
|
| 775 |
if prior:
|
| 776 |
rec['epoch'] = int(prior.get('epoch') or 0) + 1
|
| 777 |
reg[username] = rec
|
platform/harness/datastore.py
CHANGED
|
@@ -254,7 +254,7 @@ ENTITIES = {
|
|
| 254 |
# carry a real barcode and 1,997 carry none. It is a `store=True` char column on
|
| 255 |
# `product.product`, so the mirror can hold it.
|
| 256 |
"fields": ["default_code", "name", "categ_id", "type", "standard_price", "active",
|
| 257 |
-
"barcode", "write_date"],
|
| 258 |
# ⛔ WITHOUT THIS THE COLUMN ALTERS IN AND STAYS NULL FOREVER — the same trap
|
| 259 |
# `account_move.invoice_origin` and the `res_partner` address block are both commented
|
| 260 |
# for. WE moved the schema; no product's `write_date` moved, so an incremental
|
|
@@ -270,7 +270,7 @@ ENTITIES = {
|
|
| 270 |
# DOES NOT COME FROM HERE: it comes live from `modules/products.py::catalogue()`. This
|
| 271 |
# column exists so the mirror is not permanently blind to a field the source has, which is
|
| 272 |
# D-165's shape; widening `read_products` is a separate ticket with its own fence.
|
| 273 |
-
"backfill_fields": ["barcode"
|
| 274 |
},
|
| 275 |
"account_move": {
|
| 276 |
"model": "account.move", "archivable": False,
|
|
@@ -355,8 +355,9 @@ ENTITIES = {
|
|
| 355 |
# ⛔ `optional` — see `ready()`. A NEW entity must never gate the readiness of surfaces
|
| 356 |
# that do not read it, or adding one takes the product down until it has synced.
|
| 357 |
"model": "stock.move", "archivable": False, "optional": True,
|
| 358 |
-
"fields": ["product_id", "quantity_done", "date", "state",
|
| 359 |
"location_id", "location_dest_id", "picking_id", "write_date"],
|
|
|
|
| 360 |
},
|
| 361 |
# ⭐ THE USAGE LOOKUP, WITHOUT WHICH THE ROW ABOVE CANNOT BE READ. `location_id` syncs as
|
| 362 |
# `location_id` + `location_id_name` (the m2o convention) — a NAME, never a usage — so the
|
|
@@ -369,7 +370,26 @@ ENTITIES = {
|
|
| 369 |
# which; that choice lives in `model/metrics/stock.yml`, not here.
|
| 370 |
"stock_location": {
|
| 371 |
"model": "stock.location", "archivable": True, "optional": True,
|
| 372 |
-
"fields": ["name", "complete_name", "usage", "active", "write_date"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
},
|
| 374 |
}
|
| 375 |
|
|
@@ -955,14 +975,18 @@ NUMERIC_FIELDS = ("amount_untaxed", "amount_untaxed_signed", "amount_residual_si
|
|
| 955 |
"price_subtotal", "margin", "purchase_price", "product_uom_qty",
|
| 956 |
"standard_price", "debit", "credit", "balance", "amount",
|
| 957 |
# W37-T13 — the stock-movement quantity. See the note above.
|
| 958 |
-
"quantity_done"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
|
| 960 |
|
| 961 |
def _cols(spec):
|
| 962 |
cols = ["id BIGINT PRIMARY KEY"]
|
| 963 |
for f in spec["fields"]:
|
| 964 |
base = f.removesuffix("_id")
|
| 965 |
-
if f.endswith("_id"):
|
| 966 |
cols += [f"{base}_id BIGINT", f"{base}_name VARCHAR"]
|
| 967 |
elif f in BOOL_FIELDS:
|
| 968 |
cols.append(f"{f} BOOLEAN")
|
|
@@ -997,7 +1021,7 @@ def _ensure_columns(con, key, spec):
|
|
| 997 |
|
| 998 |
def _field_cols(f):
|
| 999 |
"""The store column(s) one spec field materialises into (m2o fields become _id + _name)."""
|
| 1000 |
-
if f.endswith("_id"):
|
| 1001 |
base = f.removesuffix("_id")
|
| 1002 |
return [f"{base}_id", f"{base}_name"]
|
| 1003 |
return [f]
|
|
@@ -1301,7 +1325,7 @@ def sync_all(entities=None, max_batches=200, log=print):
|
|
| 1301 |
_paused_notice("sync", log)
|
| 1302 |
return {}
|
| 1303 |
out = {}
|
| 1304 |
-
for key in (
|
| 1305 |
t0 = time.time()
|
| 1306 |
phase, pulled = sync_entity(key, max_batches=max_batches, log=log)
|
| 1307 |
out[key] = {"phase": phase, "pulled": pulled, "secs": round(time.time() - t0, 1)}
|
|
@@ -1328,7 +1352,7 @@ def reconcile_deletes(entities=None, log=print):
|
|
| 1328 |
con = connect()
|
| 1329 |
try:
|
| 1330 |
out = {}
|
| 1331 |
-
for key in (
|
| 1332 |
spec = ENTITIES[key]
|
| 1333 |
# HOTFIX 2026-09-29: DETECT FIRST, then walk. The cursor sync has already pulled every
|
| 1334 |
# created row, so the mirror can only hold MORE rows than the source when something
|
|
|
|
| 254 |
# carry a real barcode and 1,997 carry none. It is a `store=True` char column on
|
| 255 |
# `product.product`, so the mirror can hold it.
|
| 256 |
"fields": ["default_code", "name", "categ_id", "type", "standard_price", "active",
|
| 257 |
+
"barcode", "uom_id", "write_date"],
|
| 258 |
# ⛔ WITHOUT THIS THE COLUMN ALTERS IN AND STAYS NULL FOREVER — the same trap
|
| 259 |
# `account_move.invoice_origin` and the `res_partner` address block are both commented
|
| 260 |
# for. WE moved the schema; no product's `write_date` moved, so an incremental
|
|
|
|
| 270 |
# DOES NOT COME FROM HERE: it comes live from `modules/products.py::catalogue()`. This
|
| 271 |
# column exists so the mirror is not permanently blind to a field the source has, which is
|
| 272 |
# D-165's shape; widening `read_products` is a separate ticket with its own fence.
|
| 273 |
+
"backfill_fields": ["barcode", "uom_id"],
|
| 274 |
},
|
| 275 |
"account_move": {
|
| 276 |
"model": "account.move", "archivable": False,
|
|
|
|
| 355 |
# ⛔ `optional` — see `ready()`. A NEW entity must never gate the readiness of surfaces
|
| 356 |
# that do not read it, or adding one takes the product down until it has synced.
|
| 357 |
"model": "stock.move", "archivable": False, "optional": True,
|
| 358 |
+
"fields": ["name", "product_id", "product_uom", "quantity_done", "date", "state",
|
| 359 |
"location_id", "location_dest_id", "picking_id", "write_date"],
|
| 360 |
+
"backfill_fields": ["name", "product_uom"],
|
| 361 |
},
|
| 362 |
# ⭐ THE USAGE LOOKUP, WITHOUT WHICH THE ROW ABOVE CANNOT BE READ. `location_id` syncs as
|
| 363 |
# `location_id` + `location_id_name` (the m2o convention) — a NAME, never a usage — so the
|
|
|
|
| 370 |
# which; that choice lives in `model/metrics/stock.yml`, not here.
|
| 371 |
"stock_location": {
|
| 372 |
"model": "stock.location", "archivable": True, "optional": True,
|
| 373 |
+
"fields": ["name", "complete_name", "usage", "active", "parent_path", "write_date"],
|
| 374 |
+
"backfill_fields": ["parent_path"],
|
| 375 |
+
},
|
| 376 |
+
"stock_valuation_layer": {
|
| 377 |
+
"model": "stock.valuation.layer", "archivable": False, "optional": True,
|
| 378 |
+
"fields": ["product_id", "quantity", "value", "create_date", "stock_move_id", "write_date"],
|
| 379 |
+
},
|
| 380 |
+
"stock_quant": {
|
| 381 |
+
"model": "stock.quant", "archivable": False, "optional": True,
|
| 382 |
+
"fields": ["product_id", "location_id", "quantity", "reserved_quantity", "write_date"],
|
| 383 |
+
},
|
| 384 |
+
"purchase_order": {
|
| 385 |
+
"model": "purchase.order", "archivable": False, "optional": True,
|
| 386 |
+
"fields": ["name", "partner_id", "date_approve", "date_order", "state",
|
| 387 |
+
"amount_untaxed", "amount_total", "currency_id", "write_date"],
|
| 388 |
+
},
|
| 389 |
+
"purchase_order_line": {
|
| 390 |
+
"model": "purchase.order.line", "archivable": False, "optional": True,
|
| 391 |
+
"fields": ["order_id", "product_id", "product_uom", "product_uom_qty", "product_qty",
|
| 392 |
+
"qty_received", "price_unit", "price_subtotal", "date_planned", "write_date"],
|
| 393 |
},
|
| 394 |
}
|
| 395 |
|
|
|
|
| 975 |
"price_subtotal", "margin", "purchase_price", "product_uom_qty",
|
| 976 |
"standard_price", "debit", "credit", "balance", "amount",
|
| 977 |
# W37-T13 — the stock-movement quantity. See the note above.
|
| 978 |
+
"quantity_done", "quantity", "value", "reserved_quantity",
|
| 979 |
+
"amount_total", "product_qty", "qty_received", "price_unit")
|
| 980 |
+
|
| 981 |
+
# Odoo also names this many2one without the usual `_id` suffix.
|
| 982 |
+
MANY2ONE_FIELDS = frozenset({"product_uom"})
|
| 983 |
|
| 984 |
|
| 985 |
def _cols(spec):
|
| 986 |
cols = ["id BIGINT PRIMARY KEY"]
|
| 987 |
for f in spec["fields"]:
|
| 988 |
base = f.removesuffix("_id")
|
| 989 |
+
if f.endswith("_id") or f in MANY2ONE_FIELDS:
|
| 990 |
cols += [f"{base}_id BIGINT", f"{base}_name VARCHAR"]
|
| 991 |
elif f in BOOL_FIELDS:
|
| 992 |
cols.append(f"{f} BOOLEAN")
|
|
|
|
| 1021 |
|
| 1022 |
def _field_cols(f):
|
| 1023 |
"""The store column(s) one spec field materialises into (m2o fields become _id + _name)."""
|
| 1024 |
+
if f.endswith("_id") or f in MANY2ONE_FIELDS:
|
| 1025 |
base = f.removesuffix("_id")
|
| 1026 |
return [f"{base}_id", f"{base}_name"]
|
| 1027 |
return [f]
|
|
|
|
| 1325 |
_paused_notice("sync", log)
|
| 1326 |
return {}
|
| 1327 |
out = {}
|
| 1328 |
+
for key in (list(ENTITIES) if entities is None else entities):
|
| 1329 |
t0 = time.time()
|
| 1330 |
phase, pulled = sync_entity(key, max_batches=max_batches, log=log)
|
| 1331 |
out[key] = {"phase": phase, "pulled": pulled, "secs": round(time.time() - t0, 1)}
|
|
|
|
| 1352 |
con = connect()
|
| 1353 |
try:
|
| 1354 |
out = {}
|
| 1355 |
+
for key in (list(ENTITIES) if entities is None else entities):
|
| 1356 |
spec = ENTITIES[key]
|
| 1357 |
# HOTFIX 2026-09-29: DETECT FIRST, then walk. The cursor sync has already pulled every
|
| 1358 |
# created row, so the mirror can only hold MORE rows than the source when something
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
cd10a6eaf0d0fd25401ff83e82e559fd52504b0916729a79c9fa9dc6a483488e
|
web/src/connectors/ConnectTutorial.tsx
CHANGED
|
@@ -32,6 +32,7 @@ type SetupSpec = ConnectorConnectSpec & {
|
|
| 32 |
hint: string;
|
| 33 |
fieldHints: Record<string, string>;
|
| 34 |
tutorial: TutorialGuide;
|
|
|
|
| 35 |
};
|
| 36 |
type SetupRead = { phase: "loading" } | { phase: "error"; message: string }
|
| 37 |
| { phase: "held" } | { phase: "ready"; spec: SetupSpec };
|
|
@@ -78,6 +79,7 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 78 |
const [label, setLabel] = useState(row.label);
|
| 79 |
const [scope, setScope] = useState("");
|
| 80 |
const [values, setValues] = useState<Record<string, string>>({});
|
|
|
|
| 81 |
const [storedId, setStoredId] = useState<string | null>(null);
|
| 82 |
const [busy, setBusy] = useState(false);
|
| 83 |
const [error, setError] = useState("");
|
|
@@ -125,7 +127,11 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 125 |
}
|
| 126 |
setValues(Object.fromEntries(spec.fields.map((field) => [field.key, field.default ?? ""])));
|
| 127 |
setScope(spec.scopes[0]);
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
} catch {
|
| 130 |
if (!controller.signal.aborted) setRead({ phase: "error", message: "Cannot reach the server. Try again." });
|
| 131 |
}
|
|
@@ -149,7 +155,11 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 149 |
const { spec } = read;
|
| 150 |
const complete = Boolean(label.trim()) && spec.scopes.includes(scope)
|
| 151 |
&& spec.fields.every((field) => Boolean(values[field.key]?.trim()));
|
| 152 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
const test = async () => {
|
| 155 |
if (inFlight.current || !complete || uncertainSave) return;
|
|
@@ -163,6 +173,7 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 163 |
const result = await call("/admin/keychain", {
|
| 164 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 165 |
body: JSON.stringify({ label: label.trim(), type: spec.type, scope,
|
|
|
|
| 166 |
fields: Object.fromEntries(spec.fields.map((field) => [field.key, values[field.key].trim()])) }),
|
| 167 |
});
|
| 168 |
if (!mounted.current || result.stopped) return;
|
|
@@ -204,7 +215,7 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 204 |
}
|
| 205 |
clearConnectorDetailCache();
|
| 206 |
setValues({});
|
| 207 |
-
setStep(
|
| 208 |
} catch {
|
| 209 |
if (!mounted.current) return;
|
| 210 |
if (saving) {
|
|
@@ -223,14 +234,14 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 223 |
<ConnectionWizard title={titles[step]} titleId="conn-tutorial-title" headingRef={heading}
|
| 224 |
stepKey={String(step + 1)} stepIndex={step} stepCount={titles.length}
|
| 225 |
footer={<>
|
| 226 |
-
{step > 0 && step <
|
| 227 |
onClick={() => setStep(step - 1)}>Back</button> : null}
|
| 228 |
-
{step <
|
| 229 |
disabled={busy || (step === 2 && !complete)} onClick={() => setStep(step + 1)}>Next</button> : null}
|
| 230 |
-
{step ===
|
| 231 |
disabled={busy || !complete || uncertainSave} onClick={() => void test()}>
|
| 232 |
{busy ? "Testing…" : storedId ? "Test again" : "Test"}</button> : null}
|
| 233 |
-
{step ===
|
| 234 |
</>}>
|
| 235 |
{step === 0 ? <p className="external-sub">{spec.tutorial.need}</p> : null}
|
| 236 |
{step === 1 ? <>
|
|
@@ -261,7 +272,16 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 261 |
</div>)}
|
| 262 |
{storedId || uncertainSave ? <button type="button" className="conn-tutorial-button" onClick={onOpenSettings}>Connection settings</button> : null}
|
| 263 |
</div> : null}
|
| 264 |
-
{step === 3 ? <>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
<p className="conn-tutorial-summary">{screenText(label)}</p>
|
| 266 |
<p className="external-sub">{spec.tutorial.testNote}</p>
|
| 267 |
{error ? <div className="conn-tutorial-error" role="alert">
|
|
@@ -269,7 +289,7 @@ function CredentialTutorial({ row, onDone, onOpenSettings }: {
|
|
| 269 |
{storedId || uncertainSave ? <button type="button" className="conn-tutorial-button" onClick={onOpenSettings}>Connection settings</button> : null}
|
| 270 |
</div> : null}
|
| 271 |
</> : null}
|
| 272 |
-
{step ===
|
| 273 |
? "Key stored" : spec.type === "odoo" ? "Server reachable" : "Connected"}</p> : null}
|
| 274 |
</ConnectionWizard>
|
| 275 |
</div>;
|
|
|
|
| 32 |
hint: string;
|
| 33 |
fieldHints: Record<string, string>;
|
| 34 |
tutorial: TutorialGuide;
|
| 35 |
+
initialDatabases: { key: string; label: string; selected: boolean }[];
|
| 36 |
};
|
| 37 |
type SetupRead = { phase: "loading" } | { phase: "error"; message: string }
|
| 38 |
| { phase: "held" } | { phase: "ready"; spec: SetupSpec };
|
|
|
|
| 79 |
const [label, setLabel] = useState(row.label);
|
| 80 |
const [scope, setScope] = useState("");
|
| 81 |
const [values, setValues] = useState<Record<string, string>>({});
|
| 82 |
+
const [selectedDatabases, setSelectedDatabases] = useState<string[]>([]);
|
| 83 |
const [storedId, setStoredId] = useState<string | null>(null);
|
| 84 |
const [busy, setBusy] = useState(false);
|
| 85 |
const [error, setError] = useState("");
|
|
|
|
| 127 |
}
|
| 128 |
setValues(Object.fromEntries(spec.fields.map((field) => [field.key, field.default ?? ""])));
|
| 129 |
setScope(spec.scopes[0]);
|
| 130 |
+
const initialDatabases = (Array.isArray(rawSpec.initialDatabases) ? rawSpec.initialDatabases : [])
|
| 131 |
+
.map(object).filter((item) => typeof item.key === "string" && typeof item.label === "string")
|
| 132 |
+
.map((item) => ({ key: String(item.key), label: screenText(item.label), selected: item.selected === true }));
|
| 133 |
+
setSelectedDatabases(initialDatabases.filter((item) => item.selected).map((item) => item.key));
|
| 134 |
+
setRead({ phase: "ready", spec: { ...spec, hint: screenText(rawSpec.hint), fieldHints, tutorial, initialDatabases } });
|
| 135 |
} catch {
|
| 136 |
if (!controller.signal.aborted) setRead({ phase: "error", message: "Cannot reach the server. Try again." });
|
| 137 |
}
|
|
|
|
| 155 |
const { spec } = read;
|
| 156 |
const complete = Boolean(label.trim()) && spec.scopes.includes(scope)
|
| 157 |
&& spec.fields.every((field) => Boolean(values[field.key]?.trim()));
|
| 158 |
+
const hasSelection = spec.initialDatabases.length > 0;
|
| 159 |
+
const testStep = hasSelection ? 4 : 3;
|
| 160 |
+
const doneStep = testStep + 1;
|
| 161 |
+
const titles = ["What you need", "Get credentials", "Paste credentials",
|
| 162 |
+
...(hasSelection ? ["Choose databases"] : []), "Test connection", "Done"];
|
| 163 |
|
| 164 |
const test = async () => {
|
| 165 |
if (inFlight.current || !complete || uncertainSave) return;
|
|
|
|
| 173 |
const result = await call("/admin/keychain", {
|
| 174 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 175 |
body: JSON.stringify({ label: label.trim(), type: spec.type, scope,
|
| 176 |
+
...(hasSelection ? { initialDatabases: selectedDatabases } : {}),
|
| 177 |
fields: Object.fromEntries(spec.fields.map((field) => [field.key, values[field.key].trim()])) }),
|
| 178 |
});
|
| 179 |
if (!mounted.current || result.stopped) return;
|
|
|
|
| 215 |
}
|
| 216 |
clearConnectorDetailCache();
|
| 217 |
setValues({});
|
| 218 |
+
setStep(doneStep);
|
| 219 |
} catch {
|
| 220 |
if (!mounted.current) return;
|
| 221 |
if (saving) {
|
|
|
|
| 234 |
<ConnectionWizard title={titles[step]} titleId="conn-tutorial-title" headingRef={heading}
|
| 235 |
stepKey={String(step + 1)} stepIndex={step} stepCount={titles.length}
|
| 236 |
footer={<>
|
| 237 |
+
{step > 0 && step < doneStep ? <button type="button" className="conn-tutorial-button" disabled={busy}
|
| 238 |
onClick={() => setStep(step - 1)}>Back</button> : null}
|
| 239 |
+
{step < testStep ? <button type="button" className="conn-tutorial-button is-primary external-next"
|
| 240 |
disabled={busy || (step === 2 && !complete)} onClick={() => setStep(step + 1)}>Next</button> : null}
|
| 241 |
+
{step === testStep ? <button type="button" className="conn-tutorial-button is-primary external-next"
|
| 242 |
disabled={busy || !complete || uncertainSave} onClick={() => void test()}>
|
| 243 |
{busy ? "Testing…" : storedId ? "Test again" : "Test"}</button> : null}
|
| 244 |
+
{step === doneStep ? <button type="button" className="conn-tutorial-button is-primary external-next" onClick={onDone}>Done</button> : null}
|
| 245 |
</>}>
|
| 246 |
{step === 0 ? <p className="external-sub">{spec.tutorial.need}</p> : null}
|
| 247 |
{step === 1 ? <>
|
|
|
|
| 272 |
</div>)}
|
| 273 |
{storedId || uncertainSave ? <button type="button" className="conn-tutorial-button" onClick={onOpenSettings}>Connection settings</button> : null}
|
| 274 |
</div> : null}
|
| 275 |
+
{hasSelection && step === 3 ? <div className="conn-tutorial-fields">
|
| 276 |
+
{spec.initialDatabases.map((database) => <label key={database.key} className="conn-tutorial-choice">
|
| 277 |
+
<input type="checkbox" checked={selectedDatabases.includes(database.key)}
|
| 278 |
+
disabled={busy || storedId !== null || uncertainSave}
|
| 279 |
+
onChange={(event) => setSelectedDatabases((current) => event.target.checked
|
| 280 |
+
? [...current, database.key] : current.filter((key) => key !== database.key))} />
|
| 281 |
+
{database.label}
|
| 282 |
+
</label>)}
|
| 283 |
+
</div> : null}
|
| 284 |
+
{step === testStep ? <>
|
| 285 |
<p className="conn-tutorial-summary">{screenText(label)}</p>
|
| 286 |
<p className="external-sub">{spec.tutorial.testNote}</p>
|
| 287 |
{error ? <div className="conn-tutorial-error" role="alert">
|
|
|
|
| 289 |
{storedId || uncertainSave ? <button type="button" className="conn-tutorial-button" onClick={onOpenSettings}>Connection settings</button> : null}
|
| 290 |
</div> : null}
|
| 291 |
</> : null}
|
| 292 |
+
{step === doneStep ? <p className="external-sub" role="status">{spec.type === "stripe" || spec.type === "shopify"
|
| 293 |
? "Key stored" : spec.type === "odoo" ? "Server reachable" : "Connected"}</p> : null}
|
| 294 |
</ConnectionWizard>
|
| 295 |
</div>;
|
web/src/connectors/connectors.css
CHANGED
|
@@ -137,6 +137,19 @@
|
|
| 137 |
.external-steps strong { font-weight: 600; }
|
| 138 |
|
| 139 |
.conn-tutorial-fields { display: grid; gap: calc(var(--lp-r-sm) * 4); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
.conn-tutorial-field { display: grid; gap: var(--lp-r-sm); }
|
| 141 |
.conn-tutorial-field label { font-size: var(--lp-fs-xs); font-weight: 500; color: var(--lp-ink); }
|
| 142 |
.conn-tutorial-field input,
|
|
|
|
| 137 |
.external-steps strong { font-weight: 600; }
|
| 138 |
|
| 139 |
.conn-tutorial-fields { display: grid; gap: calc(var(--lp-r-sm) * 4); }
|
| 140 |
+
.conn-tutorial-choice {
|
| 141 |
+
display: flex;
|
| 142 |
+
align-items: center;
|
| 143 |
+
gap: calc(var(--lp-r-sm) * 2);
|
| 144 |
+
font-size: var(--lp-fs-xs);
|
| 145 |
+
color: var(--lp-ink);
|
| 146 |
+
}
|
| 147 |
+
.conn-tutorial-choice input { accent-color: var(--lp-primary); }
|
| 148 |
+
.conn-tutorial-choice input:disabled { opacity: 0.5; cursor: not-allowed; }
|
| 149 |
+
.conn-tutorial-choice input:focus-visible {
|
| 150 |
+
outline: calc(var(--lp-r-sm) / 2) solid var(--lp-blue-deep);
|
| 151 |
+
outline-offset: var(--lp-r-sm);
|
| 152 |
+
}
|
| 153 |
.conn-tutorial-field { display: grid; gap: var(--lp-r-sm); }
|
| 154 |
.conn-tutorial-field label { font-size: var(--lp-fs-xs); font-weight: 500; color: var(--lp-ink); }
|
| 155 |
.conn-tutorial-field input,
|
web/src/shell/Shell.tsx
CHANGED
|
@@ -1611,6 +1611,8 @@ function AccountMenu({
|
|
| 1611 |
className="shell-menu-item"
|
| 1612 |
role="menuitem"
|
| 1613 |
onClick={() => {
|
|
|
|
|
|
|
| 1614 |
setOpen(false);
|
| 1615 |
onSettings("account");
|
| 1616 |
}}
|
|
|
|
| 1611 |
className="shell-menu-item"
|
| 1612 |
role="menuitem"
|
| 1613 |
onClick={() => {
|
| 1614 |
+
// Settings outlives this menu item; its opener must stay mounted.
|
| 1615 |
+
wrap.current?.querySelector<HTMLButtonElement>(".shell-account")?.focus();
|
| 1616 |
setOpen(false);
|
| 1617 |
onSettings("account");
|
| 1618 |
}}
|