Compare commits
88 Commits
8be0caa474
...
fusion_acc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
848aa0f0e5 | ||
|
|
5a864e4b48 | ||
|
|
0618ca7773 | ||
|
|
6a53da6002 | ||
|
|
3c7a1c8cea | ||
|
|
1c773bb5e4 | ||
|
|
5994a1b96b | ||
|
|
e17e7f9e4c | ||
|
|
8de4beb46a | ||
|
|
7d7bd93345 | ||
|
|
23b988c401 | ||
|
|
d1661f3a33 | ||
|
|
8b6dd3aa63 | ||
|
|
4677fae891 | ||
|
|
1918e03485 | ||
|
|
6d020f6419 | ||
|
|
b33e12e587 | ||
|
|
1ffa86b532 | ||
|
|
1f94927f12 | ||
|
|
97640a5ac8 | ||
|
|
9db7271bdf | ||
|
|
0f575dd523 | ||
|
|
16db299145 | ||
|
|
144e90a379 | ||
|
|
118f0d9d16 | ||
|
|
15cf4e129f | ||
|
|
5cdd3e756d | ||
|
|
c20e0888e1 | ||
|
|
22b277c6b8 | ||
|
|
17053b1603 | ||
|
|
a4728d7ae7 | ||
|
|
b78e6dc842 | ||
|
|
5963aba0a8 | ||
|
|
f160a9eeec | ||
|
|
ba95d927c0 | ||
|
|
96ac0131b0 | ||
|
|
cabf51add7 | ||
|
|
0eee14f69a | ||
|
|
9d3b8f7484 | ||
|
|
50f736d8a7 | ||
|
|
e14ad21689 | ||
|
|
0a9ed635e8 | ||
|
|
a93162cb70 | ||
|
|
a90a349fbc | ||
|
|
6e53955e9c | ||
|
|
8dab9b36da | ||
|
|
14e59148c6 | ||
|
|
55eb368195 | ||
|
|
d623b67157 | ||
|
|
aaaf49989c | ||
|
|
878c013902 | ||
|
|
ffc029a875 | ||
|
|
6d90789967 | ||
|
|
6048df0645 | ||
|
|
b6aedc9bbe | ||
|
|
25f033d0c8 | ||
|
|
75850aad73 | ||
|
|
5c3e7a3cf3 | ||
|
|
e01a2a0e35 | ||
|
|
6cbb5f85fe | ||
|
|
596ecb9e03 | ||
|
|
99e27cc566 | ||
|
|
8fc864623b | ||
|
|
c9ac4c64fb | ||
|
|
b06e01babb | ||
|
|
11837ed4f5 | ||
|
|
9e4de89269 | ||
|
|
1634ecd4f6 | ||
|
|
3e48bab087 | ||
|
|
a4a9692888 | ||
|
|
d4dbca5927 | ||
|
|
24e2708d98 | ||
|
|
6ecb1bbbee | ||
|
|
050d3d06a7 | ||
|
|
41336b179f | ||
|
|
d1819b940e | ||
|
|
f979bc686d | ||
|
|
d953525758 | ||
|
|
12b6b46e2e | ||
|
|
7fa54d8fc9 | ||
|
|
4ffbdc596d | ||
|
|
5020129c45 | ||
|
|
3993f58910 | ||
|
|
8eee64f053 | ||
|
|
2d099b2d0d | ||
|
|
c7ecd90982 | ||
|
|
2804168d9e | ||
|
|
6e964c230f |
167
fusion_accounting/PHASE_2_PLAN.md
Normal file
167
fusion_accounting/PHASE_2_PLAN.md
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
# Phase 2 — Fusion Accounting Reports Implementation Plan
|
||||||
|
|
||||||
|
**Module:** `fusion_accounting_reports`
|
||||||
|
**Branch:** `fusion_accounting/phase-2-reports`
|
||||||
|
**Pre-phase tag:** `fusion_accounting/pre-phase-2`
|
||||||
|
**Estimated tasks:** 46
|
||||||
|
**Reference:** `/Users/gurpreet/Github/RePackaged-Odoo/accounting/account_reports/`
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Replace Odoo Enterprise's `account_reports` module with a Fusion-native financial reports engine. CORE scope: P&L (income statement), balance sheet, trial balance, general ledger with drill-down. AI augmentation: anomaly detection (variance vs prior period) + AI-generated commentary. Coexists with Enterprise (Enterprise wins by default; Fusion menu shows when Enterprise absent).
|
||||||
|
|
||||||
|
## Architecture (HYBRID engine)
|
||||||
|
|
||||||
|
```
|
||||||
|
fusion.report.engine (AbstractModel) ← shared primitives
|
||||||
|
├── compute_pnl(period, comparison=None)
|
||||||
|
├── compute_balance_sheet(date_to, comparison=None)
|
||||||
|
├── compute_trial_balance(period)
|
||||||
|
├── compute_gl(period, account_ids=None)
|
||||||
|
├── drill_down(report_type, line_id, period)
|
||||||
|
└── _walk_account_hierarchy(root_account_ids)
|
||||||
|
|
||||||
|
services/ ← pure-Python
|
||||||
|
├── date_periods.py → fiscal-period math, comparison-period derivation
|
||||||
|
├── account_hierarchy.py → recursive account tree walk + roll-ups
|
||||||
|
├── totaling.py → balance/credit/debit aggregation rules
|
||||||
|
├── currency_conversion.py → multi-currency revaluation at report date
|
||||||
|
├── anomaly_detection.py → variance vs prior-period statistical flags
|
||||||
|
└── commentary_generator.py → LLM prompt + parse for narrative
|
||||||
|
|
||||||
|
models/
|
||||||
|
├── fusion_report.py → report definition (metadata, line specs)
|
||||||
|
├── fusion_report_engine.py → AbstractModel orchestrator
|
||||||
|
├── fusion_report_pnl.py → P&L definition + execute
|
||||||
|
├── fusion_report_balance_sheet.py
|
||||||
|
├── fusion_report_trial_balance.py
|
||||||
|
├── fusion_report_general_ledger.py
|
||||||
|
├── fusion_report_anomaly.py → persisted flagged variances
|
||||||
|
├── fusion_report_commentary.py → cached AI narratives
|
||||||
|
└── fusion_unreconciled_gl_mv.py → MV for fast GL listing on large DBs
|
||||||
|
|
||||||
|
controllers/bank_rec_controller.py ← 8 JSON-RPC endpoints
|
||||||
|
├── /fusion/reports/run → execute one report
|
||||||
|
├── /fusion/reports/drill_down → drill into a report line
|
||||||
|
├── /fusion/reports/get_anomalies → list flagged variances
|
||||||
|
├── /fusion/reports/get_commentary → fetch / regenerate narrative
|
||||||
|
├── /fusion/reports/compare_periods → side-by-side comparison
|
||||||
|
├── /fusion/reports/export_pdf → PDF export
|
||||||
|
├── /fusion/reports/export_xlsx → XLSX export
|
||||||
|
└── /fusion/reports/list_available → list all report types
|
||||||
|
|
||||||
|
static/src/
|
||||||
|
├── scss/ ← report-specific design tokens
|
||||||
|
├── services/reports_service.js ← reactive state + RPC wrappers
|
||||||
|
├── views/reports_viewer/ ← top-level OWL controller
|
||||||
|
└── components/ ← report_table, drill_down_dialog,
|
||||||
|
period_filter, ai_commentary_panel,
|
||||||
|
anomaly_strip
|
||||||
|
```
|
||||||
|
|
||||||
|
## Coexistence
|
||||||
|
|
||||||
|
Same pattern as Phase 1: `group_fusion_show_when_enterprise_absent` from `fusion_accounting_core`. Reports menu only visible when `account_reports` is NOT installed. Engine + AI tools always available.
|
||||||
|
|
||||||
|
## Tasks (46 total)
|
||||||
|
|
||||||
|
### Group 1: Foundation (tasks 1-2)
|
||||||
|
1. Safety net (tag pre-phase-2, branch phase-2-reports) — **DONE**
|
||||||
|
2. Plan doc + module skeleton
|
||||||
|
|
||||||
|
### Group 2: Engine primitives — TDD layered (tasks 3-8)
|
||||||
|
3. `services/date_periods.py` (fiscal periods, comparison derivation)
|
||||||
|
4. `services/currency_conversion.py` + `services/account_hierarchy.py` + `services/totaling.py`
|
||||||
|
5. `models/fusion_report.py` (report definition model)
|
||||||
|
6. `services/line_resolver.py` (compute report rows from definition)
|
||||||
|
7. `services/drill_down_resolver.py`
|
||||||
|
8. `models/fusion_report_engine.py` (5-method API: compute_pnl, compute_balance_sheet, compute_trial_balance, compute_gl, drill_down)
|
||||||
|
|
||||||
|
### Group 3: Per-report models (tasks 9-12)
|
||||||
|
9. P&L (income statement)
|
||||||
|
10. Balance sheet
|
||||||
|
11. Trial balance
|
||||||
|
12. General ledger
|
||||||
|
|
||||||
|
### Group 4: AI features (tasks 13-17)
|
||||||
|
13. Anomaly detection service (variance vs prior period)
|
||||||
|
14. AI commentary service
|
||||||
|
15. Commentary prompt + LLMProvider integration
|
||||||
|
16. `fusion.report.commentary` persisted model
|
||||||
|
17. `fusion.report.anomaly` persisted model
|
||||||
|
|
||||||
|
### Group 5: Backend wiring (tasks 18-20)
|
||||||
|
18. JSON-RPC controller (8 endpoints)
|
||||||
|
19. ReportsAdapter `_via_fusion` paths
|
||||||
|
20. 5 new AI tools
|
||||||
|
|
||||||
|
### Group 6: Tests + perf (tasks 21-25)
|
||||||
|
21. Property-based tests (totals balance invariant)
|
||||||
|
22. Integration tests — P&L correctness vs known fixtures
|
||||||
|
23. Integration tests — balance sheet + trial balance
|
||||||
|
24. Materialized view for GL
|
||||||
|
25. Cron jobs (anomaly scan + commentary refresh)
|
||||||
|
|
||||||
|
### Group 7: Frontend (tasks 26-33)
|
||||||
|
26. SCSS tokens + main report stylesheet
|
||||||
|
27. `reports_service.js`
|
||||||
|
28. `report_viewer` component (top-level)
|
||||||
|
29. `report_table` component (rows, totals, drill chevrons)
|
||||||
|
30. `drill_down_dialog`
|
||||||
|
31. `period_filter` (date range + comparison toggle)
|
||||||
|
32. `ai_commentary_panel` (Fusion-only)
|
||||||
|
33. `anomaly_strip` (Fusion-only)
|
||||||
|
|
||||||
|
### Group 8: Export + wizards (tasks 34-36)
|
||||||
|
34. PDF export (QWeb template per report)
|
||||||
|
35. XLSX export wizard
|
||||||
|
36. Period selection + comparison wizard
|
||||||
|
|
||||||
|
### Group 9: Migration + coexistence (tasks 37-39)
|
||||||
|
37. Migration wizard inheritance (cache existing definitions)
|
||||||
|
38. Menu + window actions with coexistence group filter
|
||||||
|
39. Coexistence test
|
||||||
|
|
||||||
|
### Group 10: Final tests + polish (tasks 40-46)
|
||||||
|
40. 5 OWL tour tests
|
||||||
|
41. Performance benchmarks
|
||||||
|
42. Optimize if benchmarks fail (conditional)
|
||||||
|
43. Local LLM compat test for commentary
|
||||||
|
44. Update meta-module manifest
|
||||||
|
45. CLAUDE.md, UPGRADE_NOTES.md, README.md
|
||||||
|
46. End-to-end smoke + tag phase-2-complete + push
|
||||||
|
|
||||||
|
## Performance Targets (P95)
|
||||||
|
|
||||||
|
- `engine.compute_pnl` (1 year, 500 accounts): <2s
|
||||||
|
- `engine.compute_balance_sheet`: <2s
|
||||||
|
- `engine.compute_trial_balance`: <1s
|
||||||
|
- `engine.compute_gl` (1 month, all accounts): <3s
|
||||||
|
- `engine.drill_down` (1 line): <500ms
|
||||||
|
- Controller `run` endpoint: <2.5s
|
||||||
|
|
||||||
|
## V19 Conventions (from Phase 1 lessons)
|
||||||
|
|
||||||
|
- `models.Constraint` not `_sql_constraints`
|
||||||
|
- No `@api.depends('id')` on stored compute fields
|
||||||
|
- `@route(type='jsonrpc')` not `type='json'`
|
||||||
|
- `ir.cron` has no `numbercall` field
|
||||||
|
- `res.groups.user_ids` not `users`
|
||||||
|
- `ir.ui.menu.group_ids` not `groups_id`
|
||||||
|
- `res.users.all_group_ids` for searches
|
||||||
|
- `models.Constraint` for unique-keys
|
||||||
|
- Prefer `env.flush_all()` before MV REFRESH
|
||||||
|
|
||||||
|
## Test Targets
|
||||||
|
|
||||||
|
Match Phase 1's test pyramid:
|
||||||
|
- Unit (services pure-Python)
|
||||||
|
- Integration (engine end-to-end with factories)
|
||||||
|
- Property-based (Hypothesis, totals balance invariant)
|
||||||
|
- Controller (HttpCase JSON-RPC)
|
||||||
|
- MV correctness
|
||||||
|
- Performance benchmarks (tagged 'benchmark')
|
||||||
|
- OWL tours (tagged 'tour')
|
||||||
|
- Local LLM smoke (tagged 'local_llm', skips when no LLM)
|
||||||
|
|
||||||
|
Phase 1 final: 157 tests passing. Phase 2 target: ~120-150 additional.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
'name': 'Fusion Accounting',
|
'name': 'Fusion Accounting',
|
||||||
'version': '19.0.1.0.0',
|
'version': '19.0.1.0.2',
|
||||||
'category': 'Accounting/Accounting',
|
'category': 'Accounting/Accounting',
|
||||||
'sequence': 25,
|
'sequence': 25,
|
||||||
'summary': 'Meta-module that installs the full Fusion Accounting suite (core, AI, migration; bank rec, reports, etc. as later sub-modules ship).',
|
'summary': 'Meta-module that installs the full Fusion Accounting suite (core, AI, migration; bank rec, reports, etc. as later sub-modules ship).',
|
||||||
@@ -13,10 +13,10 @@ Currently installs:
|
|||||||
- fusion_accounting_core Shared schema, security, runtime helpers
|
- fusion_accounting_core Shared schema, security, runtime helpers
|
||||||
- fusion_accounting_ai AI Co-Pilot (Claude/GPT)
|
- fusion_accounting_ai AI Co-Pilot (Claude/GPT)
|
||||||
- fusion_accounting_migration Transitional Enterprise->Fusion data migration
|
- fusion_accounting_migration Transitional Enterprise->Fusion data migration
|
||||||
|
- fusion_accounting_bank_rec AI-assisted bank reconciliation (Phase 1)
|
||||||
|
- fusion_accounting_reports AI-augmented financial reports (Phase 2)
|
||||||
|
|
||||||
Future sub-modules (added per the roadmap as each Phase ships):
|
Future sub-modules (added per the roadmap as each Phase ships):
|
||||||
- fusion_accounting_bank_rec (Phase 1)
|
|
||||||
- fusion_accounting_reports (Phase 2)
|
|
||||||
- fusion_accounting_dashboard (Phase 3)
|
- fusion_accounting_dashboard (Phase 3)
|
||||||
- fusion_accounting_followup (Phase 5)
|
- fusion_accounting_followup (Phase 5)
|
||||||
- fusion_accounting_assets (Phase 6)
|
- fusion_accounting_assets (Phase 6)
|
||||||
@@ -33,6 +33,8 @@ Built by Nexa Systems Inc.
|
|||||||
'fusion_accounting_core',
|
'fusion_accounting_core',
|
||||||
'fusion_accounting_ai',
|
'fusion_accounting_ai',
|
||||||
'fusion_accounting_migration',
|
'fusion_accounting_migration',
|
||||||
|
'fusion_accounting_bank_rec',
|
||||||
|
'fusion_accounting_reports',
|
||||||
],
|
],
|
||||||
'data': [],
|
'data': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ Routes bank-rec data lookups across:
|
|||||||
- FUSION: fusion.bank.rec.widget (added by fusion_accounting_bank_rec, Phase 1)
|
- FUSION: fusion.bank.rec.widget (added by fusion_accounting_bank_rec, Phase 1)
|
||||||
- ENTERPRISE: account_accountant's bank_rec_widget JS service
|
- ENTERPRISE: account_accountant's bank_rec_widget JS service
|
||||||
- COMMUNITY: pure search on account.bank.statement.line
|
- COMMUNITY: pure search on account.bank.statement.line
|
||||||
|
|
||||||
|
In addition to ``list_unreconciled``, the adapter exposes thin wrappers
|
||||||
|
around the engine's public API: ``suggest_matches``, ``accept_suggestion``,
|
||||||
|
``unreconcile``. AI tools and the OWL controller go through these wrappers
|
||||||
|
instead of touching the engine directly so install-mode routing stays in
|
||||||
|
one place.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .base import DataAdapter
|
from .base import DataAdapter
|
||||||
@@ -14,6 +20,10 @@ class BankRecAdapter(DataAdapter):
|
|||||||
FUSION_MODEL = 'fusion.bank.rec.widget'
|
FUSION_MODEL = 'fusion.bank.rec.widget'
|
||||||
ENTERPRISE_MODULE = 'account_accountant'
|
ENTERPRISE_MODULE = 'account_accountant'
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# list_unreconciled
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
def list_unreconciled(self, journal_id=None, limit=100, date_from=None,
|
def list_unreconciled(self, journal_id=None, limit=100, date_from=None,
|
||||||
date_to=None, min_amount=None, company_id=None):
|
date_to=None, min_amount=None, company_id=None):
|
||||||
"""Return unreconciled bank statement lines.
|
"""Return unreconciled bank statement lines.
|
||||||
@@ -31,13 +41,29 @@ class BankRecAdapter(DataAdapter):
|
|||||||
def list_unreconciled_via_fusion(self, journal_id=None, limit=100,
|
def list_unreconciled_via_fusion(self, journal_id=None, limit=100,
|
||||||
date_from=None, date_to=None,
|
date_from=None, date_to=None,
|
||||||
min_amount=None, company_id=None):
|
min_amount=None, company_id=None):
|
||||||
# Phase 1 will add fusion.bank.rec.widget; this method becomes the primary path.
|
"""Community shape + fusion AI fields (top suggestion, band, attachments)."""
|
||||||
# For now: even when the model exists, delegate to community read shape.
|
base = self.list_unreconciled_via_community(
|
||||||
return self.list_unreconciled_via_community(
|
|
||||||
journal_id=journal_id, limit=limit,
|
journal_id=journal_id, limit=limit,
|
||||||
date_from=date_from, date_to=date_to,
|
date_from=date_from, date_to=date_to,
|
||||||
min_amount=min_amount, company_id=company_id,
|
min_amount=min_amount, company_id=company_id,
|
||||||
)
|
)
|
||||||
|
if not base:
|
||||||
|
return base
|
||||||
|
Line = self.env['account.bank.statement.line'].sudo()
|
||||||
|
ids = [row['id'] for row in base]
|
||||||
|
lines_by_id = {line.id: line for line in Line.browse(ids)}
|
||||||
|
for row in base:
|
||||||
|
line = lines_by_id.get(row['id'])
|
||||||
|
if not line:
|
||||||
|
row['fusion_top_suggestion_id'] = None
|
||||||
|
row['fusion_confidence_band'] = 'none'
|
||||||
|
row['attachment_count'] = 0
|
||||||
|
continue
|
||||||
|
top = line.fusion_top_suggestion_id
|
||||||
|
row['fusion_top_suggestion_id'] = top.id if top else None
|
||||||
|
row['fusion_confidence_band'] = line.fusion_confidence_band or 'none'
|
||||||
|
row['attachment_count'] = len(line.bank_statement_attachment_ids)
|
||||||
|
return base
|
||||||
|
|
||||||
def list_unreconciled_via_enterprise(self, journal_id=None, limit=100,
|
def list_unreconciled_via_enterprise(self, journal_id=None, limit=100,
|
||||||
date_from=None, date_to=None,
|
date_from=None, date_to=None,
|
||||||
@@ -83,5 +109,121 @@ class BankRecAdapter(DataAdapter):
|
|||||||
for r in records
|
for r in records
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# suggest_matches
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
def suggest_matches(self, statement_line_ids, *, limit_per_line=3,
|
||||||
|
company_id=None):
|
||||||
|
"""Return AI suggestions per bank line.
|
||||||
|
|
||||||
|
Shape: ``{line_id: [{'id', 'rank', 'confidence', 'reasoning',
|
||||||
|
'candidate_id'}, ...]}``. Empty dict when AI suggestions are not
|
||||||
|
available (Enterprise / Community).
|
||||||
|
"""
|
||||||
|
return self._dispatch(
|
||||||
|
'suggest_matches',
|
||||||
|
statement_line_ids=statement_line_ids,
|
||||||
|
limit_per_line=limit_per_line,
|
||||||
|
company_id=company_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
def suggest_matches_via_fusion(self, statement_line_ids, *,
|
||||||
|
limit_per_line=3, company_id=None):
|
||||||
|
Line = self.env['account.bank.statement.line'].sudo()
|
||||||
|
lines = Line.browse(list(statement_line_ids or [])).exists()
|
||||||
|
if not lines:
|
||||||
|
return {}
|
||||||
|
return self.env['fusion.reconcile.engine'].suggest_matches(
|
||||||
|
lines, limit_per_line=limit_per_line)
|
||||||
|
|
||||||
|
def suggest_matches_via_enterprise(self, statement_line_ids, *,
|
||||||
|
limit_per_line=3, company_id=None):
|
||||||
|
# Enterprise has its own suggest mechanism inside bank_rec_widget;
|
||||||
|
# we don't proxy it from Python.
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def suggest_matches_via_community(self, statement_line_ids, *,
|
||||||
|
limit_per_line=3, company_id=None):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# accept_suggestion
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
def accept_suggestion(self, suggestion_id):
|
||||||
|
"""Accept a fusion AI suggestion and reconcile against its proposal.
|
||||||
|
|
||||||
|
Returns ``{'partial_ids': [...], 'exchange_diff_move_id': int|None,
|
||||||
|
'write_off_move_id': int|None}``. Fusion-only.
|
||||||
|
"""
|
||||||
|
return self._dispatch(
|
||||||
|
'accept_suggestion', suggestion_id=suggestion_id)
|
||||||
|
|
||||||
|
def accept_suggestion_via_fusion(self, suggestion_id):
|
||||||
|
return self.env['fusion.reconcile.engine'].accept_suggestion(
|
||||||
|
int(suggestion_id))
|
||||||
|
|
||||||
|
def accept_suggestion_via_enterprise(self, suggestion_id):
|
||||||
|
raise NotImplementedError("accept_suggestion is fusion-only")
|
||||||
|
|
||||||
|
def accept_suggestion_via_community(self, suggestion_id):
|
||||||
|
raise NotImplementedError("accept_suggestion is fusion-only")
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# unreconcile
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
def unreconcile(self, partial_reconcile_ids):
|
||||||
|
"""Reverse a reconciliation by partial IDs.
|
||||||
|
|
||||||
|
Returns ``{'unreconciled_line_ids': [...]}``. Available in all modes
|
||||||
|
(the engine delegates to V19's standard
|
||||||
|
``account.bank.statement.line.action_undo_reconciliation``).
|
||||||
|
"""
|
||||||
|
return self._dispatch(
|
||||||
|
'unreconcile', partial_reconcile_ids=partial_reconcile_ids)
|
||||||
|
|
||||||
|
def unreconcile_via_fusion(self, partial_reconcile_ids):
|
||||||
|
Partial = self.env['account.partial.reconcile'].sudo()
|
||||||
|
partials = Partial.browse(list(partial_reconcile_ids or [])).exists()
|
||||||
|
return self.env['fusion.reconcile.engine'].unreconcile(partials)
|
||||||
|
|
||||||
|
def unreconcile_via_enterprise(self, partial_reconcile_ids):
|
||||||
|
# Enterprise/community paths can't depend on fusion.reconcile.engine
|
||||||
|
# being loaded (fusion_accounting_ai does NOT depend on
|
||||||
|
# fusion_accounting_bank_rec). Mirror the engine's behaviour using
|
||||||
|
# only Community-available helpers.
|
||||||
|
return self._unreconcile_standalone(partial_reconcile_ids)
|
||||||
|
|
||||||
|
def unreconcile_via_community(self, partial_reconcile_ids):
|
||||||
|
return self._unreconcile_standalone(partial_reconcile_ids)
|
||||||
|
|
||||||
|
def _unreconcile_standalone(self, partial_reconcile_ids):
|
||||||
|
"""Engine-free unreconcile for installs without fusion_accounting_bank_rec.
|
||||||
|
|
||||||
|
Mirrors ``fusion.reconcile.engine.unreconcile``: finds bank lines whose
|
||||||
|
moves own any of the partials' journal items, runs the standard undo
|
||||||
|
on them, then unlinks any leftovers.
|
||||||
|
"""
|
||||||
|
Partial = self.env['account.partial.reconcile'].sudo()
|
||||||
|
partials = Partial.browse(list(partial_reconcile_ids or [])).exists()
|
||||||
|
if not partials:
|
||||||
|
return {'unreconciled_line_ids': []}
|
||||||
|
all_lines = (
|
||||||
|
partials.mapped('debit_move_id')
|
||||||
|
| partials.mapped('credit_move_id')
|
||||||
|
)
|
||||||
|
line_ids = all_lines.ids
|
||||||
|
affected = self.env['account.bank.statement.line'].sudo().search([
|
||||||
|
('move_id', 'in', all_lines.mapped('move_id').ids),
|
||||||
|
])
|
||||||
|
if affected:
|
||||||
|
affected.action_undo_reconciliation()
|
||||||
|
remaining = partials.exists()
|
||||||
|
if remaining:
|
||||||
|
remaining.unlink()
|
||||||
|
return {'unreconciled_line_ids': line_ids}
|
||||||
|
|
||||||
|
|
||||||
register_adapter('bank_rec', BankRecAdapter)
|
register_adapter('bank_rec', BankRecAdapter)
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ _logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ReportsAdapter(DataAdapter):
|
class ReportsAdapter(DataAdapter):
|
||||||
FUSION_MODEL = 'fusion.account.report'
|
# Phase 2 wires fusion.report.engine as the FUSION-mode backend for
|
||||||
|
# the new report_type-shaped methods (run_fusion_report, get_anomalies,
|
||||||
|
# get_commentary). The legacy ref_id-shaped run_report / export_report
|
||||||
|
# methods continue to defer to community when in FUSION mode (their
|
||||||
|
# original behavior), so this rename does not change their results.
|
||||||
|
FUSION_MODEL = 'fusion.report.engine'
|
||||||
ENTERPRISE_MODULE = 'account_reports'
|
ENTERPRISE_MODULE = 'account_reports'
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@@ -167,4 +172,159 @@ class ReportsAdapter(DataAdapter):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ==================================================================
|
||||||
|
# Phase 2 (Task 19): fusion.report.engine-routed report methods
|
||||||
|
#
|
||||||
|
# These coexist with the legacy ref_id-shaped run_report/export_report
|
||||||
|
# API. New callers (financial_reports AI tools, OWL widget) use the
|
||||||
|
# *_fusion_report methods below; those route through the engine when
|
||||||
|
# fusion_accounting_reports is installed.
|
||||||
|
# ==================================================================
|
||||||
|
|
||||||
|
# ------------------ run_fusion_report --------------------------
|
||||||
|
|
||||||
|
def run_fusion_report(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
return self._dispatch(
|
||||||
|
'run_fusion_report',
|
||||||
|
report_type=report_type,
|
||||||
|
date_from=date_from, date_to=date_to,
|
||||||
|
comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
def run_fusion_report_via_fusion(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
if 'fusion.report.engine' not in self.env.registry:
|
||||||
|
return {'rows': [], 'error': 'fusion.report.engine not installed'}
|
||||||
|
from datetime import datetime
|
||||||
|
from odoo.addons.fusion_accounting_reports.services.date_periods import (
|
||||||
|
Period,
|
||||||
|
)
|
||||||
|
df = (datetime.strptime(date_from, '%Y-%m-%d').date()
|
||||||
|
if isinstance(date_from, str) else date_from)
|
||||||
|
dt = (datetime.strptime(date_to, '%Y-%m-%d').date()
|
||||||
|
if isinstance(date_to, str) else date_to)
|
||||||
|
period = Period(date_from=df, date_to=dt, label=f"{df} - {dt}")
|
||||||
|
engine = self.env['fusion.report.engine']
|
||||||
|
company_id = company_id or self.env.company.id
|
||||||
|
if report_type == 'pnl':
|
||||||
|
return engine.compute_pnl(
|
||||||
|
period, comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
if report_type == 'balance_sheet':
|
||||||
|
return engine.compute_balance_sheet(
|
||||||
|
dt, comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
if report_type == 'trial_balance':
|
||||||
|
return engine.compute_trial_balance(
|
||||||
|
period, company_id=company_id,
|
||||||
|
)
|
||||||
|
if report_type == 'general_ledger':
|
||||||
|
return engine.compute_gl(period, company_id=company_id)
|
||||||
|
return {'rows': [], 'error': f'unknown report_type {report_type}'}
|
||||||
|
|
||||||
|
def run_fusion_report_via_enterprise(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
# Enterprise's account_reports has its own UI; we don't proxy from
|
||||||
|
# Python. Callers should use the Enterprise menus or the legacy
|
||||||
|
# run_report(ref_id=...) method instead.
|
||||||
|
return {
|
||||||
|
'rows': [],
|
||||||
|
'error': 'Enterprise reports must be run from the Enterprise UI',
|
||||||
|
}
|
||||||
|
|
||||||
|
def run_fusion_report_via_community(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
return {
|
||||||
|
'rows': [],
|
||||||
|
'error': 'No fusion reports engine available in pure Community',
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------ get_anomalies ------------------------------
|
||||||
|
|
||||||
|
def get_anomalies(self, report_type, date_from, date_to,
|
||||||
|
comparison='previous_year', company_id=None):
|
||||||
|
return self._dispatch(
|
||||||
|
'get_anomalies',
|
||||||
|
report_type=report_type,
|
||||||
|
date_from=date_from, date_to=date_to,
|
||||||
|
comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_anomalies_via_fusion(self, report_type, date_from, date_to,
|
||||||
|
comparison='previous_year', company_id=None):
|
||||||
|
if 'fusion.report.engine' not in self.env.registry:
|
||||||
|
return {'anomalies': []}
|
||||||
|
from odoo.addons.fusion_accounting_reports.services.anomaly_detection import (
|
||||||
|
detect,
|
||||||
|
)
|
||||||
|
report = self.run_fusion_report_via_fusion(
|
||||||
|
report_type=report_type,
|
||||||
|
date_from=date_from, date_to=date_to,
|
||||||
|
comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
if 'error' in report:
|
||||||
|
return {'anomalies': []}
|
||||||
|
return {'anomalies': detect(report)}
|
||||||
|
|
||||||
|
def get_anomalies_via_enterprise(self, report_type, date_from, date_to,
|
||||||
|
comparison='previous_year', company_id=None):
|
||||||
|
return {'anomalies': []}
|
||||||
|
|
||||||
|
def get_anomalies_via_community(self, report_type, date_from, date_to,
|
||||||
|
comparison='previous_year', company_id=None):
|
||||||
|
return {'anomalies': []}
|
||||||
|
|
||||||
|
# ------------------ get_commentary -----------------------------
|
||||||
|
|
||||||
|
def get_commentary(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
return self._dispatch(
|
||||||
|
'get_commentary',
|
||||||
|
report_type=report_type,
|
||||||
|
date_from=date_from, date_to=date_to,
|
||||||
|
comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_commentary_via_fusion(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
empty = {
|
||||||
|
'summary': '', 'highlights': [],
|
||||||
|
'concerns': [], 'next_actions': [],
|
||||||
|
}
|
||||||
|
if 'fusion.report.engine' not in self.env.registry:
|
||||||
|
return empty
|
||||||
|
from odoo.addons.fusion_accounting_reports.services.anomaly_detection import (
|
||||||
|
detect,
|
||||||
|
)
|
||||||
|
from odoo.addons.fusion_accounting_reports.services.commentary_generator import (
|
||||||
|
generate_commentary,
|
||||||
|
)
|
||||||
|
report = self.run_fusion_report_via_fusion(
|
||||||
|
report_type=report_type,
|
||||||
|
date_from=date_from, date_to=date_to,
|
||||||
|
comparison=comparison, company_id=company_id,
|
||||||
|
)
|
||||||
|
if 'error' in report:
|
||||||
|
return empty
|
||||||
|
anomalies = detect(report)
|
||||||
|
return generate_commentary(
|
||||||
|
self.env, report_result=report, anomalies=anomalies,
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_commentary_via_enterprise(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
return {
|
||||||
|
'summary': '', 'highlights': [],
|
||||||
|
'concerns': [], 'next_actions': [],
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_commentary_via_community(self, report_type, date_from, date_to,
|
||||||
|
comparison='none', company_id=None):
|
||||||
|
return {
|
||||||
|
'summary': '', 'highlights': [],
|
||||||
|
'concerns': [], 'next_actions': [],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
register_adapter('reports', ReportsAdapter)
|
register_adapter('reports', ReportsAdapter)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
from . import system_prompt
|
from . import system_prompt
|
||||||
from . import domain_prompts
|
from . import domain_prompts
|
||||||
|
from . import bank_rec_prompt
|
||||||
|
|||||||
107
fusion_accounting_ai/services/prompts/bank_rec_prompt.py
Normal file
107
fusion_accounting_ai/services/prompts/bank_rec_prompt.py
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
"""Bank reconciliation AI re-rank prompt.
|
||||||
|
|
||||||
|
Used by fusion_accounting_bank_rec/services/confidence_scoring.py to ask
|
||||||
|
an LLM to refine the statistical ranking of candidate matches.
|
||||||
|
|
||||||
|
Output contract: the LLM MUST respond with valid JSON of shape:
|
||||||
|
{"ranked": [{"candidate_id": int, "confidence": float, "reason": str}, ...]}
|
||||||
|
|
||||||
|
System prompt is provider-agnostic - works with OpenAI Chat Completions,
|
||||||
|
Claude Messages, and local OpenAI-compatible servers (LM Studio, Ollama).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
|
SYSTEM_PROMPT = """You are an expert accountant assisting with bank reconciliation.
|
||||||
|
|
||||||
|
Your job: given a bank statement line and a list of candidate journal items
|
||||||
|
that statistically scored well as potential matches, re-rank them based on
|
||||||
|
domain expertise. Consider:
|
||||||
|
|
||||||
|
1. **Amount-exact matches** are almost always correct unless the partner is wrong.
|
||||||
|
2. **Memo / reference clues** - bank memos often contain invoice numbers, partner
|
||||||
|
names, or transaction references that disambiguate matches.
|
||||||
|
3. **Date proximity** - invoices are typically reconciled within 30 days of issue.
|
||||||
|
4. **Pattern conformance** - if the partner has a learned pattern (e.g. "always
|
||||||
|
pays exact amount, weekly cadence"), favor candidates that fit that pattern.
|
||||||
|
5. **Precedent similarity** - if a near-identical reconcile happened before,
|
||||||
|
it's likely the right one.
|
||||||
|
|
||||||
|
Return ONLY valid JSON of this exact shape:
|
||||||
|
{
|
||||||
|
"ranked": [
|
||||||
|
{"candidate_id": <int>, "confidence": <float 0-1>, "reason": "<short string>"},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
Do NOT include any prose before or after the JSON. Do NOT use markdown code fences.
|
||||||
|
The "ranked" array MUST contain every candidate_id from the input, in your
|
||||||
|
preferred order (highest confidence first).
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def build_prompt(statement_line, scored_candidates, pattern=None, precedents=None):
|
||||||
|
"""Build (system_prompt, user_prompt) for AI re-rank.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
statement_line: account.bank.statement.line recordset (singleton)
|
||||||
|
scored_candidates: list of ScoredCandidate dataclasses (from confidence_scoring)
|
||||||
|
pattern: fusion.reconcile.pattern recordset for the partner, or None
|
||||||
|
precedents: list of PrecedentMatch dataclasses, or None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(system_prompt: str, user_prompt: str) tuple
|
||||||
|
"""
|
||||||
|
user_parts = []
|
||||||
|
|
||||||
|
user_parts.append("BANK LINE:")
|
||||||
|
user_parts.append(f" Date: {statement_line.date}")
|
||||||
|
user_parts.append(
|
||||||
|
f" Amount: {statement_line.amount} {statement_line.currency_id.name or ''}"
|
||||||
|
)
|
||||||
|
user_parts.append(
|
||||||
|
f" Memo / payment ref: {statement_line.payment_ref or '(none)'}"
|
||||||
|
)
|
||||||
|
if statement_line.partner_id:
|
||||||
|
user_parts.append(f" Partner: {statement_line.partner_id.name}")
|
||||||
|
|
||||||
|
if pattern:
|
||||||
|
user_parts.append("")
|
||||||
|
user_parts.append("PARTNER PATTERN (learned from past reconciles):")
|
||||||
|
user_parts.append(f" Reconcile count: {pattern.reconcile_count}")
|
||||||
|
user_parts.append(f" Preferred strategy: {pattern.pref_strategy}")
|
||||||
|
user_parts.append(
|
||||||
|
f" Typical cadence: ~{pattern.typical_cadence_days} days between reconciles"
|
||||||
|
)
|
||||||
|
if pattern.typical_amount_range:
|
||||||
|
user_parts.append(f" Typical amount range: {pattern.typical_amount_range}")
|
||||||
|
if pattern.common_memo_tokens:
|
||||||
|
user_parts.append(f" Common memo tokens: {pattern.common_memo_tokens}")
|
||||||
|
|
||||||
|
if precedents:
|
||||||
|
user_parts.append("")
|
||||||
|
user_parts.append("RECENT PRECEDENTS (most-similar past reconciles for this partner):")
|
||||||
|
# Cap at 3 precedents to keep prompt small and reduce token cost.
|
||||||
|
for p in precedents[:3]:
|
||||||
|
user_parts.append(
|
||||||
|
f" - amount={p.amount}, similarity={p.similarity_score:.2f}, "
|
||||||
|
f"matched {p.matched_move_line_count} line(s), tokens={p.memo_tokens}"
|
||||||
|
)
|
||||||
|
|
||||||
|
user_parts.append("")
|
||||||
|
user_parts.append("CANDIDATES (scored by statistical pipeline):")
|
||||||
|
for s in scored_candidates:
|
||||||
|
user_parts.append(
|
||||||
|
f" - candidate_id={s.candidate_id}, statistical_confidence={s.confidence}, "
|
||||||
|
f"amount_match={s.score_amount_match}, pattern_fit={s.score_partner_pattern}, "
|
||||||
|
f"precedent_sim={s.score_precedent_similarity}, "
|
||||||
|
f"reason=\"{s.reasoning}\""
|
||||||
|
)
|
||||||
|
|
||||||
|
user_parts.append("")
|
||||||
|
user_parts.append("Re-rank these candidates and return JSON per the system prompt.")
|
||||||
|
|
||||||
|
user_prompt = "\n".join(user_parts)
|
||||||
|
return (SYSTEM_PROMPT, user_prompt)
|
||||||
@@ -9,11 +9,12 @@ from .inventory import TOOLS as INVENTORY_TOOLS
|
|||||||
from .adp import TOOLS as ADP_TOOLS
|
from .adp import TOOLS as ADP_TOOLS
|
||||||
from .reporting import TOOLS as REPORTING_TOOLS
|
from .reporting import TOOLS as REPORTING_TOOLS
|
||||||
from .audit import TOOLS as AUDIT_TOOLS
|
from .audit import TOOLS as AUDIT_TOOLS
|
||||||
|
from .financial_reports import TOOLS as FINANCIAL_REPORTS_TOOLS
|
||||||
|
|
||||||
TOOL_DISPATCH = {}
|
TOOL_DISPATCH = {}
|
||||||
for tools_dict in [
|
for tools_dict in [
|
||||||
BANK_RECON_TOOLS, HST_TOOLS, AR_TOOLS, AP_TOOLS, JOURNAL_TOOLS,
|
BANK_RECON_TOOLS, HST_TOOLS, AR_TOOLS, AP_TOOLS, JOURNAL_TOOLS,
|
||||||
MONTH_END_TOOLS, PAYROLL_TOOLS, INVENTORY_TOOLS, ADP_TOOLS,
|
MONTH_END_TOOLS, PAYROLL_TOOLS, INVENTORY_TOOLS, ADP_TOOLS,
|
||||||
REPORTING_TOOLS, AUDIT_TOOLS,
|
REPORTING_TOOLS, AUDIT_TOOLS, FINANCIAL_REPORTS_TOOLS,
|
||||||
]:
|
]:
|
||||||
TOOL_DISPATCH.update(tools_dict)
|
TOOL_DISPATCH.update(tools_dict)
|
||||||
|
|||||||
@@ -67,7 +67,16 @@ def match_bank_line_to_payments(env, params):
|
|||||||
st_line = env['account.bank.statement.line'].browse(st_line_id)
|
st_line = env['account.bank.statement.line'].browse(st_line_id)
|
||||||
if not st_line.exists():
|
if not st_line.exists():
|
||||||
return {'error': 'Statement line not found'}
|
return {'error': 'Statement line not found'}
|
||||||
st_line.set_line_bank_statement_line(move_line_ids)
|
# Phase 1 Task 23: route through engine when available
|
||||||
|
if 'fusion.reconcile.engine' in env.registry:
|
||||||
|
cands = env['account.move.line'].browse(move_line_ids).exists()
|
||||||
|
if not cands:
|
||||||
|
return {'error': 'No valid move_line_ids'}
|
||||||
|
env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
st_line, against_lines=cands)
|
||||||
|
st_line.invalidate_recordset(['is_reconciled'])
|
||||||
|
else:
|
||||||
|
st_line.set_line_bank_statement_line(move_line_ids)
|
||||||
return {
|
return {
|
||||||
'status': 'matched',
|
'status': 'matched',
|
||||||
'statement_line_id': st_line_id,
|
'statement_line_id': st_line_id,
|
||||||
@@ -83,7 +92,12 @@ def auto_reconcile_bank_lines(env, params):
|
|||||||
('company_id', '=', int(company_id)),
|
('company_id', '=', int(company_id)),
|
||||||
])
|
])
|
||||||
before_count = len(lines)
|
before_count = len(lines)
|
||||||
lines._try_auto_reconcile_statement_lines(company_id=int(company_id))
|
# Phase 1 Task 23: route through engine when available
|
||||||
|
if 'fusion.reconcile.engine' in env.registry:
|
||||||
|
env['fusion.reconcile.engine'].reconcile_batch(
|
||||||
|
lines, strategy='auto')
|
||||||
|
else:
|
||||||
|
lines._try_auto_reconcile_statement_lines(company_id=int(company_id))
|
||||||
still_unreconciled = env['account.bank.statement.line'].search([
|
still_unreconciled = env['account.bank.statement.line'].search([
|
||||||
('is_reconciled', '=', False),
|
('is_reconciled', '=', False),
|
||||||
('company_id', '=', int(company_id)),
|
('company_id', '=', int(company_id)),
|
||||||
@@ -946,6 +960,171 @@ def _format_aml_candidates(amls):
|
|||||||
} for aml in amls]
|
} for aml in amls]
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Phase 1 Bank Reconciliation: engine-backed tools
|
||||||
|
#
|
||||||
|
# These five tools wrap the fusion.reconcile.engine 6-method API via the
|
||||||
|
# bank_rec data adapter (or the engine directly when the adapter does not
|
||||||
|
# expose a wrapper). They give the AI chat the same reconciliation surface
|
||||||
|
# a human gets in the OWL bank-rec UI.
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_suggest_matches(env, params):
|
||||||
|
"""Compute and persist AI suggestions for one or more bank statement lines.
|
||||||
|
|
||||||
|
Wraps ``BankRecAdapter.suggest_matches`` -> ``fusion.reconcile.engine``.
|
||||||
|
"""
|
||||||
|
raw_ids = params.get('statement_line_ids')
|
||||||
|
if not raw_ids:
|
||||||
|
return {'error': 'statement_line_ids is required'}
|
||||||
|
statement_line_ids = [int(x) for x in raw_ids]
|
||||||
|
limit_per_line = int(params.get('limit_per_line', 3))
|
||||||
|
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'bank_rec')
|
||||||
|
raw = adapter.suggest_matches(
|
||||||
|
statement_line_ids=statement_line_ids,
|
||||||
|
limit_per_line=limit_per_line,
|
||||||
|
company_id=env.company.id,
|
||||||
|
) or {}
|
||||||
|
|
||||||
|
suggestions = {}
|
||||||
|
total = 0
|
||||||
|
for line_id, sug_list in raw.items():
|
||||||
|
out = []
|
||||||
|
for s in sug_list:
|
||||||
|
out.append({
|
||||||
|
'suggestion_id': s.get('id'),
|
||||||
|
'candidate_id': s.get('candidate_id'),
|
||||||
|
'confidence': s.get('confidence'),
|
||||||
|
'reasoning': s.get('reasoning') or '',
|
||||||
|
'rank': s.get('rank'),
|
||||||
|
})
|
||||||
|
total += 1
|
||||||
|
suggestions[line_id] = out
|
||||||
|
return {'suggestions': suggestions, 'count': total}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_accept_suggestion(env, params):
|
||||||
|
"""Accept a fusion.reconcile.suggestion: reconciles the bank line against
|
||||||
|
the suggestion's proposed move lines and marks the suggestion accepted.
|
||||||
|
|
||||||
|
Wraps ``BankRecAdapter.accept_suggestion``.
|
||||||
|
"""
|
||||||
|
if not params.get('suggestion_id'):
|
||||||
|
return {'error': 'suggestion_id is required'}
|
||||||
|
suggestion_id = int(params['suggestion_id'])
|
||||||
|
suggestion = env['fusion.reconcile.suggestion'].browse(suggestion_id)
|
||||||
|
if not suggestion.exists():
|
||||||
|
return {'error': 'Suggestion not found'}
|
||||||
|
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'bank_rec')
|
||||||
|
result = adapter.accept_suggestion(suggestion_id) or {}
|
||||||
|
statement_line = suggestion.statement_line_id
|
||||||
|
return {
|
||||||
|
'status': 'accepted',
|
||||||
|
'suggestion_id': suggestion_id,
|
||||||
|
'partial_ids': list(result.get('partial_ids') or []),
|
||||||
|
'is_reconciled': bool(statement_line.is_reconciled),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_reconcile_bank_line(env, params):
|
||||||
|
"""Manually reconcile a bank statement line against a set of journal items.
|
||||||
|
|
||||||
|
Routes through ``fusion.reconcile.engine.reconcile_one`` so behaviour
|
||||||
|
matches the OWL widget and ``fusion_accept_suggestion``. Use this for
|
||||||
|
direct AI-initiated matches that did not come from an AI suggestion.
|
||||||
|
"""
|
||||||
|
if not params.get('statement_line_id'):
|
||||||
|
return {'error': 'statement_line_id is required'}
|
||||||
|
raw_against = params.get('against_move_line_ids')
|
||||||
|
if not raw_against:
|
||||||
|
return {'error': 'against_move_line_ids is required'}
|
||||||
|
|
||||||
|
st_line_id = int(params['statement_line_id'])
|
||||||
|
aml_ids = [int(x) for x in raw_against]
|
||||||
|
statement_line = env['account.bank.statement.line'].browse(st_line_id)
|
||||||
|
if not statement_line.exists():
|
||||||
|
return {'error': 'Statement line not found'}
|
||||||
|
against_lines = env['account.move.line'].browse(aml_ids).exists()
|
||||||
|
if not against_lines:
|
||||||
|
return {'error': 'No valid against_move_line_ids'}
|
||||||
|
|
||||||
|
result = env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
statement_line, against_lines=against_lines)
|
||||||
|
return {
|
||||||
|
'status': 'reconciled',
|
||||||
|
'statement_line_id': st_line_id,
|
||||||
|
'partial_ids': list(result.get('partial_ids') or []),
|
||||||
|
'is_reconciled': bool(statement_line.is_reconciled),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_unreconcile(env, params):
|
||||||
|
"""Reverse a reconciliation by partial_reconcile_ids.
|
||||||
|
|
||||||
|
Wraps ``BankRecAdapter.unreconcile``. Works in fusion, Enterprise, and
|
||||||
|
Community installs (the adapter falls back to a standalone path when
|
||||||
|
fusion_accounting_bank_rec is not loaded).
|
||||||
|
"""
|
||||||
|
raw_ids = params.get('partial_reconcile_ids')
|
||||||
|
if not raw_ids:
|
||||||
|
return {'error': 'partial_reconcile_ids is required'}
|
||||||
|
partial_ids = [int(x) for x in raw_ids]
|
||||||
|
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'bank_rec')
|
||||||
|
result = adapter.unreconcile(partial_ids) or {}
|
||||||
|
unreconciled_line_ids = list(result.get('unreconciled_line_ids') or [])
|
||||||
|
return {
|
||||||
|
'status': 'unreconciled',
|
||||||
|
'unreconciled_line_ids': unreconciled_line_ids,
|
||||||
|
'count': len(unreconciled_line_ids),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_get_pending_suggestions(env, params):
|
||||||
|
"""List pending fusion.reconcile.suggestion rows.
|
||||||
|
|
||||||
|
Optional filters: ``statement_line_id``, ``min_confidence`` (default 0.0),
|
||||||
|
``limit`` (default 50). Only returns suggestions in the ``pending`` state
|
||||||
|
for the current company.
|
||||||
|
"""
|
||||||
|
domain = [
|
||||||
|
('company_id', '=', env.company.id),
|
||||||
|
('state', '=', 'pending'),
|
||||||
|
]
|
||||||
|
if params.get('statement_line_id'):
|
||||||
|
domain.append(
|
||||||
|
('statement_line_id', '=', int(params['statement_line_id'])))
|
||||||
|
min_confidence = float(params.get('min_confidence') or 0.0)
|
||||||
|
if min_confidence > 0.0:
|
||||||
|
domain.append(('confidence', '>=', min_confidence))
|
||||||
|
limit = int(params.get('limit', 50))
|
||||||
|
|
||||||
|
Suggestion = env['fusion.reconcile.suggestion'].sudo()
|
||||||
|
records = Suggestion.search(
|
||||||
|
domain, limit=limit, order='confidence desc, id desc')
|
||||||
|
rows = []
|
||||||
|
for s in records:
|
||||||
|
st_line = s.statement_line_id
|
||||||
|
rows.append({
|
||||||
|
'id': s.id,
|
||||||
|
'statement_line_id': st_line.id if st_line else None,
|
||||||
|
'statement_line_ref': (
|
||||||
|
st_line.payment_ref or '' if st_line else ''),
|
||||||
|
'candidate_ids': s.proposed_move_line_ids.ids,
|
||||||
|
'confidence': s.confidence,
|
||||||
|
'rank': s.rank,
|
||||||
|
'reasoning': s.reasoning or '',
|
||||||
|
'state': s.state,
|
||||||
|
})
|
||||||
|
return {'count': len(rows), 'suggestions': rows}
|
||||||
|
|
||||||
|
|
||||||
TOOLS = {
|
TOOLS = {
|
||||||
'get_unreconciled_bank_lines': get_unreconciled_bank_lines,
|
'get_unreconciled_bank_lines': get_unreconciled_bank_lines,
|
||||||
'get_unreconciled_receipts': get_unreconciled_receipts,
|
'get_unreconciled_receipts': get_unreconciled_receipts,
|
||||||
@@ -962,4 +1141,10 @@ TOOLS = {
|
|||||||
'reconcile_payroll_cheques': reconcile_payroll_cheques,
|
'reconcile_payroll_cheques': reconcile_payroll_cheques,
|
||||||
'suggest_bank_line_matches': suggest_bank_line_matches,
|
'suggest_bank_line_matches': suggest_bank_line_matches,
|
||||||
'search_matching_entries': search_matching_entries,
|
'search_matching_entries': search_matching_entries,
|
||||||
|
# Phase 1 engine-backed tools
|
||||||
|
'fusion_suggest_matches': fusion_suggest_matches,
|
||||||
|
'fusion_accept_suggestion': fusion_accept_suggestion,
|
||||||
|
'fusion_reconcile_bank_line': fusion_reconcile_bank_line,
|
||||||
|
'fusion_unreconcile': fusion_unreconcile,
|
||||||
|
'fusion_get_pending_suggestions': fusion_get_pending_suggestions,
|
||||||
}
|
}
|
||||||
|
|||||||
127
fusion_accounting_ai/services/tools/financial_reports.py
Normal file
127
fusion_accounting_ai/services/tools/financial_reports.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
"""Fusion-engine-routed AI tools for financial reports.
|
||||||
|
|
||||||
|
These 5 tools route through ReportsAdapter's Phase-2 methods
|
||||||
|
(run_fusion_report / get_anomalies / get_commentary), which in turn
|
||||||
|
call fusion.report.engine when fusion_accounting_reports is installed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _company_id(env, params):
|
||||||
|
raw = params.get('company_id')
|
||||||
|
return int(raw) if raw else env.company.id
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_run_report(env, params):
|
||||||
|
"""Run a fusion financial report.
|
||||||
|
|
||||||
|
Params: report_type (pnl|balance_sheet|trial_balance|general_ledger),
|
||||||
|
date_from, date_to, comparison (none|previous_period|previous_year),
|
||||||
|
optional company_id.
|
||||||
|
"""
|
||||||
|
if 'fusion.report.engine' not in env.registry:
|
||||||
|
return {'error': 'fusion_accounting_reports not installed'}
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'reports')
|
||||||
|
result = adapter.run_fusion_report(
|
||||||
|
report_type=params.get('report_type'),
|
||||||
|
date_from=params.get('date_from'),
|
||||||
|
date_to=params.get('date_to'),
|
||||||
|
comparison=params.get('comparison', 'none'),
|
||||||
|
company_id=_company_id(env, params),
|
||||||
|
)
|
||||||
|
rows = result.get('rows', [])
|
||||||
|
return {
|
||||||
|
'report_type': params.get('report_type'),
|
||||||
|
'period': result.get('period'),
|
||||||
|
'comparison_period': result.get('comparison_period'),
|
||||||
|
'row_count': len(rows),
|
||||||
|
'rows': rows,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_get_anomalies(env, params):
|
||||||
|
"""Detect variance anomalies in a report."""
|
||||||
|
if 'fusion.report.engine' not in env.registry:
|
||||||
|
return {'error': 'fusion_accounting_reports not installed'}
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'reports')
|
||||||
|
result = adapter.get_anomalies(
|
||||||
|
report_type=params.get('report_type'),
|
||||||
|
date_from=params.get('date_from'),
|
||||||
|
date_to=params.get('date_to'),
|
||||||
|
comparison=params.get('comparison', 'previous_year'),
|
||||||
|
company_id=_company_id(env, params),
|
||||||
|
)
|
||||||
|
anomalies = result.get('anomalies', [])
|
||||||
|
return {'count': len(anomalies), 'anomalies': anomalies}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_generate_commentary(env, params):
|
||||||
|
"""Generate AI commentary for a report."""
|
||||||
|
if 'fusion.report.engine' not in env.registry:
|
||||||
|
return {'error': 'fusion_accounting_reports not installed'}
|
||||||
|
from ..data_adapters import get_adapter
|
||||||
|
adapter = get_adapter(env, 'reports')
|
||||||
|
result = adapter.get_commentary(
|
||||||
|
report_type=params.get('report_type'),
|
||||||
|
date_from=params.get('date_from'),
|
||||||
|
date_to=params.get('date_to'),
|
||||||
|
comparison=params.get('comparison', 'none'),
|
||||||
|
company_id=_company_id(env, params),
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
'summary': result.get('summary', ''),
|
||||||
|
'highlights': result.get('highlights', []),
|
||||||
|
'concerns': result.get('concerns', []),
|
||||||
|
'next_actions': result.get('next_actions', []),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_drill_down_report_line(env, params):
|
||||||
|
"""Drill from a report line into the underlying journal items."""
|
||||||
|
if 'fusion.report.engine' not in env.registry:
|
||||||
|
return {'error': 'fusion_accounting_reports not installed'}
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from odoo.addons.fusion_accounting_reports.services.date_periods import (
|
||||||
|
Period,
|
||||||
|
)
|
||||||
|
date_from = params['date_from']
|
||||||
|
date_to = params['date_to']
|
||||||
|
if isinstance(date_from, str):
|
||||||
|
date_from = datetime.strptime(date_from, '%Y-%m-%d').date()
|
||||||
|
if isinstance(date_to, str):
|
||||||
|
date_to = datetime.strptime(date_to, '%Y-%m-%d').date()
|
||||||
|
period = Period(date_from=date_from, date_to=date_to, label='drill')
|
||||||
|
engine = env['fusion.report.engine']
|
||||||
|
rows = engine.drill_down(
|
||||||
|
account_id=int(params['account_id']),
|
||||||
|
period=period,
|
||||||
|
company_id=_company_id(env, params),
|
||||||
|
)
|
||||||
|
return {'count': len(rows), 'rows': rows}
|
||||||
|
|
||||||
|
|
||||||
|
def fusion_compare_periods(env, params):
|
||||||
|
"""Run a report with period comparison side-by-side.
|
||||||
|
|
||||||
|
Defaults comparison to 'previous_year' so callers get a comparison
|
||||||
|
column without specifying it explicitly.
|
||||||
|
"""
|
||||||
|
return fusion_run_report(env, {
|
||||||
|
**params,
|
||||||
|
'comparison': params.get('comparison', 'previous_year'),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
TOOLS = {
|
||||||
|
'fusion_run_report': fusion_run_report,
|
||||||
|
'fusion_get_anomalies': fusion_get_anomalies,
|
||||||
|
'fusion_generate_commentary': fusion_generate_commentary,
|
||||||
|
'fusion_drill_down_report_line': fusion_drill_down_report_line,
|
||||||
|
'fusion_compare_periods': fusion_compare_periods,
|
||||||
|
}
|
||||||
103
fusion_accounting_bank_rec/CLAUDE.md
Normal file
103
fusion_accounting_bank_rec/CLAUDE.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
# fusion_accounting_bank_rec — Cursor / Claude Context
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
Replaces (or augments — coexists with) Odoo Enterprise's `account_accountant`
|
||||||
|
bank reconciliation widget with a Fusion-native, AI-assistive implementation.
|
||||||
|
Ships in Phase 1 of the fusion_accounting roadmap.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
Hybrid: the engine (`fusion.reconcile.engine`, AbstractModel) is the SINGLE
|
||||||
|
write surface for reconciliations. Everything else (controller, OWL widget,
|
||||||
|
AI tools, wizards, cron) routes through the engine's 6-method API:
|
||||||
|
|
||||||
|
- `reconcile_one(line, against_lines, write_off_vals=None)`
|
||||||
|
- `reconcile_batch(lines, strategy='auto')`
|
||||||
|
- `suggest_matches(lines, limit_per_line=3)`
|
||||||
|
- `accept_suggestion(suggestion)`
|
||||||
|
- `write_off(line, account, amount, label, tax_id=None)`
|
||||||
|
- `unreconcile(partial_reconciles)`
|
||||||
|
|
||||||
|
Pure-Python services live in `services/`:
|
||||||
|
- `memo_tokenizer` — Canadian bank memo regex
|
||||||
|
- `exchange_diff` — FX gain/loss pre-compute
|
||||||
|
- `matching_strategies` — AmountExact, FIFO, MultiInvoice
|
||||||
|
- `precedent_lookup` — K-nearest search
|
||||||
|
- `pattern_extractor` — per-partner aggregate
|
||||||
|
- `confidence_scoring` — 4-pass pipeline (statistical → AI re-rank)
|
||||||
|
- `precedent_backfill` — migration helper
|
||||||
|
|
||||||
|
Persistent models in `models/`:
|
||||||
|
- `fusion.reconcile.pattern` — per-(company, partner) learned profile
|
||||||
|
- `fusion.reconcile.precedent` — per-decision history
|
||||||
|
- `fusion.reconcile.suggestion` — AI suggestions with state lifecycle
|
||||||
|
- `fusion.bank.rec.widget` — TransientModel for OWL round-trip
|
||||||
|
- `fusion.unreconciled.bank.line.mv` — pre-aggregated MV for fast UI listing
|
||||||
|
- `fusion.bank.rec.cron` — cron handler (suggest, pattern refresh, MV refresh)
|
||||||
|
- `fusion.auto.reconcile.wizard` / `fusion.bulk.reconcile.wizard` — TransientModel wizards
|
||||||
|
- `fusion.migration.wizard` (inherits) — adds `_bank_rec_bootstrap_step`
|
||||||
|
- `account.bank.statement.line` (inherits) — adds fusion_top_suggestion_id, fusion_confidence_band, etc.
|
||||||
|
- `account.reconcile.model` (inherits) — adds fusion_ai_confidence_threshold
|
||||||
|
|
||||||
|
Controller: `controllers/bank_rec_controller.py` exposes 10 JSON-RPC endpoints
|
||||||
|
under `/fusion/bank_rec/*`. All calls route through the engine.
|
||||||
|
|
||||||
|
OWL frontend: `static/src/`
|
||||||
|
- `services/bank_reconciliation_service.js` — central reactive state + RPC wrappers
|
||||||
|
- `views/kanban/bank_rec_kanban_*.js` — top-level controller + renderer
|
||||||
|
- `components/bank_reconciliation/<...>` — 14 mirrored Enterprise components + 8 fusion-only components (ai_suggestion folder, batch_action_bar, reconcile_model_picker, attachment_strip, partner_history_panel)
|
||||||
|
- `tours/bank_rec_tours.js` — 5 OWL tour smoke tests
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- **V19 deprecations to avoid:** `_sql_constraints` (use `models.Constraint`),
|
||||||
|
`@api.depends('id')` (raises `NotImplementedError`), `@route(type='json')`
|
||||||
|
(use `type='jsonrpc'`), `numbercall` field on `ir.cron` (removed),
|
||||||
|
`groups_id` on `res.users` (use `all_group_ids` for searching),
|
||||||
|
`users` field on `res.groups` (use `user_ids`), `groups_id` on
|
||||||
|
`ir.ui.menu` (use `group_ids`).
|
||||||
|
|
||||||
|
- **Coexistence:** When `account_accountant` is installed, the fusion menu
|
||||||
|
is hidden via `fusion_accounting_core.group_fusion_show_when_enterprise_absent`
|
||||||
|
(a computed group). Engine model is always available.
|
||||||
|
|
||||||
|
- **Materialized view refresh:** Triggered on `fusion.reconcile.suggestion`
|
||||||
|
create/write (best-effort, non-blocking). Cron refreshes every 5 min via
|
||||||
|
a dedicated autocommit cursor (REFRESH CONCURRENTLY can't run inside
|
||||||
|
Odoo's regular transaction).
|
||||||
|
|
||||||
|
- **Test factories:** `tests/_factories.py` provides `make_bank_journal`,
|
||||||
|
`make_bank_line`, `make_invoice`, `make_reconcileable_pair`, `make_suggestion`,
|
||||||
|
`make_pattern`, `make_precedent`. NOTE: `make_bank_journal` defaults to
|
||||||
|
code `'TEST'` so multiple calls in one test will collide; pass an explicit
|
||||||
|
unique code or share a journal across calls.
|
||||||
|
|
||||||
|
- **Hypothesis property tests:** Use `@settings(suppress_health_check=[...])`
|
||||||
|
to silence function_scoped_fixture warnings in TransactionCase.
|
||||||
|
|
||||||
|
## Test counts (as of Phase 1 complete)
|
||||||
|
|
||||||
|
- 157 logical tests total in fusion_accounting_bank_rec
|
||||||
|
- 0 failures, 0 errors
|
||||||
|
- Includes: 4 benchmark tests (tagged 'benchmark'), 1 local LLM smoke (tagged 'local_llm', skips when no LLM), 5 OWL tour tests (tagged 'tour')
|
||||||
|
|
||||||
|
## Performance baseline
|
||||||
|
|
||||||
|
| Operation | P95 | Budget |
|
||||||
|
|---|---|---|
|
||||||
|
| `engine.suggest_matches` (1 line) | 234ms | <500ms |
|
||||||
|
| `engine.reconcile_batch` (50 lines) | 3318ms | <5000ms |
|
||||||
|
| `controller.list_unreconciled` (50 lines) | 77ms | <200ms |
|
||||||
|
| MV refresh | 60ms | <2000ms |
|
||||||
|
|
||||||
|
All within 1x of budget at Phase 1 ship.
|
||||||
|
|
||||||
|
## Known concerns / Phase 1.5 backlog
|
||||||
|
|
||||||
|
- `accept_suggestion` returns `partial_ids` but not `is_reconciled` — UI reads it post-call
|
||||||
|
- `engine.write_off` mixed mode (write-off + against_lines) implemented but untested
|
||||||
|
- `engine.reconcile_one` returns `exchange_diff_move_id: None` (Odoo's reconcile() handles FX inline; surfacing the move_id needs an extra query)
|
||||||
|
- `against_lines` early-break in `reconcile_one` silently drops excess; auto strategy avoids this but manual callers should pre-validate
|
||||||
|
- Reconcile-model bulk wizard `_apply_lines_for_bank_statement_line` is Enterprise-only (Community falls back to per-line error)
|
||||||
|
- OWL tour tests skip-mode when websocket-client absent
|
||||||
41
fusion_accounting_bank_rec/README.md
Normal file
41
fusion_accounting_bank_rec/README.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# fusion_accounting_bank_rec
|
||||||
|
|
||||||
|
AI-assisted bank reconciliation for Odoo 19 Community — a Fusion-native
|
||||||
|
replacement for Enterprise's `account_accountant` bank reconciliation widget.
|
||||||
|
|
||||||
|
## What it does
|
||||||
|
|
||||||
|
- Side-by-side parity with Enterprise's bank reconciliation UI (kanban + side
|
||||||
|
panel, multi-currency, write-offs, attachments, chatter)
|
||||||
|
- AI-assistive: confidence-scored suggestions per bank line via the
|
||||||
|
`fusion.reconcile.engine` 4-pass scoring pipeline (statistical + optional
|
||||||
|
LLM re-rank)
|
||||||
|
- Coexists with `account_accountant` (Enterprise wins by default; Fusion menu
|
||||||
|
appears only when Enterprise is uninstalled)
|
||||||
|
- Migration-aware: bootstrap step backfills `fusion.reconcile.precedent` from
|
||||||
|
existing `account.partial.reconcile` rows so the AI has memory from day 1
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install
|
||||||
|
odoo --addons-path=... -i fusion_accounting_bank_rec
|
||||||
|
|
||||||
|
# Open the widget (when Enterprise's account_accountant is NOT installed)
|
||||||
|
# Apps → Bank Reconciliation → Reconcile Bank Lines
|
||||||
|
|
||||||
|
# When Enterprise IS installed: use Enterprise's UI; the engine + AI tools
|
||||||
|
# are still available via the AI chat.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
- Local LLM (LM Studio, Ollama):
|
||||||
|
- `fusion_accounting.openai_base_url` = `http://host.docker.internal:1234/v1`
|
||||||
|
- `fusion_accounting.openai_model` = your local model name
|
||||||
|
- `fusion_accounting.provider.bank_rec_suggest` = `openai`
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- `CLAUDE.md` — agent context
|
||||||
|
- `UPGRADE_NOTES.md` — Odoo version anchoring
|
||||||
34
fusion_accounting_bank_rec/UPGRADE_NOTES.md
Normal file
34
fusion_accounting_bank_rec/UPGRADE_NOTES.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# fusion_accounting_bank_rec — Upgrade Notes
|
||||||
|
|
||||||
|
## Odoo Version Anchor
|
||||||
|
|
||||||
|
This module targets **Odoo 19.0** (community-base).
|
||||||
|
|
||||||
|
Reference snapshot of Enterprise code mirrored from:
|
||||||
|
- `account_accountant` (Odoo 19.0.x)
|
||||||
|
- Source: `/Users/gurpreet/Github/RePackaged-Odoo/accounting/account_accountant/`
|
||||||
|
|
||||||
|
## Cross-Version Diff Strategy
|
||||||
|
|
||||||
|
When a new Odoo version ships:
|
||||||
|
|
||||||
|
1. Run `check_odoo_diff.sh` (in repo root) against the new Enterprise version
|
||||||
|
2. Note any breaking changes in `account.bank.statement.line` API
|
||||||
|
3. For mirrored OWL components, diff Enterprise's new versions against ours and
|
||||||
|
port material changes (signature renames, new behaviour we want to inherit)
|
||||||
|
4. Re-run the full test suite + tour tests against the new Odoo version
|
||||||
|
5. Update this file with the new version anchor + any deviations
|
||||||
|
|
||||||
|
## V19 Migration Notes (already applied)
|
||||||
|
|
||||||
|
- `_sql_constraints` → `models.Constraint` (Tasks 14, 15)
|
||||||
|
- `@api.depends('id')` → removed (Task 17)
|
||||||
|
- `@route(type='json')` → `type='jsonrpc'` (Task 26)
|
||||||
|
- `numbercall` removed from `ir.cron` (Task 25)
|
||||||
|
- `res.groups.users` → `user_ids` (Task 43)
|
||||||
|
- `ir.ui.menu.groups_id` → `group_ids` (Tasks 42, 43)
|
||||||
|
|
||||||
|
## Phase 1 → Phase 1.5 Migration
|
||||||
|
|
||||||
|
If we ship Phase 1.5 (UI polish, deferred features), changes will go in
|
||||||
|
incremental commits. No DB migration needed (Phase 1 schema is forward-compatible).
|
||||||
@@ -2,3 +2,4 @@ from . import models
|
|||||||
from . import controllers
|
from . import controllers
|
||||||
from . import services
|
from . import services
|
||||||
from . import wizards
|
from . import wizards
|
||||||
|
from . import reports
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
'name': 'Fusion Accounting — Bank Reconciliation',
|
'name': 'Fusion Accounting — Bank Reconciliation',
|
||||||
'version': '19.0.1.0.5',
|
'version': '19.0.1.0.26',
|
||||||
'category': 'Accounting/Accounting',
|
'category': 'Accounting/Accounting',
|
||||||
'sequence': 28,
|
'sequence': 28,
|
||||||
'summary': 'Native V19 bank reconciliation widget with AI confidence scoring + behavioural learning.',
|
'summary': 'Native V19 bank reconciliation widget with AI confidence scoring + behavioural learning.',
|
||||||
@@ -24,13 +24,89 @@ Built by Nexa Systems Inc.
|
|||||||
'author': 'Nexa Systems Inc.',
|
'author': 'Nexa Systems Inc.',
|
||||||
'website': 'https://nexasystems.ca',
|
'website': 'https://nexasystems.ca',
|
||||||
'maintainer': 'Nexa Systems Inc.',
|
'maintainer': 'Nexa Systems Inc.',
|
||||||
'depends': ['fusion_accounting_core'],
|
'depends': ['fusion_accounting_core', 'fusion_accounting_migration'],
|
||||||
'external_dependencies': {
|
'external_dependencies': {
|
||||||
'python': ['hypothesis'],
|
'python': ['hypothesis'],
|
||||||
},
|
},
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
|
'data/cron.xml',
|
||||||
|
'wizards/auto_reconcile_wizard_views.xml',
|
||||||
|
'wizards/bulk_reconcile_wizard_views.xml',
|
||||||
|
'reports/migration_audit_report_views.xml',
|
||||||
|
'reports/migration_audit_report_action.xml',
|
||||||
|
'views/menu_views.xml',
|
||||||
],
|
],
|
||||||
|
'assets': {
|
||||||
|
'web.assets_backend': [
|
||||||
|
'fusion_accounting_bank_rec/static/src/scss/_variables.scss',
|
||||||
|
'fusion_accounting_bank_rec/static/src/scss/bank_reconciliation.scss',
|
||||||
|
'fusion_accounting_bank_rec/static/src/scss/ai_suggestion.scss',
|
||||||
|
'fusion_accounting_bank_rec/static/src/scss/dark_mode.scss',
|
||||||
|
'fusion_accounting_bank_rec/static/src/services/bank_reconciliation_service.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/views/kanban/bank_rec_kanban_controller.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/views/kanban/bank_rec_kanban_renderer.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/views/kanban/bank_rec_kanban_view.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/views/kanban/bank_rec_kanban.xml',
|
||||||
|
# OWL component mirror — Enterprise account_accountant bank-rec.
|
||||||
|
# Re-export shim so mirrored components can use the relative
|
||||||
|
# `../bank_reconciliation_service` import unchanged.
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/bank_reconciliation_service.js',
|
||||||
|
# Batch 1 (Task 30) — display components
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/statement_line/statement_line.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/statement_line/statement_line.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/statement_summary/statement_summary.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/statement_summary/statement_summary.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/line_info_pop_over/line_info_pop_over.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/line_info_pop_over/line_info_pop_over.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/reconciled_line_name/reconciled_line_name.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/reconciled_line_name/reconciled_line_name.xml',
|
||||||
|
# Batch 2 (Task 31) — action + edit components
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/button/button.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/button/button.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/button_list/button_list.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/button_list/button_list.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/line_to_reconcile/line_to_reconcile.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/line_to_reconcile/line_to_reconcile.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/list_view/list.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/list_view/list_view_many2one_multi_edit.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/list_view/list_view_many2one_multi_edit.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/apply_amount/apply_amount.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/apply_amount/apply_amount.xml',
|
||||||
|
# Batch 3 (Task 32) — dialog components
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/bankrec_form_dialog/bankrec_form_dialog.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/bankrec_form_dialog/bankrec_form_dialog.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/search_dialog/search_dialog.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/search_dialog/search_dialog.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/search_dialog/search_dialog_list.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/search_dialog/search_dialog_list.xml',
|
||||||
|
# Batch 4 (Task 33) — auxiliary components
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/quick_create/quick_create.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/quick_create/quick_create.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/chatter/chatter.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/file_uploader/file_uploader.js',
|
||||||
|
# Fusion-only (Task 34) — AI suggestion UI
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_suggestion_strip.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_suggestion_strip.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_alternatives_panel.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_alternatives_panel.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_reasoning_tooltip.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/ai_suggestion/ai_reasoning_tooltip.xml',
|
||||||
|
# Fusion-only (Task 35) — batch action bar + reconcile model picker
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/batch_action_bar/batch_action_bar.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/batch_action_bar/batch_action_bar.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/reconcile_model_picker/reconcile_model_picker.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/reconcile_model_picker/reconcile_model_picker.xml',
|
||||||
|
# Fusion-only (Task 36) — attachment strip + partner history panel
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/attachment_strip/attachment_strip.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/attachment_strip/attachment_strip.xml',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/partner_history_panel/partner_history_panel.js',
|
||||||
|
'fusion_accounting_bank_rec/static/src/components/bank_reconciliation/partner_history_panel/partner_history_panel.xml',
|
||||||
|
],
|
||||||
|
'web.assets_tests': [
|
||||||
|
'fusion_accounting_bank_rec/static/src/tours/bank_rec_tours.js',
|
||||||
|
],
|
||||||
|
},
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'application': False,
|
'application': False,
|
||||||
'license': 'OPL-1',
|
'license': 'OPL-1',
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from . import bank_rec_controller
|
||||||
|
|||||||
325
fusion_accounting_bank_rec/controllers/bank_rec_controller.py
Normal file
325
fusion_accounting_bank_rec/controllers/bank_rec_controller.py
Normal file
@@ -0,0 +1,325 @@
|
|||||||
|
"""HTTP controller: 10 JSON-RPC endpoints for the OWL bank-rec widget.
|
||||||
|
|
||||||
|
All endpoints route through ``BankRecAdapter`` (which lives in
|
||||||
|
``fusion_accounting_ai`` and already encapsulates fusion / enterprise /
|
||||||
|
community routing) or directly through ``fusion.reconcile.engine`` for
|
||||||
|
methods the adapter does not yet expose. The controller never touches
|
||||||
|
``account.partial.reconcile`` directly.
|
||||||
|
|
||||||
|
V19: uses ``@route(type='jsonrpc')``, the V19-blessed replacement for the
|
||||||
|
deprecated ``type='json'`` (Odoo 19 logs a deprecation warning if you
|
||||||
|
still use ``json``).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from odoo import _, http
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.http import request
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _adapter():
|
||||||
|
"""Resolve the bank-rec data adapter from fusion_accounting_ai."""
|
||||||
|
from odoo.addons.fusion_accounting_ai.services.data_adapters import (
|
||||||
|
get_adapter,
|
||||||
|
)
|
||||||
|
return get_adapter(request.env, 'bank_rec')
|
||||||
|
|
||||||
|
|
||||||
|
class FusionBankRecController(http.Controller):
|
||||||
|
"""JSON-RPC surface consumed by the OWL bank-reconciliation widget.
|
||||||
|
|
||||||
|
All routes are ``auth='user'`` -- anonymous traffic is rejected by
|
||||||
|
Odoo's HTTP layer before reaching the handler.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 1. get_state -- initial widget bootstrap
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/get_state', type='jsonrpc', auth='user')
|
||||||
|
def get_state(self, journal_id, company_id):
|
||||||
|
"""Return the journal summary that seeds the kanban widget."""
|
||||||
|
Journal = request.env['account.journal']
|
||||||
|
Line = request.env['account.bank.statement.line']
|
||||||
|
journal = Journal.browse(int(journal_id))
|
||||||
|
if not journal.exists():
|
||||||
|
raise ValidationError(_("Journal %s not found") % journal_id)
|
||||||
|
company_id = int(company_id) if company_id else request.env.company.id
|
||||||
|
unreconciled_lines = Line.search([
|
||||||
|
('journal_id', '=', journal.id),
|
||||||
|
('is_reconciled', '=', False),
|
||||||
|
('company_id', '=', company_id),
|
||||||
|
])
|
||||||
|
total_amount = sum(abs(l.amount) for l in unreconciled_lines)
|
||||||
|
last_stmt = request.env['account.bank.statement'].search(
|
||||||
|
[('journal_id', '=', journal.id)],
|
||||||
|
order='date desc', limit=1)
|
||||||
|
currency = journal.currency_id or journal.company_id.currency_id
|
||||||
|
return {
|
||||||
|
'journal': {
|
||||||
|
'id': journal.id,
|
||||||
|
'name': journal.name,
|
||||||
|
'currency_code': currency.name,
|
||||||
|
},
|
||||||
|
'unreconciled_count': len(unreconciled_lines),
|
||||||
|
'total_pending_amount': total_amount,
|
||||||
|
'last_statement_date': str(last_stmt.date) if last_stmt and last_stmt.date else None,
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 2. list_unreconciled -- paginated, fusion-enriched
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/list_unreconciled', type='jsonrpc', auth='user')
|
||||||
|
def list_unreconciled(self, journal_id, limit=50, offset=0,
|
||||||
|
company_id=None, date_from=None, date_to=None,
|
||||||
|
min_amount=None):
|
||||||
|
"""Return enriched, paginated unreconciled bank lines."""
|
||||||
|
limit = int(limit)
|
||||||
|
offset = int(offset)
|
||||||
|
company_id = (int(company_id) if company_id
|
||||||
|
else request.env.company.id)
|
||||||
|
# The adapter doesn't take an offset; over-fetch and slice.
|
||||||
|
rows = _adapter().list_unreconciled(
|
||||||
|
journal_id=int(journal_id),
|
||||||
|
limit=limit + offset,
|
||||||
|
company_id=company_id,
|
||||||
|
date_from=date_from,
|
||||||
|
date_to=date_to,
|
||||||
|
min_amount=min_amount,
|
||||||
|
)
|
||||||
|
sliced = rows[offset:offset + limit]
|
||||||
|
Line = request.env['account.bank.statement.line']
|
||||||
|
domain = [
|
||||||
|
('journal_id', '=', int(journal_id)),
|
||||||
|
('is_reconciled', '=', False),
|
||||||
|
('company_id', '=', company_id),
|
||||||
|
]
|
||||||
|
if date_from:
|
||||||
|
domain.append(('date', '>=', date_from))
|
||||||
|
if date_to:
|
||||||
|
domain.append(('date', '<=', date_to))
|
||||||
|
if min_amount is not None:
|
||||||
|
domain.append(('amount', '>=', float(min_amount)))
|
||||||
|
total = Line.search_count(domain)
|
||||||
|
return {
|
||||||
|
'count': len(sliced),
|
||||||
|
'total': total,
|
||||||
|
'lines': sliced,
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 3. get_line_detail -- one line + suggestions + attachments
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/get_line_detail', type='jsonrpc', auth='user')
|
||||||
|
def get_line_detail(self, statement_line_id):
|
||||||
|
"""Return full detail for one line including pending suggestions."""
|
||||||
|
Line = request.env['account.bank.statement.line']
|
||||||
|
line = Line.browse(int(statement_line_id))
|
||||||
|
if not line.exists():
|
||||||
|
raise ValidationError(
|
||||||
|
_("Statement line %s not found") % statement_line_id)
|
||||||
|
Sug = request.env['fusion.reconcile.suggestion']
|
||||||
|
suggestions = Sug.search([
|
||||||
|
('statement_line_id', '=', line.id),
|
||||||
|
('state', '=', 'pending'),
|
||||||
|
], order='confidence desc, rank asc')
|
||||||
|
Att = request.env['ir.attachment']
|
||||||
|
attachments = Att.search([
|
||||||
|
('res_model', '=', 'account.move'),
|
||||||
|
('res_id', '=', line.move_id.id),
|
||||||
|
]) if line.move_id else Att.browse()
|
||||||
|
currency = line.currency_id or line.company_id.currency_id
|
||||||
|
return {
|
||||||
|
'line': {
|
||||||
|
'id': line.id,
|
||||||
|
'date': str(line.date) if line.date else None,
|
||||||
|
'payment_ref': line.payment_ref or '',
|
||||||
|
'amount': line.amount,
|
||||||
|
'partner_id': line.partner_id.id if line.partner_id else None,
|
||||||
|
'partner_name': line.partner_id.name if line.partner_id else None,
|
||||||
|
'currency_id': currency.id,
|
||||||
|
'currency_code': currency.name,
|
||||||
|
'journal_id': line.journal_id.id,
|
||||||
|
'journal_name': line.journal_id.name,
|
||||||
|
'is_reconciled': line.is_reconciled,
|
||||||
|
},
|
||||||
|
'suggestions': [{
|
||||||
|
'id': s.id,
|
||||||
|
'candidate_ids': s.proposed_move_line_ids.ids,
|
||||||
|
'confidence': s.confidence,
|
||||||
|
'rank': s.rank,
|
||||||
|
'reasoning': s.reasoning or '',
|
||||||
|
'scores': {
|
||||||
|
'amount_match': s.score_amount_match,
|
||||||
|
'partner_pattern': s.score_partner_pattern,
|
||||||
|
'precedent_similarity': s.score_precedent_similarity,
|
||||||
|
'ai_rerank': s.score_ai_rerank,
|
||||||
|
},
|
||||||
|
} for s in suggestions],
|
||||||
|
'attachments': [{
|
||||||
|
'id': a.id,
|
||||||
|
'name': a.name,
|
||||||
|
'mimetype': a.mimetype,
|
||||||
|
} for a in attachments],
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 4. suggest_matches -- lazy AI suggest for a line
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/suggest_matches', type='jsonrpc', auth='user')
|
||||||
|
def suggest_matches(self, statement_line_ids, limit_per_line=3):
|
||||||
|
"""Trigger AI suggest for one or more statement lines."""
|
||||||
|
ids = [int(i) for i in (statement_line_ids or [])]
|
||||||
|
result = _adapter().suggest_matches(
|
||||||
|
statement_line_ids=ids,
|
||||||
|
limit_per_line=int(limit_per_line),
|
||||||
|
)
|
||||||
|
return {'suggestions': result}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 5. accept_suggestion -- promote AI suggestion to real reconcile
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/accept_suggestion', type='jsonrpc', auth='user')
|
||||||
|
def accept_suggestion(self, suggestion_id):
|
||||||
|
"""Accept a fusion suggestion. Returns the partial IDs created."""
|
||||||
|
sug = request.env['fusion.reconcile.suggestion'].browse(
|
||||||
|
int(suggestion_id))
|
||||||
|
if not sug.exists():
|
||||||
|
raise ValidationError(
|
||||||
|
_("Suggestion %s not found") % suggestion_id)
|
||||||
|
# Capture the journal/company before reconcile (the sug may go stale).
|
||||||
|
journal_id = sug.statement_line_id.journal_id.id
|
||||||
|
company_id = sug.company_id.id
|
||||||
|
result = _adapter().accept_suggestion(suggestion_id=int(suggestion_id))
|
||||||
|
unreconciled_count_after = request.env[
|
||||||
|
'account.bank.statement.line'].search_count([
|
||||||
|
('journal_id', '=', journal_id),
|
||||||
|
('is_reconciled', '=', False),
|
||||||
|
('company_id', '=', company_id),
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
'status': 'accepted',
|
||||||
|
'partial_ids': result.get('partial_ids', []),
|
||||||
|
'unreconciled_count_after': unreconciled_count_after,
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 6. reconcile_manual -- user picked candidates manually
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/reconcile_manual', type='jsonrpc', auth='user')
|
||||||
|
def reconcile_manual(self, statement_line_id, against_move_line_ids):
|
||||||
|
"""Reconcile a line against an explicit set of journal items."""
|
||||||
|
line = request.env['account.bank.statement.line'].browse(
|
||||||
|
int(statement_line_id))
|
||||||
|
if not line.exists():
|
||||||
|
raise ValidationError(
|
||||||
|
_("Statement line %s not found") % statement_line_id)
|
||||||
|
cands = request.env['account.move.line'].browse(
|
||||||
|
[int(i) for i in (against_move_line_ids or [])])
|
||||||
|
result = request.env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
line, against_lines=cands)
|
||||||
|
return {
|
||||||
|
'status': 'reconciled',
|
||||||
|
'partial_ids': result.get('partial_ids', []),
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 7. unreconcile -- reverse a prior reconcile
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/unreconcile', type='jsonrpc', auth='user')
|
||||||
|
def unreconcile(self, partial_reconcile_ids):
|
||||||
|
"""Reverse one or more partial reconciles."""
|
||||||
|
ids = [int(i) for i in (partial_reconcile_ids or [])]
|
||||||
|
result = _adapter().unreconcile(partial_reconcile_ids=ids)
|
||||||
|
return {
|
||||||
|
'status': 'unreconciled',
|
||||||
|
'unreconciled_line_ids': result.get('unreconciled_line_ids', []),
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 8. write_off -- absorb residual into a write-off account
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/write_off', type='jsonrpc', auth='user')
|
||||||
|
def write_off(self, statement_line_id, account_id, amount, label,
|
||||||
|
tax_id=None):
|
||||||
|
"""Apply a write-off against a bank statement line."""
|
||||||
|
line = request.env['account.bank.statement.line'].browse(
|
||||||
|
int(statement_line_id))
|
||||||
|
if not line.exists():
|
||||||
|
raise ValidationError(
|
||||||
|
_("Statement line %s not found") % statement_line_id)
|
||||||
|
account = request.env['account.account'].browse(int(account_id))
|
||||||
|
tax = (request.env['account.tax'].browse(int(tax_id))
|
||||||
|
if tax_id else None)
|
||||||
|
result = request.env['fusion.reconcile.engine'].write_off(
|
||||||
|
line, account=account, amount=float(amount),
|
||||||
|
tax_id=tax, label=label)
|
||||||
|
return {
|
||||||
|
'status': 'written_off',
|
||||||
|
'partial_ids': result.get('partial_ids', []),
|
||||||
|
'write_off_move_id': result.get('write_off_move_id'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 9. bulk_reconcile -- batch auto-reconcile a recordset
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/bulk_reconcile', type='jsonrpc', auth='user')
|
||||||
|
def bulk_reconcile(self, statement_line_ids, strategy='auto'):
|
||||||
|
"""Batch auto-reconcile. Returns counts + per-line errors."""
|
||||||
|
ids = [int(i) for i in (statement_line_ids or [])]
|
||||||
|
lines = request.env['account.bank.statement.line'].browse(ids)
|
||||||
|
result = request.env['fusion.reconcile.engine'].reconcile_batch(
|
||||||
|
lines, strategy=strategy)
|
||||||
|
return result
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 10. get_partner_history -- partner reconcile history panel
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@http.route('/fusion/bank_rec/get_partner_history', type='jsonrpc', auth='user')
|
||||||
|
def get_partner_history(self, partner_id, limit=20):
|
||||||
|
"""Return a partner's reconcile history + learned pattern."""
|
||||||
|
Partner = request.env['res.partner']
|
||||||
|
partner = Partner.browse(int(partner_id))
|
||||||
|
if not partner.exists():
|
||||||
|
raise ValidationError(_("Partner %s not found") % partner_id)
|
||||||
|
Precedent = request.env['fusion.reconcile.precedent']
|
||||||
|
recent = Precedent.search(
|
||||||
|
[('partner_id', '=', partner.id)],
|
||||||
|
order='reconciled_at desc, id desc',
|
||||||
|
limit=int(limit),
|
||||||
|
)
|
||||||
|
Pattern = request.env['fusion.reconcile.pattern']
|
||||||
|
pattern = Pattern.search(
|
||||||
|
[('partner_id', '=', partner.id)], limit=1)
|
||||||
|
return {
|
||||||
|
'partner': {
|
||||||
|
'id': partner.id,
|
||||||
|
'name': partner.name,
|
||||||
|
},
|
||||||
|
'recent_reconciles': [{
|
||||||
|
'precedent_id': p.id,
|
||||||
|
'date': str(p.date) if p.date else None,
|
||||||
|
'amount': p.amount,
|
||||||
|
'memo_tokens': p.memo_tokens or '',
|
||||||
|
'matched_count': p.matched_move_line_count,
|
||||||
|
'source': p.source,
|
||||||
|
} for p in recent],
|
||||||
|
'pattern': ({
|
||||||
|
'reconcile_count': pattern.reconcile_count,
|
||||||
|
'pref_strategy': pattern.pref_strategy or None,
|
||||||
|
'common_memo_tokens': pattern.common_memo_tokens or None,
|
||||||
|
'typical_cadence_days': pattern.typical_cadence_days,
|
||||||
|
} if pattern else None),
|
||||||
|
}
|
||||||
35
fusion_accounting_bank_rec/data/cron.xml
Normal file
35
fusion_accounting_bank_rec/data/cron.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo noupdate="1">
|
||||||
|
|
||||||
|
<record id="cron_fusion_bank_rec_suggest" model="ir.cron">
|
||||||
|
<field name="name">Fusion Bank Rec — Warm AI Suggestions</field>
|
||||||
|
<field name="model_id" ref="model_fusion_bank_rec_cron"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model._cron_suggest_pending()</field>
|
||||||
|
<field name="interval_number">30</field>
|
||||||
|
<field name="interval_type">minutes</field>
|
||||||
|
<field name="active" eval="True"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="cron_fusion_bank_rec_pattern_refresh" model="ir.cron">
|
||||||
|
<field name="name">Fusion Bank Rec — Refresh Partner Patterns</field>
|
||||||
|
<field name="model_id" ref="model_fusion_bank_rec_cron"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model._cron_refresh_patterns()</field>
|
||||||
|
<field name="interval_number">1</field>
|
||||||
|
<field name="interval_type">days</field>
|
||||||
|
<field name="nextcall" eval="(DateTime.now().replace(hour=2, minute=0, second=0) + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
|
||||||
|
<field name="active" eval="True"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="cron_fusion_bank_rec_mv_refresh" model="ir.cron">
|
||||||
|
<field name="name">Fusion Bank Rec — Refresh Unreconciled MV</field>
|
||||||
|
<field name="model_id" ref="model_fusion_bank_rec_cron"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model._cron_refresh_mv()</field>
|
||||||
|
<field name="interval_number">5</field>
|
||||||
|
<field name="interval_type">minutes</field>
|
||||||
|
<field name="active" eval="True"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
-- Materialized view: pre-aggregated data for the OWL bank reconciliation widget.
|
||||||
|
-- Refreshed on cron (Task 25) and on suggestion writes.
|
||||||
|
-- Indexed on (company_id, journal_id, date) for fast UI queries.
|
||||||
|
|
||||||
|
-- NOTE: account_bank_statement_line does not store `date` directly in V19;
|
||||||
|
-- it is a related field through move_id -> account_move.date. We JOIN on
|
||||||
|
-- account_move to get it.
|
||||||
|
CREATE MATERIALIZED VIEW IF NOT EXISTS fusion_unreconciled_bank_line_mv AS
|
||||||
|
SELECT
|
||||||
|
bsl.id AS id,
|
||||||
|
bsl.company_id AS company_id,
|
||||||
|
bsl.journal_id AS journal_id,
|
||||||
|
am.date AS date,
|
||||||
|
bsl.amount AS amount,
|
||||||
|
bsl.payment_ref AS payment_ref,
|
||||||
|
bsl.currency_id AS currency_id,
|
||||||
|
bsl.partner_id AS partner_id,
|
||||||
|
bsl.create_date AS create_date,
|
||||||
|
-- Top suggestion (highest confidence pending one)
|
||||||
|
(SELECT s.id FROM fusion_reconcile_suggestion s
|
||||||
|
WHERE s.statement_line_id = bsl.id AND s.state = 'pending'
|
||||||
|
ORDER BY s.confidence DESC, s.rank ASC LIMIT 1) AS top_suggestion_id,
|
||||||
|
(SELECT s.confidence FROM fusion_reconcile_suggestion s
|
||||||
|
WHERE s.statement_line_id = bsl.id AND s.state = 'pending'
|
||||||
|
ORDER BY s.confidence DESC, s.rank ASC LIMIT 1) AS top_confidence,
|
||||||
|
CASE
|
||||||
|
WHEN (SELECT MAX(s.confidence) FROM fusion_reconcile_suggestion s
|
||||||
|
WHERE s.statement_line_id = bsl.id AND s.state = 'pending') >= 0.85
|
||||||
|
THEN 'high'
|
||||||
|
WHEN (SELECT MAX(s.confidence) FROM fusion_reconcile_suggestion s
|
||||||
|
WHERE s.statement_line_id = bsl.id AND s.state = 'pending') >= 0.60
|
||||||
|
THEN 'medium'
|
||||||
|
WHEN (SELECT MAX(s.confidence) FROM fusion_reconcile_suggestion s
|
||||||
|
WHERE s.statement_line_id = bsl.id AND s.state = 'pending') > 0
|
||||||
|
THEN 'low'
|
||||||
|
ELSE 'none'
|
||||||
|
END AS confidence_band,
|
||||||
|
-- Attachment count (assumes ir_attachment.res_model='account.bank.statement.line')
|
||||||
|
(SELECT COUNT(*) FROM ir_attachment att
|
||||||
|
WHERE att.res_model = 'account.bank.statement.line' AND att.res_id = bsl.id)
|
||||||
|
AS attachment_count,
|
||||||
|
-- Partner reconcile pattern hint
|
||||||
|
COALESCE((SELECT p.reconcile_count FROM fusion_reconcile_pattern p
|
||||||
|
WHERE p.partner_id = bsl.partner_id AND p.company_id = bsl.company_id LIMIT 1), 0)
|
||||||
|
AS partner_reconcile_count
|
||||||
|
FROM account_bank_statement_line bsl
|
||||||
|
JOIN account_move am ON am.id = bsl.move_id
|
||||||
|
WHERE bsl.is_reconciled IS NOT TRUE;
|
||||||
|
|
||||||
|
-- Indexes for the common UI queries: filter by company + journal, sort by date desc.
|
||||||
|
CREATE INDEX IF NOT EXISTS fusion_mv_unrec_company_journal_date_idx
|
||||||
|
ON fusion_unreconciled_bank_line_mv (company_id, journal_id, date DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS fusion_mv_unrec_partner_idx
|
||||||
|
ON fusion_unreconciled_bank_line_mv (partner_id) WHERE partner_id IS NOT NULL;
|
||||||
|
-- UNIQUE index required for CONCURRENTLY refresh
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS fusion_mv_unrec_id_idx
|
||||||
|
ON fusion_unreconciled_bank_line_mv (id);
|
||||||
@@ -5,3 +5,6 @@ from . import fusion_bank_rec_widget
|
|||||||
from . import account_bank_statement_line
|
from . import account_bank_statement_line
|
||||||
from . import account_reconcile_model
|
from . import account_reconcile_model
|
||||||
from . import fusion_reconcile_engine
|
from . import fusion_reconcile_engine
|
||||||
|
from . import fusion_unreconciled_bank_line_mv
|
||||||
|
from . import fusion_bank_rec_cron
|
||||||
|
from . import fusion_migration_wizard
|
||||||
|
|||||||
119
fusion_accounting_bank_rec/models/fusion_bank_rec_cron.py
Normal file
119
fusion_accounting_bank_rec/models/fusion_bank_rec_cron.py
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
"""Cron handler model for fusion_accounting_bank_rec.
|
||||||
|
|
||||||
|
Three scheduled jobs:
|
||||||
|
- _cron_suggest_pending: warm AI suggestions for unreconciled lines (30 min)
|
||||||
|
- _cron_refresh_patterns: recompute fusion.reconcile.pattern aggregates (daily 02:00)
|
||||||
|
- _cron_refresh_mv: REFRESH MATERIALIZED VIEW CONCURRENTLY (5 min)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import odoo
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
from ..services.pattern_extractor import extract_pattern_for_partner
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class FusionBankRecCron(models.AbstractModel):
|
||||||
|
_name = "fusion.bank.rec.cron"
|
||||||
|
_description = "Fusion Bank Reconciliation Cron Handlers"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _cron_suggest_pending(self, batch_size=50):
|
||||||
|
"""For each unreconciled bank line that doesn't have a recent pending
|
||||||
|
suggestion, run engine.suggest_matches.
|
||||||
|
|
||||||
|
Recent = a pending suggestion created within the last 24 hours."""
|
||||||
|
cutoff = fields.Datetime.now() - timedelta(hours=24)
|
||||||
|
Line = self.env['account.bank.statement.line']
|
||||||
|
lines_to_consider = Line.search([
|
||||||
|
('is_reconciled', '=', False),
|
||||||
|
('partner_id', '!=', False),
|
||||||
|
], limit=batch_size * 5)
|
||||||
|
|
||||||
|
Suggestion = self.env['fusion.reconcile.suggestion']
|
||||||
|
lines_needing_suggestions = self.env['account.bank.statement.line']
|
||||||
|
for line in lines_to_consider:
|
||||||
|
recent = Suggestion.search_count([
|
||||||
|
('statement_line_id', '=', line.id),
|
||||||
|
('state', '=', 'pending'),
|
||||||
|
('create_date', '>=', cutoff),
|
||||||
|
])
|
||||||
|
if recent == 0:
|
||||||
|
lines_needing_suggestions |= line
|
||||||
|
if len(lines_needing_suggestions) >= batch_size:
|
||||||
|
break
|
||||||
|
|
||||||
|
if not lines_needing_suggestions:
|
||||||
|
_logger.debug("Cron: no bank lines need suggestion warming")
|
||||||
|
return
|
||||||
|
|
||||||
|
_logger.info(
|
||||||
|
"Cron: warming suggestions for %d bank lines",
|
||||||
|
len(lines_needing_suggestions))
|
||||||
|
try:
|
||||||
|
self.env['fusion.reconcile.engine'].suggest_matches(
|
||||||
|
lines_needing_suggestions, limit_per_line=3)
|
||||||
|
except Exception as e:
|
||||||
|
_logger.exception("Cron suggest_pending failed: %s", e)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _cron_refresh_patterns(self):
|
||||||
|
"""For each (company, partner) pair with precedents, recompute and
|
||||||
|
upsert the fusion.reconcile.pattern row."""
|
||||||
|
Pattern = self.env['fusion.reconcile.pattern']
|
||||||
|
self.env.cr.execute("""
|
||||||
|
SELECT DISTINCT company_id, partner_id
|
||||||
|
FROM fusion_reconcile_precedent
|
||||||
|
WHERE partner_id IS NOT NULL
|
||||||
|
""")
|
||||||
|
pairs = self.env.cr.fetchall()
|
||||||
|
_logger.info(
|
||||||
|
"Cron: refreshing patterns for %d (company, partner) pairs",
|
||||||
|
len(pairs))
|
||||||
|
for company_id, partner_id in pairs:
|
||||||
|
try:
|
||||||
|
vals = extract_pattern_for_partner(
|
||||||
|
self.env, company_id=company_id, partner_id=partner_id)
|
||||||
|
existing = Pattern.search([
|
||||||
|
('company_id', '=', company_id),
|
||||||
|
('partner_id', '=', partner_id),
|
||||||
|
], limit=1)
|
||||||
|
if existing:
|
||||||
|
existing.write(vals)
|
||||||
|
else:
|
||||||
|
Pattern.create(vals)
|
||||||
|
except Exception as e:
|
||||||
|
_logger.warning(
|
||||||
|
"Pattern refresh failed for company=%s partner=%s: %s",
|
||||||
|
company_id, partner_id, e)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _cron_refresh_mv(self):
|
||||||
|
"""Refresh the materialized view CONCURRENTLY using an autocommit cursor.
|
||||||
|
|
||||||
|
REFRESH CONCURRENTLY can't run inside a transaction, so we open a
|
||||||
|
fresh connection in autocommit mode (per Task 24's note). On any
|
||||||
|
failure, we fall back to the model's blocking refresh."""
|
||||||
|
try:
|
||||||
|
db_name = self.env.cr.dbname
|
||||||
|
db = odoo.sql_db.db_connect(db_name)
|
||||||
|
with db.cursor() as cron_cr:
|
||||||
|
cron_cr._cnx.set_session(autocommit=True)
|
||||||
|
cron_cr.execute(
|
||||||
|
"REFRESH MATERIALIZED VIEW CONCURRENTLY "
|
||||||
|
"fusion_unreconciled_bank_line_mv")
|
||||||
|
_logger.debug("Cron: MV refresh CONCURRENTLY succeeded")
|
||||||
|
except Exception as e:
|
||||||
|
_logger.warning(
|
||||||
|
"Cron MV refresh CONCURRENTLY failed (%s); falling back to "
|
||||||
|
"blocking refresh", e)
|
||||||
|
try:
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
except Exception as e2:
|
||||||
|
_logger.exception(
|
||||||
|
"Cron MV refresh fallback also failed: %s", e2)
|
||||||
97
fusion_accounting_bank_rec/models/fusion_migration_wizard.py
Normal file
97
fusion_accounting_bank_rec/models/fusion_migration_wizard.py
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
"""Bank-rec specific migration step.
|
||||||
|
|
||||||
|
Hooks into fusion.migration.wizard (defined by fusion_accounting_migration)
|
||||||
|
to bootstrap fusion.reconcile.precedent from existing
|
||||||
|
account.partial.reconcile rows. This gives the AI immediate "memory" from
|
||||||
|
past Enterprise reconciles so suggestions can be ranked by precedent
|
||||||
|
similarity from day one.
|
||||||
|
|
||||||
|
The bootstrap step is exposed as a public method (_bank_rec_bootstrap_step)
|
||||||
|
so tests and the audit report can invoke it directly. action_run_migration
|
||||||
|
is overridden to call super() then run the bootstrap.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from odoo import _, models
|
||||||
|
|
||||||
|
from ..services.precedent_backfill import backfill_precedents
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class FusionMigrationWizard(models.TransientModel):
|
||||||
|
_inherit = "fusion.migration.wizard"
|
||||||
|
|
||||||
|
def _bank_rec_bootstrap_step(self):
|
||||||
|
"""Migration step: backfill precedents + refresh patterns + refresh MV.
|
||||||
|
|
||||||
|
Returns a dict describing what happened, suitable for surfacing to
|
||||||
|
the user via notification or PDF audit report.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
_logger.info(
|
||||||
|
"fusion_accounting_bank_rec migration step: bootstrap starting")
|
||||||
|
|
||||||
|
company_id = None
|
||||||
|
if 'company_id' in self._fields and self.company_id:
|
||||||
|
company_id = self.company_id.id
|
||||||
|
|
||||||
|
precedent_result = backfill_precedents(
|
||||||
|
self.env, company_id=company_id, limit=10000)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.env['fusion.bank.rec.cron']._cron_refresh_patterns()
|
||||||
|
patterns_ok = True
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
_logger.warning(
|
||||||
|
"Pattern refresh during migration failed: %s", e)
|
||||||
|
patterns_ok = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
mv_ok = True
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
_logger.warning("MV refresh during migration failed: %s", e)
|
||||||
|
mv_ok = False
|
||||||
|
|
||||||
|
result = {
|
||||||
|
'step': 'bank_rec_bootstrap',
|
||||||
|
'precedents_created': precedent_result['created'],
|
||||||
|
'precedents_skipped': precedent_result['skipped'],
|
||||||
|
'patterns_refreshed': patterns_ok,
|
||||||
|
'mv_refreshed': mv_ok,
|
||||||
|
}
|
||||||
|
_logger.info(
|
||||||
|
"fusion_accounting_bank_rec bootstrap complete: %s", result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def action_run_migration(self):
|
||||||
|
"""Override the migration entry-point to add the bank-rec step.
|
||||||
|
|
||||||
|
Calls super() (which currently returns a notification stub from
|
||||||
|
Phase 0) and then runs the bank-rec bootstrap. Returns a
|
||||||
|
notification summarizing both.
|
||||||
|
"""
|
||||||
|
_ = super().action_run_migration()
|
||||||
|
result = self._bank_rec_bootstrap_step()
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.client',
|
||||||
|
'tag': 'display_notification',
|
||||||
|
'params': {
|
||||||
|
'type': 'success',
|
||||||
|
'title': _("Bank-Rec Migration Complete"),
|
||||||
|
'message': _(
|
||||||
|
"Backfilled %(created)d precedents "
|
||||||
|
"(skipped %(skipped)d). "
|
||||||
|
"Patterns refreshed: %(p)s. MV refreshed: %(m)s."
|
||||||
|
) % {
|
||||||
|
'created': result['precedents_created'],
|
||||||
|
'skipped': result['precedents_skipped'],
|
||||||
|
'p': 'yes' if result['patterns_refreshed'] else 'no',
|
||||||
|
'm': 'yes' if result['mv_refreshed'] else 'no',
|
||||||
|
},
|
||||||
|
'sticky': False,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -177,14 +177,19 @@ class FusionReconcileEngine(models.AbstractModel):
|
|||||||
if line.is_reconciled:
|
if line.is_reconciled:
|
||||||
skipped += 1
|
skipped += 1
|
||||||
continue
|
continue
|
||||||
|
# Per-line savepoint so a single DB-level failure (e.g. a
|
||||||
|
# check-constraint violation on one bad line) doesn't poison
|
||||||
|
# the whole batch's transaction.
|
||||||
try:
|
try:
|
||||||
candidates = self._fetch_candidates(line)
|
with self.env.cr.savepoint():
|
||||||
picked = self._apply_strategy(line, candidates, strategy)
|
candidates = self._fetch_candidates(line)
|
||||||
if picked:
|
picked = self._apply_strategy(
|
||||||
self.reconcile_one(line, against_lines=picked)
|
line, candidates, strategy)
|
||||||
reconciled += 1
|
if picked:
|
||||||
else:
|
self.reconcile_one(line, against_lines=picked)
|
||||||
skipped += 1
|
reconciled += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
except Exception as e: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
errors.append({'line_id': line.id, 'error': str(e)})
|
errors.append({'line_id': line.id, 'error': str(e)})
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class FusionReconcilePrecedent(models.Model):
|
|||||||
reconciled_at = fields.Datetime()
|
reconciled_at = fields.Datetime()
|
||||||
source = fields.Selection([
|
source = fields.Selection([
|
||||||
('historical_bootstrap', 'Imported from history'),
|
('historical_bootstrap', 'Imported from history'),
|
||||||
|
('backfill', 'Backfilled from account.partial.reconcile (migration)'),
|
||||||
('manual', 'Manual reconcile via fusion'),
|
('manual', 'Manual reconcile via fusion'),
|
||||||
('ai_accepted', 'AI suggestion accepted'),
|
('ai_accepted', 'AI suggestion accepted'),
|
||||||
('auto_rule', 'account.reconcile.model auto-fired'),
|
('auto_rule', 'account.reconcile.model auto-fired'),
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ suggestions here, and the user (or batch-accept action) approves them
|
|||||||
through the engine's accept_suggestion() method.
|
through the engine's accept_suggestion() method.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FusionReconcileSuggestion(models.Model):
|
class FusionReconcileSuggestion(models.Model):
|
||||||
_name = "fusion.reconcile.suggestion"
|
_name = "fusion.reconcile.suggestion"
|
||||||
@@ -96,3 +100,38 @@ class FusionReconcileSuggestion(models.Model):
|
|||||||
sug.confidence_band = 'low'
|
sug.confidence_band = 'low'
|
||||||
else:
|
else:
|
||||||
sug.confidence_band = 'none'
|
sug.confidence_band = 'none'
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# CRUD overrides — trigger MV refresh so the OWL widget sees fresh
|
||||||
|
# confidence bands / top suggestion ids without waiting for cron.
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
records = super().create(vals_list)
|
||||||
|
self._trigger_mv_refresh()
|
||||||
|
return records
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
res = super().write(vals)
|
||||||
|
# Only refresh on changes that affect the MV's projected columns.
|
||||||
|
if 'state' in vals or 'confidence' in vals or 'rank' in vals:
|
||||||
|
self._trigger_mv_refresh()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _trigger_mv_refresh(self):
|
||||||
|
"""Best-effort MV refresh; never poison the originating transaction.
|
||||||
|
|
||||||
|
Uses concurrently=False because Postgres forbids
|
||||||
|
REFRESH MATERIALIZED VIEW CONCURRENTLY inside a transaction block,
|
||||||
|
and Odoo's per-request cursor is always in a transaction. The cron
|
||||||
|
job (Task 25) opens a dedicated autocommit cursor for CONCURRENTLY
|
||||||
|
refreshes when the MV grows large enough that a brief blocking
|
||||||
|
refresh becomes objectionable.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
_logger.warning(
|
||||||
|
"MV refresh after suggestion write failed: %s", e)
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
"""Materialized view exposing pre-aggregated unreconciled-bank-line data.
|
||||||
|
|
||||||
|
The MV is created in the model's init() (called by Odoo on install/upgrade).
|
||||||
|
Refresh strategy:
|
||||||
|
- Cron (every 5 min) — see fusion_accounting_bank_rec/data/cron.xml (Task 25)
|
||||||
|
- Triggered refresh after suggestion writes (handled in fusion_reconcile_suggestion.py)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class FusionUnreconciledBankLineMV(models.Model):
|
||||||
|
_name = "fusion.unreconciled.bank.line.mv"
|
||||||
|
_description = "Materialized view of unreconciled bank lines for OWL widget"
|
||||||
|
_auto = False # we manage the table ourselves
|
||||||
|
_table = "fusion_unreconciled_bank_line_mv"
|
||||||
|
_order = "date desc, id desc"
|
||||||
|
|
||||||
|
# Fields mirror the columns in the SQL view; required so Odoo can read them.
|
||||||
|
company_id = fields.Many2one('res.company', readonly=True)
|
||||||
|
journal_id = fields.Many2one('account.journal', readonly=True)
|
||||||
|
date = fields.Date(readonly=True)
|
||||||
|
amount = fields.Float(readonly=True)
|
||||||
|
payment_ref = fields.Char(readonly=True)
|
||||||
|
currency_id = fields.Many2one('res.currency', readonly=True)
|
||||||
|
partner_id = fields.Many2one('res.partner', readonly=True)
|
||||||
|
create_date = fields.Datetime(readonly=True)
|
||||||
|
top_suggestion_id = fields.Many2one('fusion.reconcile.suggestion', readonly=True)
|
||||||
|
top_confidence = fields.Float(readonly=True)
|
||||||
|
confidence_band = fields.Selection([
|
||||||
|
('high', 'High'),
|
||||||
|
('medium', 'Medium'),
|
||||||
|
('low', 'Low'),
|
||||||
|
('none', 'None'),
|
||||||
|
], readonly=True)
|
||||||
|
attachment_count = fields.Integer(readonly=True)
|
||||||
|
partner_reconcile_count = fields.Integer(readonly=True)
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
"""Create the MV if missing.
|
||||||
|
|
||||||
|
Reads create_mv_unreconciled_bank_line.sql and executes it. Idempotent
|
||||||
|
because the SQL uses CREATE MATERIALIZED VIEW IF NOT EXISTS."""
|
||||||
|
sql_path = os.path.join(
|
||||||
|
os.path.dirname(__file__), '..', 'data', 'sql',
|
||||||
|
'create_mv_unreconciled_bank_line.sql')
|
||||||
|
with open(sql_path, 'r') as f:
|
||||||
|
sql = f.read()
|
||||||
|
self.env.cr.execute(sql)
|
||||||
|
_logger.info(
|
||||||
|
"fusion_unreconciled_bank_line_mv: created/verified MV + indexes")
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _refresh(self, *, concurrently=True):
|
||||||
|
"""Refresh the MV.
|
||||||
|
|
||||||
|
If ``concurrently=True`` (default), uses
|
||||||
|
REFRESH MATERIALIZED VIEW CONCURRENTLY (requires the unique index).
|
||||||
|
Falls back to a blocking refresh on the first refresh after creation
|
||||||
|
(when CONCURRENTLY is not yet allowed because the MV has never been
|
||||||
|
populated).
|
||||||
|
|
||||||
|
Flushes the ORM cache first so the materialization sees the latest
|
||||||
|
committed-to-DB values for fields like ``is_reconciled`` (computed,
|
||||||
|
stored — sometimes still buffered in the cache mid-request)."""
|
||||||
|
self.env.flush_all()
|
||||||
|
keyword = "CONCURRENTLY" if concurrently else ""
|
||||||
|
try:
|
||||||
|
self.env.cr.execute(
|
||||||
|
f"REFRESH MATERIALIZED VIEW {keyword} fusion_unreconciled_bank_line_mv"
|
||||||
|
)
|
||||||
|
_logger.debug(
|
||||||
|
"fusion_unreconciled_bank_line_mv refreshed (%s)",
|
||||||
|
'concurrent' if concurrently else 'blocking')
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
# CONCURRENTLY fails on first refresh after creation if the MV is
|
||||||
|
# empty / has never been populated; fall back to non-concurrent.
|
||||||
|
if concurrently:
|
||||||
|
_logger.warning(
|
||||||
|
"Concurrent MV refresh failed (%s); falling back to "
|
||||||
|
"blocking refresh", e)
|
||||||
|
self.env.cr.execute(
|
||||||
|
"REFRESH MATERIALIZED VIEW fusion_unreconciled_bank_line_mv"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
1
fusion_accounting_bank_rec/reports/__init__.py
Normal file
1
fusion_accounting_bank_rec/reports/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import migration_audit_report
|
||||||
51
fusion_accounting_bank_rec/reports/migration_audit_report.py
Normal file
51
fusion_accounting_bank_rec/reports/migration_audit_report.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"""QWeb PDF report: summary of bank-rec migration outcomes.
|
||||||
|
|
||||||
|
Triggered from the migration wizard's "Print" menu after the wizard
|
||||||
|
completes. For each company on the system, reports:
|
||||||
|
- Backfilled precedents (source='backfill')
|
||||||
|
- Fusion reconcile patterns
|
||||||
|
- Bank statement lines still unreconciled
|
||||||
|
|
||||||
|
Lets the operator confirm Phase 1 migration successfully bootstrapped
|
||||||
|
the AI's reconcile memory from past Enterprise reconciles.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class FusionMigrationAuditReport(models.AbstractModel):
|
||||||
|
_name = "report.fusion_accounting_bank_rec.migration_audit_template"
|
||||||
|
_description = "Bank-Rec Migration Audit Report"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_report_values(self, docids, data=None):
|
||||||
|
Wizard = self.env['fusion.migration.wizard']
|
||||||
|
wizards = Wizard.browse(docids) if docids else Wizard
|
||||||
|
|
||||||
|
Precedent = self.env['fusion.reconcile.precedent']
|
||||||
|
Pattern = self.env['fusion.reconcile.pattern']
|
||||||
|
Line = self.env['account.bank.statement.line']
|
||||||
|
|
||||||
|
company_stats = []
|
||||||
|
for company in self.env['res.company'].search([]):
|
||||||
|
company_stats.append({
|
||||||
|
'company': company,
|
||||||
|
'precedents_count': Precedent.search_count([
|
||||||
|
('company_id', '=', company.id),
|
||||||
|
('source', '=', 'backfill'),
|
||||||
|
]),
|
||||||
|
'patterns_count': Pattern.search_count([
|
||||||
|
('company_id', '=', company.id),
|
||||||
|
]),
|
||||||
|
'unreconciled_count': Line.search_count([
|
||||||
|
('company_id', '=', company.id),
|
||||||
|
('is_reconciled', '=', False),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'doc_ids': docids,
|
||||||
|
'doc_model': 'fusion.migration.wizard',
|
||||||
|
'docs': wizards,
|
||||||
|
'company_stats': company_stats,
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="action_report_migration_audit" model="ir.actions.report">
|
||||||
|
<field name="name">Bank-Rec Migration Audit</field>
|
||||||
|
<field name="model">fusion.migration.wizard</field>
|
||||||
|
<field name="report_type">qweb-pdf</field>
|
||||||
|
<field name="report_name">fusion_accounting_bank_rec.migration_audit_template</field>
|
||||||
|
<field name="report_file">fusion_accounting_bank_rec.migration_audit_template</field>
|
||||||
|
<field name="binding_model_id" ref="fusion_accounting_migration.model_fusion_migration_wizard"/>
|
||||||
|
<field name="binding_type">report</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<template id="migration_audit_template">
|
||||||
|
<t t-call="web.html_container">
|
||||||
|
<t t-call="web.external_layout">
|
||||||
|
<div class="page">
|
||||||
|
<h2>Bank-Rec Migration Audit</h2>
|
||||||
|
<p>
|
||||||
|
Generated
|
||||||
|
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Per-Company Summary</h3>
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Company</th>
|
||||||
|
<th class="text-end">Backfilled Precedents</th>
|
||||||
|
<th class="text-end">Patterns</th>
|
||||||
|
<th class="text-end">Still Unreconciled</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr t-foreach="company_stats" t-as="cs">
|
||||||
|
<td><span t-esc="cs['company'].name"/></td>
|
||||||
|
<td class="text-end"><span t-esc="cs['precedents_count']"/></td>
|
||||||
|
<td class="text-end"><span t-esc="cs['patterns_count']"/></td>
|
||||||
|
<td class="text-end"><span t-esc="cs['unreconciled_count']"/></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p class="text-muted">
|
||||||
|
This report verifies that Phase 1 migration successfully
|
||||||
|
bootstrapped the AI's reconcile memory from past Enterprise
|
||||||
|
reconciles.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</template>
|
||||||
|
</odoo>
|
||||||
@@ -6,3 +6,7 @@ access_fusion_reconcile_precedent_admin,precedent admin,model_fusion_reconcile_p
|
|||||||
access_fusion_reconcile_suggestion_user,suggestion user,model_fusion_reconcile_suggestion,fusion_accounting_core.group_fusion_accounting_user,1,0,0,0
|
access_fusion_reconcile_suggestion_user,suggestion user,model_fusion_reconcile_suggestion,fusion_accounting_core.group_fusion_accounting_user,1,0,0,0
|
||||||
access_fusion_reconcile_suggestion_admin,suggestion admin,model_fusion_reconcile_suggestion,fusion_accounting_core.group_fusion_accounting_admin,1,1,1,1
|
access_fusion_reconcile_suggestion_admin,suggestion admin,model_fusion_reconcile_suggestion,fusion_accounting_core.group_fusion_accounting_admin,1,1,1,1
|
||||||
access_fusion_bank_rec_widget_user,bank rec widget user,model_fusion_bank_rec_widget,fusion_accounting_core.group_fusion_accounting_user,1,1,1,1
|
access_fusion_bank_rec_widget_user,bank rec widget user,model_fusion_bank_rec_widget,fusion_accounting_core.group_fusion_accounting_user,1,1,1,1
|
||||||
|
access_fusion_unreconciled_bank_line_mv_user,unreconciled bank line mv user,model_fusion_unreconciled_bank_line_mv,fusion_accounting_core.group_fusion_accounting_user,1,0,0,0
|
||||||
|
access_fusion_unreconciled_bank_line_mv_admin,unreconciled bank line mv admin,model_fusion_unreconciled_bank_line_mv,fusion_accounting_core.group_fusion_accounting_admin,1,0,0,0
|
||||||
|
access_fusion_auto_reconcile_wizard_user,fusion.auto.reconcile.wizard.user,model_fusion_auto_reconcile_wizard,base.group_user,1,1,1,0
|
||||||
|
access_fusion_bulk_reconcile_wizard_user,fusion.bulk.reconcile.wizard.user,model_fusion_bulk_reconcile_wizard,base.group_user,1,1,1,0
|
||||||
|
|||||||
|
@@ -4,3 +4,4 @@ from . import matching_strategies
|
|||||||
from . import precedent_lookup
|
from . import precedent_lookup
|
||||||
from . import pattern_extractor
|
from . import pattern_extractor
|
||||||
from . import confidence_scoring
|
from . import confidence_scoring
|
||||||
|
from . import precedent_backfill
|
||||||
|
|||||||
116
fusion_accounting_bank_rec/services/precedent_backfill.py
Normal file
116
fusion_accounting_bank_rec/services/precedent_backfill.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
"""Pure-Python helpers for backfilling fusion.reconcile.precedent
|
||||||
|
from existing account.partial.reconcile rows during migration.
|
||||||
|
|
||||||
|
Strategy:
|
||||||
|
- Each account.partial.reconcile that involves at least one
|
||||||
|
account.bank.statement.line's reconcile-account line is a candidate.
|
||||||
|
- One precedent per qualifying partial. The (statement_line.id, account_id,
|
||||||
|
amount) triple is encoded into matched_account_ids so a second run can
|
||||||
|
detect and skip already-backfilled rows (idempotency).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from .memo_tokenizer import tokenize_memo
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _identify_bank_side(partial):
|
||||||
|
"""Return (bank_move_line, counterpart_move_line, statement_line_id)
|
||||||
|
or (None, None, None) if neither side is a bank statement line."""
|
||||||
|
debit_line = partial.debit_move_id
|
||||||
|
credit_line = partial.credit_move_id
|
||||||
|
|
||||||
|
if debit_line.move_id.statement_line_id:
|
||||||
|
return debit_line, credit_line, debit_line.move_id.statement_line_id.id
|
||||||
|
if credit_line.move_id.statement_line_id:
|
||||||
|
return credit_line, debit_line, credit_line.move_id.statement_line_id.id
|
||||||
|
return None, None, None
|
||||||
|
|
||||||
|
|
||||||
|
def backfill_precedents(env, *, company_id=None, batch_size=500, limit=10000):
|
||||||
|
"""Walk account.partial.reconcile and create fusion.reconcile.precedent
|
||||||
|
rows for any reconcile that involves a bank statement line.
|
||||||
|
|
||||||
|
Idempotent: skips partials whose (statement_line, account, amount)
|
||||||
|
signature is already present in fusion.reconcile.precedent (encoded
|
||||||
|
via matched_account_ids).
|
||||||
|
|
||||||
|
Returns dict with `created` and `skipped` counts.
|
||||||
|
"""
|
||||||
|
Precedent = env['fusion.reconcile.precedent'].sudo()
|
||||||
|
Partial = env['account.partial.reconcile'].sudo()
|
||||||
|
Line = env['account.bank.statement.line'].sudo()
|
||||||
|
|
||||||
|
in_test_mode = env.cr.__class__.__name__ == 'TestCursor'
|
||||||
|
|
||||||
|
# Pre-filter to partials that touch a bank statement line on either side.
|
||||||
|
# In a real DB we typically have 10x more invoice<->payment partials than
|
||||||
|
# bank-rec partials; filtering here keeps the loop bounded and makes the
|
||||||
|
# default limit reflect "real" candidates rather than every partial ever.
|
||||||
|
domain = [
|
||||||
|
'|',
|
||||||
|
('debit_move_id.move_id.statement_line_id', '!=', False),
|
||||||
|
('credit_move_id.move_id.statement_line_id', '!=', False),
|
||||||
|
]
|
||||||
|
if company_id:
|
||||||
|
domain.append(('company_id', '=', company_id))
|
||||||
|
partials = Partial.search(domain, limit=limit, order='id asc')
|
||||||
|
|
||||||
|
created = 0
|
||||||
|
skipped = 0
|
||||||
|
for partial in partials:
|
||||||
|
bank_line, counterpart, bsl_id = _identify_bank_side(partial)
|
||||||
|
if not bsl_id:
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
signature_account = str(counterpart.account_id.id)
|
||||||
|
|
||||||
|
existing = Precedent.search([
|
||||||
|
('partner_id', '=',
|
||||||
|
counterpart.partner_id.id if counterpart.partner_id else False),
|
||||||
|
('amount', '=', abs(partial.amount)),
|
||||||
|
('matched_account_ids', '=ilike', f'%{signature_account}%'),
|
||||||
|
('source', '=', 'backfill'),
|
||||||
|
], limit=1)
|
||||||
|
if existing:
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
statement_line = Line.browse(bsl_id)
|
||||||
|
try:
|
||||||
|
currency = (partial.debit_currency_id
|
||||||
|
or partial.company_id.currency_id)
|
||||||
|
Precedent.create({
|
||||||
|
'company_id': partial.company_id.id,
|
||||||
|
'partner_id': (counterpart.partner_id.id
|
||||||
|
if counterpart.partner_id else False),
|
||||||
|
'amount': abs(partial.amount),
|
||||||
|
'currency_id': currency.id,
|
||||||
|
'date': statement_line.date or partial.create_date.date(),
|
||||||
|
'memo_tokens': ','.join(
|
||||||
|
tokenize_memo(statement_line.payment_ref or '')),
|
||||||
|
'journal_id': statement_line.journal_id.id,
|
||||||
|
'matched_move_line_count': 1,
|
||||||
|
'matched_account_ids': signature_account,
|
||||||
|
'reconciler_user_id': partial.create_uid.id,
|
||||||
|
'reconciled_at': partial.create_date,
|
||||||
|
'source': 'backfill',
|
||||||
|
})
|
||||||
|
created += 1
|
||||||
|
if created % batch_size == 0:
|
||||||
|
if not in_test_mode:
|
||||||
|
env.cr.commit()
|
||||||
|
_logger.info(
|
||||||
|
"Backfill progress: %d created, %d skipped",
|
||||||
|
created, skipped)
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
_logger.warning("Backfill skip partial %s: %s", partial.id, e)
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
_logger.info(
|
||||||
|
"precedent_backfill complete: %d created, %d skipped",
|
||||||
|
created, skipped)
|
||||||
|
return {'created': created, 'skipped': skipped}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class AiAlternativesPanel extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.AiAlternativesPanel";
|
||||||
|
static props = {
|
||||||
|
suggestions: { type: Array },
|
||||||
|
onClose: { type: Function, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
}
|
||||||
|
|
||||||
|
bandFor(c) {
|
||||||
|
if (c >= 0.85) return "high";
|
||||||
|
if (c >= 0.6) return "medium";
|
||||||
|
if (c > 0) return "low";
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
pctFor(c) {
|
||||||
|
return Math.round(c * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onAccept(suggestionId) {
|
||||||
|
await this.bankRec.acceptSuggestion(suggestionId);
|
||||||
|
if (this.props.onClose) {
|
||||||
|
this.props.onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.AiAlternativesPanel">
|
||||||
|
<div class="o_fusion_alternatives_panel">
|
||||||
|
<h6>Other AI suggestions</h6>
|
||||||
|
<div t-foreach="props.suggestions" t-as="sug" t-key="sug.id"
|
||||||
|
class="o_fusion_alternative">
|
||||||
|
<div>
|
||||||
|
<span class="alt_confidence" t-att-class="'band-' + bandFor(sug.confidence)">
|
||||||
|
<t t-esc="pctFor(sug.confidence)"/>%
|
||||||
|
</span>
|
||||||
|
<t t-esc="sug.reasoning"/>
|
||||||
|
</div>
|
||||||
|
<button class="btn_fusion" t-on-click="() => onAccept(sug.id)">
|
||||||
|
Use this
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div t-if="props.onClose" class="text-end mt-2">
|
||||||
|
<button class="btn_fusion" t-on-click="props.onClose">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
|
||||||
|
export class AiReasoningTooltip extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.AiReasoningTooltip";
|
||||||
|
static props = {
|
||||||
|
scores: { type: Object },
|
||||||
|
reasoning: { type: String, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
pctFor(value) {
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
return (value * 100).toFixed(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.AiReasoningTooltip">
|
||||||
|
<div class="o_fusion_reasoning_tooltip" style="font-size: 0.85em; padding: 0.5rem;">
|
||||||
|
<div t-if="props.reasoning" class="mb-2">
|
||||||
|
<em><t t-esc="props.reasoning"/></em>
|
||||||
|
</div>
|
||||||
|
<div class="text-muted">
|
||||||
|
<div>Amount match: <t t-esc="pctFor(props.scores.amount_match)"/>%</div>
|
||||||
|
<div>Partner pattern: <t t-esc="pctFor(props.scores.partner_pattern)"/>%</div>
|
||||||
|
<div>Precedent similarity: <t t-esc="pctFor(props.scores.precedent_similarity)"/>%</div>
|
||||||
|
<div t-if="props.scores.ai_rerank">
|
||||||
|
AI re-rank: <t t-esc="pctFor(props.scores.ai_rerank)"/>%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class AiSuggestionStrip extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.AiSuggestionStrip";
|
||||||
|
static props = {
|
||||||
|
suggestion: { type: Object },
|
||||||
|
showAlternatives: { type: Function, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
}
|
||||||
|
|
||||||
|
get band() {
|
||||||
|
const c = this.props.suggestion.confidence;
|
||||||
|
if (c >= 0.85) return "high";
|
||||||
|
if (c >= 0.6) return "medium";
|
||||||
|
if (c > 0) return "low";
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
get confidencePct() {
|
||||||
|
return Math.round(this.props.suggestion.confidence * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onAccept() {
|
||||||
|
await this.bankRec.acceptSuggestion(this.props.suggestion.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
onShowAlternatives() {
|
||||||
|
if (this.props.showAlternatives) {
|
||||||
|
this.props.showAlternatives();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.AiSuggestionStrip">
|
||||||
|
<div class="o_fusion_ai_suggestion" t-att-data-band="band">
|
||||||
|
<div class="o_fusion_confidence_badge">
|
||||||
|
<t t-esc="confidencePct"/>%
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_suggestion_text">
|
||||||
|
<div class="o_fusion_reasoning">
|
||||||
|
<t t-esc="props.suggestion.reasoning || 'AI suggested match'"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_suggestion_actions">
|
||||||
|
<button class="btn_fusion btn_fusion_primary" t-on-click="onAccept">
|
||||||
|
Accept
|
||||||
|
</button>
|
||||||
|
<button t-if="props.showAlternatives" class="btn_fusion"
|
||||||
|
t-on-click="onShowAlternatives">
|
||||||
|
Other options
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../apply_amount/apply_amount.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { standardFieldProps } from "@web/views/fields/standard_field_props";
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
class BankRecWidgetApplyAmountHtmlField extends Component {
|
||||||
|
static props = standardFieldProps;
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecWidgetApplyAmountHtmlField";
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.action = useService("action");
|
||||||
|
this.orm = useService("orm");
|
||||||
|
}
|
||||||
|
|
||||||
|
get value() {
|
||||||
|
return this.props.record.data[this.props.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
async switchApplyAmount(ev) {
|
||||||
|
const root = this.env.model.root;
|
||||||
|
const fetchReconciledLines = async (fields = []) => {
|
||||||
|
return await this.orm.searchRead(
|
||||||
|
"account.move.line",
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"id",
|
||||||
|
"in",
|
||||||
|
...root.data.reconciled_lines_excluding_exchange_diff_ids._currentIds,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
fields
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchStatementLines = async (fields = []) => {
|
||||||
|
return await this.orm.searchRead(
|
||||||
|
"account.move.line",
|
||||||
|
[["move_id", "=", root.data.move_id.id]],
|
||||||
|
fields
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ev.target.attributes.name?.value === "action_redirect_to_move") {
|
||||||
|
const [line] = await fetchReconciledLines(["amount_currency", "balance", "move_id"]);
|
||||||
|
await this.openMove(line.move_id[0]);
|
||||||
|
} else if (ev.target.attributes.name?.value === "apply_full_amount") {
|
||||||
|
const [line] = await fetchReconciledLines(["amount_currency", "balance"]);
|
||||||
|
await root.update({
|
||||||
|
balance: -line.balance,
|
||||||
|
amount_currency: -line.amount_currency,
|
||||||
|
});
|
||||||
|
} else if (ev.target.attributes.name?.value === "apply_partial_amount") {
|
||||||
|
const lines = await fetchStatementLines(["amount_currency", "balance"]);
|
||||||
|
// We have all the lines of the entry, we want the suspense line.
|
||||||
|
await root.update({
|
||||||
|
balance: lines.at(-1).balance,
|
||||||
|
amount_currency: lines.at(-1).amount_currency,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openMove(moveId) {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "account.move",
|
||||||
|
res_id: moveId,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fusionBankRecWidgetApplyAmountHtmlField = { component: BankRecWidgetApplyAmountHtmlField };
|
||||||
|
|
||||||
|
registry.category("fields").add("fusion_apply_amount_html", fusionBankRecWidgetApplyAmountHtmlField);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecWidgetApplyAmountHtmlField">
|
||||||
|
<div t-out="value" t-on-click="switchApplyAmount"/>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
|
||||||
|
export class AttachmentStrip extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.AttachmentStrip";
|
||||||
|
static props = {
|
||||||
|
attachments: { type: Array },
|
||||||
|
};
|
||||||
|
|
||||||
|
iconFor(mimetype) {
|
||||||
|
if (!mimetype) {
|
||||||
|
return "fa-file";
|
||||||
|
}
|
||||||
|
if (mimetype.startsWith("image/")) {
|
||||||
|
return "fa-file-image-o";
|
||||||
|
}
|
||||||
|
if (mimetype === "application/pdf") {
|
||||||
|
return "fa-file-pdf-o";
|
||||||
|
}
|
||||||
|
return "fa-file-o";
|
||||||
|
}
|
||||||
|
|
||||||
|
urlFor(att) {
|
||||||
|
return `/web/content/${att.id}?download=true`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.AttachmentStrip">
|
||||||
|
<div class="o_fusion_attachment_strip d-flex flex-wrap"
|
||||||
|
style="gap: 0.5rem; padding: 0.5rem;">
|
||||||
|
<div t-if="props.attachments.length === 0" class="text-muted small">
|
||||||
|
No attachments
|
||||||
|
</div>
|
||||||
|
<a t-foreach="props.attachments" t-as="att" t-key="att.id"
|
||||||
|
t-att-href="urlFor(att)" target="_blank"
|
||||||
|
class="o_fusion_attachment_chip"
|
||||||
|
style="display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.5rem; background: #f3f4f6; border-radius: 0.25rem; text-decoration: none; color: inherit; font-size: 0.85em;">
|
||||||
|
<i class="fa" t-att-class="iconFor(att.mimetype)"/>
|
||||||
|
<span><t t-esc="att.name"/></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-export shim so mirrored Enterprise components can use the relative
|
||||||
|
* import `../bank_reconciliation_service` unchanged. The real
|
||||||
|
* implementation lives in
|
||||||
|
* `@fusion_accounting_bank_rec/services/bank_reconciliation_service`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export {
|
||||||
|
BankReconciliationService,
|
||||||
|
bankReconciliationService,
|
||||||
|
useBankReconciliation,
|
||||||
|
} from "@fusion_accounting_bank_rec/services/bank_reconciliation_service";
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../bankrec_form_dialog/bankrec_form_dialog.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FormController } from "@web/views/form/form_controller";
|
||||||
|
import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog";
|
||||||
|
import { formView } from "@web/views/form/form_view";
|
||||||
|
import { onWillStart } from "@odoo/owl";
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { user } from "@web/core/user";
|
||||||
|
|
||||||
|
export class BankRecFormDialog extends FormViewDialog {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
Object.assign(this.viewProps, {
|
||||||
|
buttonTemplate: "fusion_accounting_bank_rec.BankRecFormDialog.buttons",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BankRecEditLineFormController extends FormController {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.isReviewed = this.props.context.is_reviewed;
|
||||||
|
onWillStart(async () => {
|
||||||
|
this.userCanReview = await user.hasGroup("account.group_account_user");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async toReviewButtonClicked(params = {}) {
|
||||||
|
await this.orm.call("account.move", "set_moves_checked", [
|
||||||
|
this.model.root.data.move_id.id,
|
||||||
|
false,
|
||||||
|
]);
|
||||||
|
return this.saveButtonClicked(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const bankRecEditLineFormController = {
|
||||||
|
...formView,
|
||||||
|
Controller: BankRecEditLineFormController,
|
||||||
|
};
|
||||||
|
|
||||||
|
registry.category("views").add("fusion_bankrec_edit_line", bankRecEditLineFormController);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecFormDialog.buttons" t-inherit="web.FormViewDialog.ToOne.buttons" t-inherit-mode="primary">
|
||||||
|
<xpath expr="//button[hasclass('o_form_button_save')]" position="after">
|
||||||
|
<button
|
||||||
|
t-if="userCanReview and this.isReviewed"
|
||||||
|
class="btn btn-info"
|
||||||
|
t-on-click.stop="() => this.toReviewButtonClicked({closable: true})"
|
||||||
|
data-hotkey="q">
|
||||||
|
<span>To Review</span>
|
||||||
|
</button>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class BatchActionBar extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BatchActionBar";
|
||||||
|
static props = {
|
||||||
|
selectedIds: { type: Array, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasSelection() {
|
||||||
|
return this.props.selectedIds && this.props.selectedIds.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectionCount() {
|
||||||
|
return this.props.selectedIds ? this.props.selectedIds.length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async onAutoReconcile() {
|
||||||
|
if (!this.hasSelection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.bankRec.bulkReconcile(this.props.selectedIds, "auto");
|
||||||
|
}
|
||||||
|
|
||||||
|
async onSuggestForSelected() {
|
||||||
|
if (!this.hasSelection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.bankRec.suggestMatches(this.props.selectedIds, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BatchActionBar">
|
||||||
|
<div class="o_fusion_batch_action_bar d-flex"
|
||||||
|
style="gap: 0.5rem; padding: 0.75rem; background: #f3f4f6; border-radius: 0.375rem;">
|
||||||
|
<span class="text-muted">
|
||||||
|
<t t-esc="selectionCount"/> selected
|
||||||
|
</span>
|
||||||
|
<button class="btn_fusion" t-att-disabled="!hasSelection" t-on-click="onSuggestForSelected">
|
||||||
|
Suggest for selected
|
||||||
|
</button>
|
||||||
|
<button class="btn_fusion btn_fusion_primary" t-att-disabled="!hasSelection" t-on-click="onAutoReconcile">
|
||||||
|
Auto-reconcile selected
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../button/button.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class BankRecButton extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecButton";
|
||||||
|
static props = {
|
||||||
|
label: { type: String, optional: true },
|
||||||
|
action: { type: Function, optional: true },
|
||||||
|
count: { type: [Number, { value: null }], optional: true },
|
||||||
|
primary: { type: Boolean, optional: true },
|
||||||
|
toReview: { type: Boolean, optional: true },
|
||||||
|
classes: { type: String, optional: true },
|
||||||
|
};
|
||||||
|
static defaultProps = {
|
||||||
|
primary: false,
|
||||||
|
classes: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.ui = useService("ui");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecButton">
|
||||||
|
<button
|
||||||
|
t-attf-class="d-flex gap-1 btn text-nowrap {{ props.classes }}"
|
||||||
|
t-att-class="{'btn-sm': !ui.isSmall, 'btn-primary': props.primary, 'btn-info': props.toReview, 'btn-secondary': !props.primary}"
|
||||||
|
t-on-click.stop="() => props?.action()"
|
||||||
|
>
|
||||||
|
<span t-esc="props?.label" class="m-auto text-truncate"/>
|
||||||
|
<span class="rounded-pill px-2 o_bg-black-10" t-if="props?.count">
|
||||||
|
<t t-esc="props.count"/>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,603 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../button_list/button_list.js`.
|
||||||
|
* Phase 1 structural parity. Behaviour delegates to the
|
||||||
|
* Enterprise-compat surface in our `fusion_bank_reconciliation` service.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { BankRecButton } from "@fusion_accounting_bank_rec/components/bank_reconciliation/button/button";
|
||||||
|
import { BankRecFileUploader } from "@fusion_accounting_bank_rec/components/bank_reconciliation/file_uploader/file_uploader";
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
|
||||||
|
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||||
|
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||||
|
import { SelectCreateDialog } from "@web/views/view_dialogs/select_create_dialog";
|
||||||
|
import { BankRecSelectCreateDialog } from "@fusion_accounting_bank_rec/components/bank_reconciliation/search_dialog/search_dialog";
|
||||||
|
import { _t } from "@web/core/l10n/translation";
|
||||||
|
import { getCurrency } from "@web/core/currency";
|
||||||
|
import { useOwnedDialogs, useService } from "@web/core/utils/hooks";
|
||||||
|
import { useBankReconciliation } from "@fusion_accounting_bank_rec/components/bank_reconciliation/bank_reconciliation_service";
|
||||||
|
import { useHotkey } from "@web/core/hotkeys/hotkey_hook";
|
||||||
|
|
||||||
|
export class BankRecButtonList extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecButtonList";
|
||||||
|
static components = {
|
||||||
|
Dropdown,
|
||||||
|
DropdownItem,
|
||||||
|
BankRecButton,
|
||||||
|
BankRecFileUploader,
|
||||||
|
};
|
||||||
|
static props = {
|
||||||
|
statementLineRootRef: { type: Object },
|
||||||
|
statementLine: { type: Object },
|
||||||
|
suspenseAccountLine: { type: Object, optional: true },
|
||||||
|
reconcileLineCount: { type: [Number, { value: null }], optional: true },
|
||||||
|
reconcileModels: Array,
|
||||||
|
preSelectedReconciliationModel: { type: Object, optional: true },
|
||||||
|
};
|
||||||
|
static defaultProps = {
|
||||||
|
reconcileLineCount: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.action = useService("action");
|
||||||
|
this.ui = useService("ui");
|
||||||
|
this.orm = useService("orm");
|
||||||
|
|
||||||
|
this.addDialog = useOwnedDialogs();
|
||||||
|
this.currencyDigits = getCurrency(this.statementLineData.currency_id.id)?.digits || 2;
|
||||||
|
this.bankReconciliation = useBankReconciliation();
|
||||||
|
|
||||||
|
this.registerHotkeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreFocus() {
|
||||||
|
if (this.isLineSelected) {
|
||||||
|
this.props.statementLineRootRef.el.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a search dialog (no create option) for selecting a `res.partner` record.
|
||||||
|
*/
|
||||||
|
setPartnerOnReconcileLine() {
|
||||||
|
this.addDialog(
|
||||||
|
SelectCreateDialog,
|
||||||
|
{
|
||||||
|
title: _t("Search: Partner"),
|
||||||
|
noCreate: false,
|
||||||
|
multiSelect: false,
|
||||||
|
resModel: "res.partner",
|
||||||
|
context: { default_name: this.statementLineData.partner_name },
|
||||||
|
onSelected: async (partner) => {
|
||||||
|
await this.orm.call(
|
||||||
|
"account.bank.statement.line",
|
||||||
|
"set_partner_bank_statement_line",
|
||||||
|
[this.statementLineData.id, partner[0]]
|
||||||
|
);
|
||||||
|
const recordsToLoad = [];
|
||||||
|
if (this.statementLineData.partner_name) {
|
||||||
|
// Reload all impacted statement lines if we have a partner_name
|
||||||
|
recordsToLoad.push(
|
||||||
|
...this.env.model.root.records.filter(
|
||||||
|
(record) =>
|
||||||
|
record.data.partner_name === this.statementLineData.partner_name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
recordsToLoad.push(this.props.statementLine);
|
||||||
|
}
|
||||||
|
await this.bankReconciliation.reloadRecords(recordsToLoad);
|
||||||
|
await this.bankReconciliation.computeReconcileLineCountPerPartnerId(
|
||||||
|
this.env.model.root.records
|
||||||
|
);
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onClose: () => {
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a dialog to select an account and assigns it to the current reconcile line.
|
||||||
|
*/
|
||||||
|
setAccountOnReconcileLine() {
|
||||||
|
const context = {
|
||||||
|
list_view_ref: "account_accountant.view_account_list_bank_rec_widget",
|
||||||
|
search_view_ref: "account_accountant.view_account_search_bank_rec_widget",
|
||||||
|
...(this.statementLineData.amount > 0
|
||||||
|
? { preferred_account_type: "income" }
|
||||||
|
: { preferred_account_type: "expense" }),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addDialog(
|
||||||
|
SelectCreateDialog,
|
||||||
|
{
|
||||||
|
title: _t("Search: Account"),
|
||||||
|
noCreate: true,
|
||||||
|
multiSelect: false,
|
||||||
|
domain: [
|
||||||
|
[
|
||||||
|
"id",
|
||||||
|
"not in",
|
||||||
|
[
|
||||||
|
this.statementLineData.journal_id.suspense_account_id.id,
|
||||||
|
this.statementLineData.journal_id.default_account_id.id,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
context: context,
|
||||||
|
resModel: "account.account",
|
||||||
|
onSelected: async (account) => {
|
||||||
|
const linesToLoad = await this._setAccountOnReconcileLine(
|
||||||
|
this.lastAccountMoveLine.data.id,
|
||||||
|
account[0],
|
||||||
|
{ context: { account_default_taxes: true } }
|
||||||
|
);
|
||||||
|
const recordsToLoad = [
|
||||||
|
...this.env.model.root.records.filter((record) =>
|
||||||
|
linesToLoad.includes(record.data.id)
|
||||||
|
),
|
||||||
|
this.props.statementLine,
|
||||||
|
];
|
||||||
|
await this.bankReconciliation.reloadRecords(recordsToLoad);
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onClose: () => {
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _setAccountOnReconcileLine(amlId, accountId, context = {}) {
|
||||||
|
return await this.orm.call(
|
||||||
|
"account.bank.statement.line",
|
||||||
|
"set_account_bank_statement_line",
|
||||||
|
[this.statementLineData.id, amlId, accountId],
|
||||||
|
context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async setAccountReceivableOnReconcileLine() {
|
||||||
|
let accountId;
|
||||||
|
if (this.statementLineData.partner_id.property_account_receivable_id.id) {
|
||||||
|
accountId = this.statementLineData.partner_id.property_account_receivable_id.id;
|
||||||
|
} else {
|
||||||
|
accountId = await this.orm.webSearchRead("account.account", [
|
||||||
|
["account_type", "=", "asset_receivable"],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
await this._setAccountOnReconcileLine(this.lastAccountMoveLine.data.id, accountId);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
async setAccountPayableOnReconcileLine() {
|
||||||
|
let accountId;
|
||||||
|
if (this.statementLineData.partner_id.property_account_payable_id.id) {
|
||||||
|
accountId = this.statementLineData.partner_id.property_account_payable_id.id;
|
||||||
|
} else {
|
||||||
|
accountId = await this.orm.webSearchRead("account.account", [
|
||||||
|
["account_type", "=", "liability_payable"],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
await this._setAccountOnReconcileLine(this.lastAccountMoveLine.data.id, accountId);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a dialog to search and select journal items to reconcile with the current bank statement line.
|
||||||
|
*/
|
||||||
|
reconcileOnReconcileLine() {
|
||||||
|
const context = {
|
||||||
|
list_view_ref: "account_accountant.view_account_move_line_list_bank_rec_widget",
|
||||||
|
search_view_ref: "account_accountant.view_account_move_line_search_bank_rec_widget",
|
||||||
|
preferred_aml_value: -this.props.suspenseAccountLine.amount_currency,
|
||||||
|
preferred_aml_currency_id: this.props.suspenseAccountLine.currency_id.id,
|
||||||
|
...(this.statementLineData.partner_id
|
||||||
|
? { search_default_partner_id: this.statementLineData.partner_id.id }
|
||||||
|
: { search_default_posted: 1 }),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addDialog(
|
||||||
|
BankRecSelectCreateDialog,
|
||||||
|
{
|
||||||
|
title: _t("Search: Journal Items to Match"),
|
||||||
|
noCreate: true,
|
||||||
|
domain: this.getReconcileButtonDomain(),
|
||||||
|
resModel: "account.move.line",
|
||||||
|
size: "xl",
|
||||||
|
context: context,
|
||||||
|
onSelected: async (moveLines) => {
|
||||||
|
await this.orm.call(
|
||||||
|
"account.bank.statement.line",
|
||||||
|
"set_line_bank_statement_line",
|
||||||
|
[this.statementLineData.id, moveLines]
|
||||||
|
);
|
||||||
|
await this.bankReconciliation.computeReconcileLineCountPerPartnerId(
|
||||||
|
this.env.model.root.records
|
||||||
|
);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
suspenseAccountLine: this.props.suspenseAccountLine,
|
||||||
|
reference: this.statementLineData.payment_ref,
|
||||||
|
date: this.statementLineData.date,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onClose: () => {
|
||||||
|
this.restoreFocus();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getReconcileButtonDomain() {
|
||||||
|
return [
|
||||||
|
["parent_state", "in", ["draft", "posted"]],
|
||||||
|
["company_id", "child_of", this.statementLineData.company_id.id],
|
||||||
|
["search_account_id.reconcile", "=", true],
|
||||||
|
["display_type", "not in", ["line_section", "line_note"]],
|
||||||
|
["reconciled", "=", false],
|
||||||
|
"|",
|
||||||
|
["search_account_id.account_type", "not in", ["asset_receivable", "liability_payable"]],
|
||||||
|
["payment_id", "=", false],
|
||||||
|
["statement_line_id", "!=", this.statementLineData.id],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the current bank statement line.
|
||||||
|
*/
|
||||||
|
async deleteTransaction() {
|
||||||
|
this.addDialog(ConfirmationDialog, {
|
||||||
|
body: _t("Are you sure you want to delete this statement line?"),
|
||||||
|
confirm: async () => {
|
||||||
|
await this.orm.unlink("account.bank.statement.line", [this.statementLineData.id]);
|
||||||
|
this.env.model.load();
|
||||||
|
},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the move of the statement line as to check
|
||||||
|
*/
|
||||||
|
async setStatementLineAsReviewed() {
|
||||||
|
await this.orm.call("account.move", "set_moves_checked", [
|
||||||
|
this.statementLineData.move_id.id,
|
||||||
|
]);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Reconciliation Model
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
async triggerReconciliationModel(reconciliationModelId) {
|
||||||
|
await this.orm.call("account.reconcile.model", "trigger_reconciliation_model", [
|
||||||
|
reconciliationModelId,
|
||||||
|
this.statementLineData.id,
|
||||||
|
]);
|
||||||
|
await this.bankReconciliation.computeReconcileLineCountPerPartnerId(
|
||||||
|
this.env.model.root.records
|
||||||
|
);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
getKeyAction(key) {
|
||||||
|
const keyActions = {
|
||||||
|
1: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".set-partner-btn") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: async () => this.setPartnerOnReconcileLine(),
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(".set-partner-btn"),
|
||||||
|
},
|
||||||
|
2: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".reconcile-btn") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: async () => this.reconcileOnReconcileLine(),
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(".reconcile-btn"),
|
||||||
|
},
|
||||||
|
3: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".set-account-btn") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: () => this.setAccountOnReconcileLine(),
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(".set-account-btn"),
|
||||||
|
},
|
||||||
|
4: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".set-payable-btn") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: () => this.setAccountPayableOnReconcileLine(),
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(".set-payable-btn"),
|
||||||
|
},
|
||||||
|
5: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".set-receivable-btn") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: () => this.setAccountReceivableOnReconcileLine(),
|
||||||
|
buttonElement:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".set-receivable-btn"),
|
||||||
|
},
|
||||||
|
6: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-0"
|
||||||
|
) && this.isLineSelected,
|
||||||
|
action: () => {
|
||||||
|
const buttonElement = this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-0"
|
||||||
|
);
|
||||||
|
if (buttonElement) {
|
||||||
|
buttonElement.click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-0"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
7: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-1"
|
||||||
|
) && this.isLineSelected,
|
||||||
|
action: () => {
|
||||||
|
const buttonElement = this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-1"
|
||||||
|
);
|
||||||
|
if (buttonElement) {
|
||||||
|
buttonElement.click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-1"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
8: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-2"
|
||||||
|
) && this.isLineSelected,
|
||||||
|
action: () => {
|
||||||
|
const buttonElement = this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-2"
|
||||||
|
);
|
||||||
|
if (buttonElement) {
|
||||||
|
buttonElement.click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(
|
||||||
|
".reconciliation-model-btn-2"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
Enter: {
|
||||||
|
condition:
|
||||||
|
this.props.statementLineRootRef.el.querySelector(".btn-primary") &&
|
||||||
|
this.isLineSelected,
|
||||||
|
action: () => {
|
||||||
|
const primaryButtons =
|
||||||
|
this.props.statementLineRootRef.el.querySelectorAll(".btn-primary");
|
||||||
|
if (primaryButtons.length > 0) {
|
||||||
|
primaryButtons[0].click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonElement: this.props.statementLineRootRef.el.querySelector(".btn-primary"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return keyActions[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
registerHotkeys() {
|
||||||
|
const hotkeyConfigs = [
|
||||||
|
{ key: "1", trigger: "alt+shift+1" },
|
||||||
|
{ key: "2", trigger: "alt+shift+2" },
|
||||||
|
{ key: "3", trigger: "alt+shift+3" },
|
||||||
|
{ key: "4", trigger: "alt+shift+4" },
|
||||||
|
{ key: "5", trigger: "alt+shift+5" },
|
||||||
|
{ key: "6", trigger: "alt+shift+6" },
|
||||||
|
{ key: "7", trigger: "alt+shift+7" },
|
||||||
|
{ key: "8", trigger: "alt+shift+8" },
|
||||||
|
{ key: "Enter", trigger: "alt+shift+enter" },
|
||||||
|
];
|
||||||
|
hotkeyConfigs.forEach(({ key, trigger }) => {
|
||||||
|
useHotkey(
|
||||||
|
trigger,
|
||||||
|
({ target }) => {
|
||||||
|
const { condition, action } = this.getKeyAction(key);
|
||||||
|
if (condition) {
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
area: () => this.props.statementLineRootRef.el.parentElement,
|
||||||
|
withOverlay: () => {
|
||||||
|
const { buttonElement, condition } = this.getKeyAction(key);
|
||||||
|
return condition ? buttonElement : null;
|
||||||
|
},
|
||||||
|
isAvailable: () => {
|
||||||
|
const { condition } = this.getKeyAction(key);
|
||||||
|
return condition;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File Uploader
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
get bankRecFileUploaderRecord() {
|
||||||
|
return {
|
||||||
|
statementLineId: this.statementLineData.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// ACTION
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
actionViewRecoModels() {
|
||||||
|
return this.action.doAction("account.action_account_reconcile_model");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// GETTER
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
get statementLineData() {
|
||||||
|
return this.props.statementLine.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLineSelected() {
|
||||||
|
return this.statementLineData.id === this.bankReconciliation.statementLine?.data.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get lastAccountMoveLine() {
|
||||||
|
return this.statementLineData.line_ids.records.at(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isCustomerRankHigher() {
|
||||||
|
return (
|
||||||
|
this.statementLineData.partner_id.customer_rank >
|
||||||
|
this.statementLineData.partner_id.supplier_rank
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSetPartnerButtonShown() {
|
||||||
|
return !this.statementLineData.partner_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSetAccountButtonShown() {
|
||||||
|
return !this.statementLineData.account_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSetReceivableButtonShown() {
|
||||||
|
return (
|
||||||
|
!this.isSetPartnerButtonShown &&
|
||||||
|
((this.statementLineData.partner_id.customer_rank && this.isCustomerRankHigher) ||
|
||||||
|
this.statementLineData.amount > 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSetPayableButtonShown() {
|
||||||
|
return (
|
||||||
|
!this.isSetPartnerButtonShown &&
|
||||||
|
((this.statementLineData.partner_id.supplier_rank && !this.isCustomerRankHigher) ||
|
||||||
|
this.statementLineData.amount < 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isReconcileButtonShown() {
|
||||||
|
return this.props.reconcileLineCount === null || this.props.reconcileLineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
get reconcileModelsInDropdown() {
|
||||||
|
if (this.ui.isSmall) {
|
||||||
|
return this.props.reconcileModels;
|
||||||
|
}
|
||||||
|
return this.props.reconcileModels.filter(
|
||||||
|
(model) => model.id !== this.props?.preSelectedReconciliationModel?.id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get buttons() {
|
||||||
|
const buttonsToDisplay = {};
|
||||||
|
if (this.isSetPartnerButtonShown) {
|
||||||
|
buttonsToDisplay.partner = {
|
||||||
|
label: _t("Set Partner"),
|
||||||
|
action: this.setPartnerOnReconcileLine.bind(this),
|
||||||
|
classes: "set-partner-btn",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
buttonsToDisplay.receivable = {
|
||||||
|
label: _t("Receivable"),
|
||||||
|
action: this.setAccountReceivableOnReconcileLine.bind(this),
|
||||||
|
classes: "set-receivable-btn",
|
||||||
|
};
|
||||||
|
buttonsToDisplay.payable = {
|
||||||
|
label: _t("Payable"),
|
||||||
|
action: this.setAccountPayableOnReconcileLine.bind(this),
|
||||||
|
classes: "set-payable-btn",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isReconcileButtonShown) {
|
||||||
|
buttonsToDisplay.reconcile = {
|
||||||
|
label: _t("Reconcile"),
|
||||||
|
action: this.reconcileOnReconcileLine.bind(this),
|
||||||
|
count: this.props.reconcileLineCount,
|
||||||
|
classes: "reconcile-btn",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isSetAccountButtonShown) {
|
||||||
|
buttonsToDisplay.account = {
|
||||||
|
label: _t("Set Account"),
|
||||||
|
action: this.setAccountOnReconcileLine.bind(this),
|
||||||
|
classes: "set-account-btn",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.statementLineData.is_reconciled && !this.statementLineData.checked) {
|
||||||
|
buttonsToDisplay.toReview = {
|
||||||
|
label: _t("Reviewed"),
|
||||||
|
action: this.setStatementLineAsReviewed.bind(this),
|
||||||
|
toReview: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttonsToDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
get buttonsToDisplay() {
|
||||||
|
const buttons = this.buttons || {};
|
||||||
|
|
||||||
|
let primaryButtonKeys = [];
|
||||||
|
let secondaryButtonKeys = [];
|
||||||
|
if (buttons?.partner && buttons?.account) {
|
||||||
|
primaryButtonKeys = ["partner", "account"];
|
||||||
|
} else if (buttons?.reconcile && !!buttons.reconcile?.count) {
|
||||||
|
primaryButtonKeys = ["reconcile"];
|
||||||
|
if (this.isSetReceivableButtonShown) {
|
||||||
|
secondaryButtonKeys = ["receivable"];
|
||||||
|
} else {
|
||||||
|
secondaryButtonKeys = ["payable"];
|
||||||
|
}
|
||||||
|
} else if (this.isSetReceivableButtonShown) {
|
||||||
|
primaryButtonKeys = ["receivable"];
|
||||||
|
} else if (this.isSetPayableButtonShown) {
|
||||||
|
primaryButtonKeys = ["payable"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
...primaryButtonKeys.map((key) => ({ ...buttons[key], primary: true })),
|
||||||
|
...secondaryButtonKeys.map((key) => ({ ...buttons[key] })),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get buttonsInDropdown() {
|
||||||
|
const buttons = this.buttons || {};
|
||||||
|
if (this.props.preSelectedReconciliationModel) {
|
||||||
|
return Object.values(buttons);
|
||||||
|
}
|
||||||
|
const buttonToDisplayClasses = this.buttonsToDisplay.map((button) => button.classes) || [];
|
||||||
|
return Object.values(buttons).filter(
|
||||||
|
(button) => !buttonToDisplayClasses.includes(button.classes)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecButtonList">
|
||||||
|
<div class="d-flex flex-wrap gap-1">
|
||||||
|
<t t-if="props.preSelectedReconciliationModel and !statementLineData.is_reconciled">
|
||||||
|
<BankRecButton
|
||||||
|
label="props.preSelectedReconciliationModel.display_name"
|
||||||
|
primary="true"
|
||||||
|
action.bind="() => this.triggerReconciliationModel(props.preSelectedReconciliationModel.id)"
|
||||||
|
/>
|
||||||
|
</t>
|
||||||
|
<t t-elif="buttons?.toReview">
|
||||||
|
<BankRecButton t-props="buttons.toReview"/>
|
||||||
|
</t>
|
||||||
|
<t t-else="">
|
||||||
|
<t t-foreach="buttonsToDisplay" t-as="button" t-key="button_index">
|
||||||
|
<BankRecButton t-props="button"/>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
<Dropdown t-if="!statementLineData.is_reconciled">
|
||||||
|
<button class="btn btn-secondary" t-att-class="{'btn-sm': !ui.isSmall}">
|
||||||
|
<i class="oi oi-ellipsis-v"/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<t t-set-slot="content">
|
||||||
|
<t t-foreach="buttonsInDropdown" t-as="button" t-key="button_index">
|
||||||
|
<DropdownItem class="'btn btn-link'" onSelected.bind="button.action">
|
||||||
|
<t t-esc="button.label"/>
|
||||||
|
</DropdownItem>
|
||||||
|
</t>
|
||||||
|
<BankRecFileUploader record="bankRecFileUploaderRecord">
|
||||||
|
<t t-set-slot="toggler">
|
||||||
|
<span class="dropdown-item dropdown-item o-navigable btn btn-link">
|
||||||
|
Upload Bills
|
||||||
|
</span>
|
||||||
|
</t>
|
||||||
|
</BankRecFileUploader>
|
||||||
|
<div class="dropdown-divider"/>
|
||||||
|
<t t-foreach="reconcileModelsInDropdown" t-as="model" t-key="model.id">
|
||||||
|
<DropdownItem class="'btn btn-link'" onSelected.bind="() => this.triggerReconciliationModel(model.id)">
|
||||||
|
<t t-esc="model.display_name"/>
|
||||||
|
</DropdownItem>
|
||||||
|
</t>
|
||||||
|
<div t-if="reconcileModelsInDropdown.length" class="dropdown-divider"/>
|
||||||
|
<DropdownItem class="'btn btn-link'" onSelected.bind="actionViewRecoModels">
|
||||||
|
Manage Models
|
||||||
|
</DropdownItem>
|
||||||
|
<DropdownItem class="'btn btn-link'" onSelected.bind="deleteTransaction">
|
||||||
|
Delete Transaction
|
||||||
|
</DropdownItem>
|
||||||
|
</t>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../chatter/chatter.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Chatter } from "@mail/chatter/web_portal/chatter";
|
||||||
|
|
||||||
|
export class BankRecChatter extends Chatter {
|
||||||
|
static props = [...Chatter.props, "statementLine?"];
|
||||||
|
|
||||||
|
async reloadParentView() {
|
||||||
|
await this.props.statementLine?.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../file_uploader/file_uploader.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { DocumentFileUploader } from "@account/components/document_file_uploader/document_file_uploader";
|
||||||
|
|
||||||
|
export class BankRecFileUploader extends DocumentFileUploader {
|
||||||
|
/**
|
||||||
|
* Extends `DocumentFileUploader.getExtraContext` to add the
|
||||||
|
* `statement_line_id` to the context, used by
|
||||||
|
* `account.bank.statement.line.create_document_from_attachment` to link
|
||||||
|
* the uploaded bill back to the originating statement line.
|
||||||
|
*/
|
||||||
|
getExtraContext() {
|
||||||
|
const extraContext = super.getExtraContext();
|
||||||
|
return {
|
||||||
|
...extraContext,
|
||||||
|
statement_line_id: this.props.record.statementLineId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getResModel() {
|
||||||
|
return "account.bank.statement.line";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../line_info_pop_over/line_info_pop_over.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { formatMonetary } from "@web/views/fields/formatters";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class BankRecLineInfoPopOver extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecLineInfoPopOver";
|
||||||
|
static props = {
|
||||||
|
lineData: { type: Object, optional: true },
|
||||||
|
statementLineData: { type: Object, optional: true },
|
||||||
|
exchangeMove: { type: Object, optional: true },
|
||||||
|
isPartiallyReconciled: { type: Boolean, optional: true },
|
||||||
|
close: { type: Function, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.action = useService("action");
|
||||||
|
}
|
||||||
|
|
||||||
|
openExchangeMove() {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "account.move",
|
||||||
|
res_id: this.props.exchangeMove.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openReconciledMove() {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "account.move",
|
||||||
|
res_id: this.reconciledLineData.move_id.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get reconciledMoveName() {
|
||||||
|
return this.reconciledLineData.move_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedReconciledMoveAmountCurrency() {
|
||||||
|
return formatMonetary(this.reconciledLineData.amount_currency, {
|
||||||
|
currencyId: this.reconciledLineData.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get reconciledLineData() {
|
||||||
|
return this.props.lineData.reconciled_lines_ids.records[0].data;
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedLineDataAmountCurrency() {
|
||||||
|
return formatMonetary(this.props.lineData.amount_currency, {
|
||||||
|
currencyId: this.props.lineData.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get exchangeDiffMoveName() {
|
||||||
|
return this.props.exchangeMove.display_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get exchangeMoveBalance() {
|
||||||
|
return this.props.exchangeMove.line_ids[0].balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedExchangeMoveBalance() {
|
||||||
|
return formatMonetary(this.exchangeMoveBalance, {
|
||||||
|
currencyId: this.props.statementLineData.company_id.currency_id?.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecLineInfoPopOver">
|
||||||
|
<table class="table table-hover m-0">
|
||||||
|
<tbody>
|
||||||
|
<tr t-if="props.exchangeMove">
|
||||||
|
<td t-on-click="openExchangeMove" class="cursor-pointer">
|
||||||
|
<span class="btn btn-link p-0" t-esc="exchangeDiffMoveName"/>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle text-end" t-esc="formattedExchangeMoveBalance"/>
|
||||||
|
</tr>
|
||||||
|
<tr t-if="props.isPartiallyReconciled">
|
||||||
|
<td t-on-click="openReconciledMove" class="cursor-pointer">
|
||||||
|
<span class="btn btn-link p-0" t-esc="reconciledMoveName"/>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<span class="text-decoration-line-through me-2" t-esc="formattedReconciledMoveAmountCurrency"/>
|
||||||
|
<span t-esc="formattedLineDataAmountCurrency"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../line_to_reconcile/line_to_reconcile.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component, useRef } from "@odoo/owl";
|
||||||
|
import { _t } from "@web/core/l10n/translation";
|
||||||
|
import { formatMonetary } from "@web/views/fields/formatters";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { useBankReconciliation } from "@fusion_accounting_bank_rec/components/bank_reconciliation/bank_reconciliation_service";
|
||||||
|
import { usePopover } from "@web/core/popover/popover_hook";
|
||||||
|
import { BankRecFormDialog } from "@fusion_accounting_bank_rec/components/bank_reconciliation/bankrec_form_dialog/bankrec_form_dialog";
|
||||||
|
import { BankRecLineInfoPopOver } from "@fusion_accounting_bank_rec/components/bank_reconciliation/line_info_pop_over/line_info_pop_over";
|
||||||
|
import { x2ManyCommands } from "@web/core/orm_service";
|
||||||
|
|
||||||
|
export class BankRecLineToReconcile extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecLineToReconcile";
|
||||||
|
|
||||||
|
static props = {
|
||||||
|
line: Object,
|
||||||
|
statementLine: Object,
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.action = useService("action");
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.dialogService = useService("dialog");
|
||||||
|
this.ui = useService("ui");
|
||||||
|
this.bankReconciliation = useBankReconciliation();
|
||||||
|
|
||||||
|
this.lineInfoRef = useRef("line-info-ref");
|
||||||
|
this.lineInfoPopOver = usePopover(BankRecLineInfoPopOver, {
|
||||||
|
position: "left",
|
||||||
|
closeOnClickAway: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onClickLine() {
|
||||||
|
if (this.ui.isSmall) {
|
||||||
|
this.toggleEditLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleEditLine() {
|
||||||
|
this.dialogService.add(BankRecFormDialog, {
|
||||||
|
title: _t("Edit Line"),
|
||||||
|
resModel: "account.move.line",
|
||||||
|
resId: this.lineData.id,
|
||||||
|
context: {
|
||||||
|
form_view_ref: "account_accountant.view_bank_rec_edit_line",
|
||||||
|
is_reviewed: this.lineData.move_id.checked,
|
||||||
|
},
|
||||||
|
onRecordSave: async (record) => {
|
||||||
|
await this.orm.call("account.bank.statement.line", "edit_reconcile_line", [
|
||||||
|
this.statementLineData.id,
|
||||||
|
this.lineData.id,
|
||||||
|
await record.getChanges(),
|
||||||
|
]);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteLine() {
|
||||||
|
await this.orm.call("account.bank.statement.line", "delete_reconciled_line", [
|
||||||
|
this.statementLineData.id,
|
||||||
|
this.lineData.id,
|
||||||
|
]);
|
||||||
|
if (this.lineData.reconciled_lines_ids.records.length) {
|
||||||
|
// Only update the line count per partner if we delete
|
||||||
|
// a line which is reconciled to another move line
|
||||||
|
this.bankReconciliation.computeReconcileLineCountPerPartnerId(
|
||||||
|
this.env.model.root.records
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// ACTION
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
openMove() {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "account.move",
|
||||||
|
res_id: this.moveData.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openPartner() {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "res.partner",
|
||||||
|
res_id: this.lineData.partner_id.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openLineInfoPopOver() {
|
||||||
|
if (this.lineInfoPopOver.isOpen || !this.showLineInfo) {
|
||||||
|
this.lineInfoPopOver.close();
|
||||||
|
} else {
|
||||||
|
this.lineInfoPopOver.open(this.lineInfoRef.el, {
|
||||||
|
statementLineData: this.statementLineData,
|
||||||
|
lineData: this.lineData,
|
||||||
|
exchangeMove: this.exchangeMove,
|
||||||
|
isPartiallyReconciled: this.isPartiallyReconciled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteTax(taxIndex) {
|
||||||
|
const taxChanged = this.lineDataTaxIds[taxIndex];
|
||||||
|
await this.orm.call("account.bank.statement.line", "edit_reconcile_line", [
|
||||||
|
this.statementLineData.id,
|
||||||
|
this.lineData.id,
|
||||||
|
{ tax_ids: [[x2ManyCommands.UNLINK, taxChanged.data.id]] },
|
||||||
|
]);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// GETTER
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
get statementLineData() {
|
||||||
|
return this.props.statementLine.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
get lineData() {
|
||||||
|
return this.props.line;
|
||||||
|
}
|
||||||
|
|
||||||
|
get reconciledLineId() {
|
||||||
|
return this.lineData.reconciled_lines_ids.records.length === 1
|
||||||
|
? this.lineData.reconciled_lines_ids.records[0].data
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get reconciledLineExcludingExchangeDiffId() {
|
||||||
|
return this.lineData.reconciled_lines_excluding_exchange_diff_ids.records.length === 1
|
||||||
|
? this.lineData.reconciled_lines_excluding_exchange_diff_ids.records[0].data
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get moveData() {
|
||||||
|
return (
|
||||||
|
this.reconciledLineId?.move_id ||
|
||||||
|
this.reconciledLineExcludingExchangeDiffId?.move_id ||
|
||||||
|
this.lineData.move_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPartiallyReconciled() {
|
||||||
|
if (!this.reconciledLineId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !this.reconciledLineId.full_reconcile_id?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasDifferentCurrencies() {
|
||||||
|
return this.lineData.currency_id.id !== this.statementLineData.currency_id.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedAmountCurrencyOfLine() {
|
||||||
|
return formatMonetary(this.lineData.amount_currency, {
|
||||||
|
currencyId: this.lineData.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedAmountCurrencyOfStatementLine() {
|
||||||
|
return formatMonetary(this.lineData.amount_currency, {
|
||||||
|
currencyId: this.statementLineData.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get exchangeMove() {
|
||||||
|
return (
|
||||||
|
this.lineData.matched_debit_ids.records[0]?.data.exchange_move_id ||
|
||||||
|
this.lineData.matched_credit_ids.records[0]?.data.exchange_move_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get showLineInfo() {
|
||||||
|
return this.isPartiallyReconciled || this.exchangeMove?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isTaxLine() {
|
||||||
|
return this.lineData.tax_line_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get lineDataTaxIds() {
|
||||||
|
return this.lineData.tax_ids.records;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecLineToReconcile">
|
||||||
|
<div class="o_row" t-on-click.stop="onClickLine">
|
||||||
|
<div class="o_line_name d-flex align-items-center gap-1 text-truncate">
|
||||||
|
<a href="#" class="text-truncate fw-bold" t-esc="lineData.partner_id.display_name" t-on-click.stop="openPartner" role="button" t-att-title="lineData.partner_id.display_name" t-if="lineData.partner_id"/>
|
||||||
|
<span t-esc="lineData.account_id.display_name" class="text-truncate" t-att-class="lineData.partner_id ? 'ms-1' : undefined"/>
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<t t-foreach="lineDataTaxIds" t-as="tax_id" t-key="tax_id_index">
|
||||||
|
<div class="o_tag d-inline-flex align-items-center badge rounded-pill o_tag_color_0 flex-shrink-0">
|
||||||
|
<span class="o_tag_badge_text text-truncate" t-esc="tax_id.data.display_name"/>
|
||||||
|
<i t-on-click.stop="() => this.deleteTax(tax_id_index)" class="ps-1 opacity-100-hover opacity-75 oi oi-close"/>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span t-if="!!moveData.display_name and moveData.id !== statementLineData.move_id.id" class="d-none d-md-inline">
|
||||||
|
<a t-on-click.stop="openMove" href="#">
|
||||||
|
<t t-esc="moveData.display_name"/>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<div class="o_line_amount d-flex align-items-center justify-content-between">
|
||||||
|
<span class="text-muted w-50 text-end" t-if="hasDifferentCurrencies">
|
||||||
|
<span t-att-class="{'btn btn-link p-0' : showLineInfo}" t-ref="line-info-ref" t-on-click.stop="openLineInfoPopOver">
|
||||||
|
<i t-if="showLineInfo" class="fa fa-info-circle me-2"/>
|
||||||
|
<t t-out="formattedAmountCurrencyOfLine"/>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span class="text-end w-100" t-if="!hasDifferentCurrencies">
|
||||||
|
<span t-att-class="{'btn btn-link p-0' : showLineInfo}" t-ref="line-info-ref" t-on-click.stop="openLineInfoPopOver">
|
||||||
|
<i t-if="showLineInfo" class="fa fa-info-circle me-2"/>
|
||||||
|
<t t-out="formattedAmountCurrencyOfStatementLine"/>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="o_line_to_reconcile_button d-none d-md-flex justify-content-end gap-2">
|
||||||
|
<button t-if="lineData.has_invalid_analytics" class="btn btn-link p-0 text-600" t-on-click.stop="toggleEditLine">
|
||||||
|
<i class="fa fa-exclamation-triangle text-warning" data-tooltip="This line has invalid analytic distribution"/>
|
||||||
|
</button>
|
||||||
|
<button t-if="!lineData.has_invalid_analytics" class="btn btn-link p-0 text-600" t-on-click.stop="toggleEditLine">
|
||||||
|
<i class="fa fa-pencil"/>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-link p-0 text-600" t-on-click.stop="deleteLine" t-if="!isTaxLine">
|
||||||
|
<i class="fa fa-trash"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../list_view/list.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*
|
||||||
|
* NOTE: Enterprise extends `AttachmentPreviewListController` from
|
||||||
|
* `account_accountant/static/src/components/attachment_preview_list_view/...`.
|
||||||
|
* That helper isn't part of Phase 1 scope; we extend the base
|
||||||
|
* `ListController` directly and TODO-flag the methods that depend on
|
||||||
|
* the previewer state. Behaviour will be wired up in fusion-only
|
||||||
|
* Tasks 34-36 alongside the right-pane preview integration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ListController } from "@web/views/list/list_controller";
|
||||||
|
import { ListRenderer } from "@web/views/list/list_renderer";
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { listView } from "@web/views/list/list_view";
|
||||||
|
import { useChildSubEnv } from "@odoo/owl";
|
||||||
|
import { makeActiveField } from "@web/model/relational_model/utils";
|
||||||
|
|
||||||
|
export class BankRecListController extends ListController {
|
||||||
|
setup() {
|
||||||
|
super.setup(...arguments);
|
||||||
|
|
||||||
|
this.skipKanbanRestore = {};
|
||||||
|
|
||||||
|
useChildSubEnv({
|
||||||
|
skipKanbanRestoreNeeded: (stLineId) => this.skipKanbanRestore[stLineId],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't allow bank_rec_form to be restored with previous values since
|
||||||
|
* the statement line has changed.
|
||||||
|
*/
|
||||||
|
async onRecordSaved(record) {
|
||||||
|
this.skipKanbanRestore[record.resId] = true;
|
||||||
|
return super.onRecordSaved(...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
get previewerStorageKey() {
|
||||||
|
return "fusion.statement_line_pdf_previewer_hidden";
|
||||||
|
}
|
||||||
|
|
||||||
|
get modelParams() {
|
||||||
|
const params = super.modelParams;
|
||||||
|
params.config.activeFields.bank_statement_attachment_ids = makeActiveField();
|
||||||
|
params.config.activeFields.bank_statement_attachment_ids.related = {
|
||||||
|
fields: {
|
||||||
|
mimetype: { name: "mimetype", type: "char" },
|
||||||
|
},
|
||||||
|
activeFields: {
|
||||||
|
mimetype: makeActiveField(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
params.config.activeFields.attachment_ids = makeActiveField();
|
||||||
|
params.config.activeFields.attachment_ids.related = {
|
||||||
|
fields: {
|
||||||
|
mimetype: { name: "mimetype", type: "char" },
|
||||||
|
},
|
||||||
|
activeFields: {
|
||||||
|
mimetype: makeActiveField(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO(fusion task 34-36): wire up attachment preview pane.
|
||||||
|
* Enterprise sets `this.attachmentPreviewState.selectedRecord` and
|
||||||
|
* calls `this.setThread(...)` on the AttachmentPreviewListController.
|
||||||
|
* Until that helper is mirrored, this is a no-op.
|
||||||
|
*/
|
||||||
|
async setSelectedRecord(/* accountBankStatementLineData */) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BankRecListRenderer extends ListRenderer {}
|
||||||
|
|
||||||
|
export const bankRecListView = {
|
||||||
|
...listView,
|
||||||
|
Controller: BankRecListController,
|
||||||
|
Renderer: BankRecListRenderer,
|
||||||
|
};
|
||||||
|
|
||||||
|
registry.category("views").add("fusion_bank_rec_list", bankRecListView);
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../list_view/list_view_many2one_multi_edit.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { computeM2OProps, Many2One } from "@web/views/fields/many2one/many2one";
|
||||||
|
import { buildM2OFieldDescription, Many2OneField } from "@web/views/fields/many2one/many2one_field";
|
||||||
|
|
||||||
|
export class BankRecMany2OneMultiID extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecMany2OneMultiID";
|
||||||
|
static components = { Many2One };
|
||||||
|
static props = { ...Many2OneField.props };
|
||||||
|
|
||||||
|
get m2oProps() {
|
||||||
|
const props = computeM2OProps(this.props);
|
||||||
|
if (this.props.record.selected && this.props.record.model.multiEdit) {
|
||||||
|
props.context.active_ids = this.env.model.root.selection.map((r) => r.resId);
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.category("fields").add("fusion_bank_rec_list_many2one_multi_id", {
|
||||||
|
...buildM2OFieldDescription(BankRecMany2OneMultiID),
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecMany2OneMultiID">
|
||||||
|
<Many2One t-props="m2oProps"/>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component, onWillStart, useState } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class PartnerHistoryPanel extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.PartnerHistoryPanel";
|
||||||
|
static props = {
|
||||||
|
partnerId: { type: Number },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
this.state = useState({ history: null, loading: true });
|
||||||
|
|
||||||
|
onWillStart(async () => {
|
||||||
|
try {
|
||||||
|
this.state.history = await this.bankRec.getPartnerHistory(
|
||||||
|
this.props.partnerId,
|
||||||
|
20,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
this.state.loading = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
formatAmount(value) {
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return "0.00";
|
||||||
|
}
|
||||||
|
return Number(value).toFixed(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.PartnerHistoryPanel">
|
||||||
|
<div class="o_fusion_partner_history_panel" style="padding: 1rem; border-left: 1px solid #e5e7eb;">
|
||||||
|
<h5 t-if="state.history">
|
||||||
|
<t t-esc="state.history.partner.name"/> — History
|
||||||
|
</h5>
|
||||||
|
<div t-if="state.loading" class="text-muted">Loading…</div>
|
||||||
|
<div t-elif="state.history">
|
||||||
|
<div t-if="state.history.pattern" class="mb-3 p-2"
|
||||||
|
style="background: #eff6ff; border-radius: 0.25rem; font-size: 0.85em;">
|
||||||
|
<strong>Learned pattern:</strong>
|
||||||
|
<div>Reconciles: <t t-esc="state.history.pattern.reconcile_count"/></div>
|
||||||
|
<div t-if="state.history.pattern.pref_strategy">
|
||||||
|
Preferred strategy: <t t-esc="state.history.pattern.pref_strategy"/>
|
||||||
|
</div>
|
||||||
|
<div t-if="state.history.pattern.typical_cadence_days">
|
||||||
|
Typical cadence: ~<t t-esc="state.history.pattern.typical_cadence_days"/> days
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h6>Recent reconciles</h6>
|
||||||
|
<div t-foreach="state.history.recent_reconciles" t-as="rec" t-key="rec.precedent_id"
|
||||||
|
style="padding: 0.5rem 0; border-bottom: 1px solid #e5e7eb; font-size: 0.85em;">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<span><t t-esc="rec.date"/></span>
|
||||||
|
<span><strong>$<t t-esc="formatAmount(rec.amount)"/></strong></span>
|
||||||
|
</div>
|
||||||
|
<div class="text-muted">
|
||||||
|
<t t-if="rec.memo_tokens"><t t-esc="rec.memo_tokens"/></t>
|
||||||
|
<span class="ms-2">(<t t-esc="rec.matched_count"/> line<t t-if="rec.matched_count !== 1">s</t>)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div t-if="state.history.recent_reconciles.length === 0" class="text-muted">
|
||||||
|
No history yet
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from `account_accountant/.../quick_create/quick_create.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
KanbanRecordQuickCreate,
|
||||||
|
KanbanQuickCreateController,
|
||||||
|
} from "@web/views/kanban/kanban_record_quick_create";
|
||||||
|
|
||||||
|
export class BankRecQuickCreateController extends KanbanQuickCreateController {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecQuickCreateController";
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BankRecQuickCreate extends KanbanRecordQuickCreate {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecQuickCreate";
|
||||||
|
static props = {
|
||||||
|
...KanbanRecordQuickCreate.props,
|
||||||
|
resModel: { type: String },
|
||||||
|
context: { type: Object },
|
||||||
|
group: { type: Object, optional: true },
|
||||||
|
};
|
||||||
|
static components = { BankRecQuickCreateController };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overridden — quick-create flow always works against a synthetic group
|
||||||
|
* built from the resModel + context props (rather than relying on a
|
||||||
|
* caller-provided group), matching Enterprise behaviour.
|
||||||
|
*/
|
||||||
|
async getQuickCreateProps(props) {
|
||||||
|
await super.getQuickCreateProps({
|
||||||
|
...props,
|
||||||
|
group: {
|
||||||
|
resModel: props.resModel,
|
||||||
|
context: props.context,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates id="template" xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecQuickCreate">
|
||||||
|
<BankRecQuickCreateController t-if="state.isLoaded" t-props="quickCreateProps"/>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecQuickCreateController">
|
||||||
|
<div class="o_fusion_bank_reconciliation_quick_create o_kanban_record" t-ref="root">
|
||||||
|
<t t-component="props.Renderer" record="model.root" Compiler="props.Compiler" archInfo="props.archInfo"/>
|
||||||
|
<div class="d-flex gap-1 button_group p-2">
|
||||||
|
<button class="btn btn-primary o_kanban_add" t-on-click="() => this.validate('add')" data-hotkey="s">
|
||||||
|
Add & New
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary o_kanban_edit" t-on-click="() => this.validate('add_close')" data-hotkey="shift+s">
|
||||||
|
Add & Close
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary o_kanban_cancel" t-on-click="() => this.cancel(true)" data-hotkey="d">
|
||||||
|
Discard
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { Component, onWillStart, useState } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class ReconcileModelPicker extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.ReconcileModelPicker";
|
||||||
|
static props = {
|
||||||
|
statementLineId: { type: Number, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
this.state = useState({ models: [], selected: null });
|
||||||
|
|
||||||
|
onWillStart(async () => {
|
||||||
|
const models = await this.orm.searchRead(
|
||||||
|
"account.reconcile.model",
|
||||||
|
[["rule_type", "=", "writeoff_button"]],
|
||||||
|
["id", "name", "fusion_ai_confidence_threshold"],
|
||||||
|
{ limit: 20 }
|
||||||
|
);
|
||||||
|
this.state.models = models;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(ev) {
|
||||||
|
const value = parseInt(ev.target.value, 10);
|
||||||
|
if (Number.isFinite(value)) {
|
||||||
|
this.onApplyModel(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async onApplyModel(modelId) {
|
||||||
|
// Phase 1 placeholder: TODO route through dedicated endpoint when Task 38 lands
|
||||||
|
this.state.selected = modelId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.ReconcileModelPicker">
|
||||||
|
<div class="o_fusion_reconcile_model_picker">
|
||||||
|
<select class="form-select" style="max-width: 240px;"
|
||||||
|
t-on-change="onChange">
|
||||||
|
<option value="">— Apply reconcile model —</option>
|
||||||
|
<option t-foreach="state.models" t-as="m" t-key="m.id" t-att-value="m.id">
|
||||||
|
<t t-esc="m.name"/>
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../reconciled_line_name/reconciled_line_name.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
import { useBankReconciliation } from "@fusion_accounting_bank_rec/components/bank_reconciliation/bank_reconciliation_service";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { x2ManyCommands } from "@web/core/orm_service";
|
||||||
|
|
||||||
|
export class BankRecReconciledLineName extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecReconciledLineName";
|
||||||
|
static props = {
|
||||||
|
statementLine: { type: Object },
|
||||||
|
linesToReconcile: { type: Object },
|
||||||
|
moveLineId: { type: String },
|
||||||
|
valueToDisplay: { type: Object },
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.bankReconciliation = useBankReconciliation();
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteTax(lineId, taxChanged) {
|
||||||
|
const lineData = this.props.linesToReconcile.filter((line) => {
|
||||||
|
return line.id === parseInt(lineId);
|
||||||
|
})[0];
|
||||||
|
await this.orm.call("account.bank.statement.line", "edit_reconcile_line", [
|
||||||
|
this.props.statementLine.data.id,
|
||||||
|
lineData.id,
|
||||||
|
{ tax_ids: [[x2ManyCommands.UNLINK, taxChanged.data.id]] },
|
||||||
|
]);
|
||||||
|
this.props.statementLine.load();
|
||||||
|
this.bankReconciliation.reloadChatter();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecReconciledLineName">
|
||||||
|
<div name="reconciled_line_name" class="text-start text-truncate text-muted">
|
||||||
|
<t t-if="props.valueToDisplay?.tax">
|
||||||
|
<t t-foreach="props.valueToDisplay.tax" t-as="tax_id" t-key="tax_id_index">
|
||||||
|
<div class="o_tag d-inline-flex align-items-center badge rounded-pill o_tag_color_0 flex-shrink-0" t-att-class="!tax_id_last ? 'me-1': ''">
|
||||||
|
<span class="o_tag_badge_text text-truncate" t-esc="tax_id.data.display_name"/>
|
||||||
|
<i t-on-click.stop="() => this.deleteTax(props.moveLineId, tax_id)" class="ps-1 opacity-100-hover opacity-75 oi oi-close"/>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
<t t-else="" t-out="props.valueToDisplay.move or props.valueToDisplay.account"/>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../search_dialog/search_dialog.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { SelectCreateDialog } from "@web/views/view_dialogs/select_create_dialog";
|
||||||
|
import { formatMonetary } from "@web/views/fields/formatters";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
const { DateTime } = luxon;
|
||||||
|
|
||||||
|
export class BankRecSelectCreateDialog extends SelectCreateDialog {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecSelectCreateDialog";
|
||||||
|
static props = {
|
||||||
|
...SelectCreateDialog.props,
|
||||||
|
suspenseAccountLine: Object,
|
||||||
|
reference: String,
|
||||||
|
date: DateTime,
|
||||||
|
size: { type: String, optional: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
...SelectCreateDialog.defaultProps,
|
||||||
|
size: "lg",
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.ui = useService("ui");
|
||||||
|
this.state.remainingAmount = this.suspenseAccountLine.amount_currency;
|
||||||
|
this.state.hideRemainingAmount = false;
|
||||||
|
|
||||||
|
this.baseViewProps.onSelectionChanged = (resIds, selectedLines) => {
|
||||||
|
this.state.resIds = resIds;
|
||||||
|
this.changeInSelectedMoveLine(selectedLines);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeInSelectedMoveLine(selectedLines) {
|
||||||
|
if (!selectedLines?.length) {
|
||||||
|
this.state.remainingAmount = this.suspenseAccountLine.amount_currency;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectedLinesSum = 0;
|
||||||
|
this.state.hideRemainingAmount = false;
|
||||||
|
if (
|
||||||
|
this.suspenseAccountLine.currency_id.id !==
|
||||||
|
this.suspenseAccountLine.company_currency_id.id
|
||||||
|
) {
|
||||||
|
const selectedLineCurrencies = selectedLines.map((line) => line.currency_id);
|
||||||
|
|
||||||
|
if (
|
||||||
|
selectedLineCurrencies.length !== 1 ||
|
||||||
|
(selectedLineCurrencies.length === 1 &&
|
||||||
|
selectedLineCurrencies[0] !== this.suspenseAccountLine.currency_id.id)
|
||||||
|
) {
|
||||||
|
this.state.hideRemainingAmount = true;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
selectedLinesSum = selectedLines.reduce((sum, line) => {
|
||||||
|
return sum + line.amount_residual_currency;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedLinesSum = selectedLines.reduce((sum, line) => {
|
||||||
|
return sum + line.amount_residual;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
this.state.remainingAmount = this.suspenseAccountLine.amount_currency + selectedLinesSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
get suspenseAccountLine() {
|
||||||
|
return this.props?.suspenseAccountLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
get remainingAmountFormatted() {
|
||||||
|
return formatMonetary(this.state.remainingAmount, {
|
||||||
|
currencyId: this.suspenseAccountLine.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedStatementLineDate() {
|
||||||
|
return this.props.date?.toLocaleString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecSelectCreateDialog" t-inherit="web.SelectCreateDialog" t-inherit-mode="primary">
|
||||||
|
<xpath expr="//Dialog" position="attributes">
|
||||||
|
<attribute name="size">props.size</attribute>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
<xpath expr="//button[hasclass('o_form_button_cancel')]" position="after">
|
||||||
|
<div t-if="!this.ui.isSmall" class="d-flex align-items-center flex-grow-1 flex-shrink-1 flex-basis-0 gap-2 min-w-0 justify-content-between" name="bank_reconciliation_info">
|
||||||
|
<span t-esc="formattedStatementLineDate"/>
|
||||||
|
<div class="text-truncate" t-esc="props.reference"/>
|
||||||
|
<div class="text-nowrap text-end" name="remaining_amount">
|
||||||
|
<span class="text-muted">Balance: </span>
|
||||||
|
<t t-if="!this.state.hideRemainingAmount" t-esc="remainingAmountFormatted"/>
|
||||||
|
<t t-else=""> / </t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../search_dialog/search_dialog_list.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ListController } from "@web/views/list/list_controller";
|
||||||
|
import { ListRenderer } from "@web/views/list/list_renderer";
|
||||||
|
import { listView } from "@web/views/list/list_view";
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
|
||||||
|
export class BankRecReconcileDialogListController extends ListController {
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.orm = useService("orm");
|
||||||
|
}
|
||||||
|
|
||||||
|
async onSelectionChanged() {
|
||||||
|
const resIds = await this.model.root.getResIds(true);
|
||||||
|
if (!resIds.length) {
|
||||||
|
this.props.onSelectionChanged(resIds, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectedLines;
|
||||||
|
// When being in the list view with more elements than the limit and
|
||||||
|
// doing a select all, the user can select more elements than the
|
||||||
|
// limit. In this case the isDomainSelected is True.
|
||||||
|
if (this.isDomainSelected) {
|
||||||
|
const { resModel, context } = this.model.root._config;
|
||||||
|
selectedLines = await this.orm.read(
|
||||||
|
resModel,
|
||||||
|
resIds,
|
||||||
|
["amount_residual", "amount_residual_currency", "currency_id"],
|
||||||
|
{ context }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
selectedLines = Object.values(this.model.root.records)
|
||||||
|
.filter((record) => resIds.includes(record._config.resId))
|
||||||
|
.map((record) => {
|
||||||
|
const data = record.data;
|
||||||
|
return {
|
||||||
|
amount_residual: data.amount_residual,
|
||||||
|
amount_residual_currency: data.amount_residual_currency,
|
||||||
|
currency_id: data.currency_id.id,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.props.onSelectionChanged(resIds, selectedLines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BankRecReconcileDialogListRenderer extends ListRenderer {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecReconcileDialogListRenderer";
|
||||||
|
static recordRowTemplate =
|
||||||
|
"fusion_accounting_bank_rec.BankRecReconcileDialogListRenderer.RecordRow";
|
||||||
|
|
||||||
|
async openMoveView(record) {
|
||||||
|
this.env.services.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "account.move",
|
||||||
|
res_id: record.data.move_id.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const bankRecReconcileDialogListRenderer = {
|
||||||
|
...listView,
|
||||||
|
Renderer: BankRecReconcileDialogListRenderer,
|
||||||
|
Controller: BankRecReconcileDialogListController,
|
||||||
|
};
|
||||||
|
|
||||||
|
registry.category("views").add("fusion_bank_rec_dialog_list", bankRecReconcileDialogListRenderer);
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecReconcileDialogListRenderer" t-inherit="web.ListRenderer" t-inherit-mode="primary">
|
||||||
|
<xpath expr="//th[@t-if='hasOpenFormViewColumn']" position="replace">
|
||||||
|
<th class="o_list_open_form_view w-print-0 p-print-0"/>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecReconcileDialogListRenderer.RecordRow" t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="primary">
|
||||||
|
<xpath expr="//t[@t-if='hasOpenFormViewColumn']" position="replace">
|
||||||
|
<td class="o_list_record_open_form_view w-print-0 p-print-0 text-center"
|
||||||
|
t-custom-click.stop="() => this.openMoveView(record)"
|
||||||
|
>
|
||||||
|
<button class="btn btn-link align-top text-end"
|
||||||
|
name="Open in form view"
|
||||||
|
aria-label="Open in form view"
|
||||||
|
>View</button>
|
||||||
|
</td>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/static/src/components/bank_reconciliation/statement_line/statement_line.js`
|
||||||
|
*
|
||||||
|
* Phase 1 structural parity. Module IDs / template names / CSS classes
|
||||||
|
* rebranded to `fusion_accounting_bank_rec`. Behaviour delegates to the
|
||||||
|
* Enterprise-compat surface in our `fusion_bank_reconciliation` service.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { BankRecButtonList } from "@fusion_accounting_bank_rec/components/bank_reconciliation/button_list/button_list";
|
||||||
|
import { BankRecLineToReconcile } from "@fusion_accounting_bank_rec/components/bank_reconciliation/line_to_reconcile/line_to_reconcile";
|
||||||
|
import { BankRecReconciledLineName } from "@fusion_accounting_bank_rec/components/bank_reconciliation/reconciled_line_name/reconciled_line_name";
|
||||||
|
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||||
|
import { formatMonetary } from "@web/views/fields/formatters";
|
||||||
|
import { KanbanRecord } from "@web/views/kanban/kanban_record";
|
||||||
|
import { user } from "@web/core/user";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { onWillStart, useState, useRef } from "@odoo/owl";
|
||||||
|
import { useBankReconciliation } from "@fusion_accounting_bank_rec/components/bank_reconciliation/bank_reconciliation_service";
|
||||||
|
|
||||||
|
export class BankRecStatementLine extends KanbanRecord {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecStatementLine";
|
||||||
|
static components = {
|
||||||
|
BankRecLineToReconcile,
|
||||||
|
BankRecButtonList,
|
||||||
|
DropdownItem,
|
||||||
|
BankRecReconciledLineName,
|
||||||
|
};
|
||||||
|
static props = [...KanbanRecord.props];
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
super.setup();
|
||||||
|
this.orm = useService("orm");
|
||||||
|
this.ui = useService("ui");
|
||||||
|
this.bankReconciliation = useBankReconciliation();
|
||||||
|
this.state = useState({
|
||||||
|
isUnfolded: false,
|
||||||
|
});
|
||||||
|
this.statementLineRootRef = useRef("root");
|
||||||
|
if (this.env.model.config.context?.default_st_line_id === this.props.record.resId) {
|
||||||
|
this.state.isUnfolded = true;
|
||||||
|
this.bankReconciliation.selectStatementLine(this.props.record);
|
||||||
|
}
|
||||||
|
onWillStart(async () => {
|
||||||
|
this.userCanReview = await user.hasGroup("account.group_account_user");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getRecordClasses() {
|
||||||
|
let classes = super.getRecordClasses();
|
||||||
|
if (this.hasStatementLine === 1) {
|
||||||
|
classes += " mt-3";
|
||||||
|
}
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// ACTION
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
openStatementCreate() {
|
||||||
|
this.action.doAction("account_accountant.action_bank_statement_form_bank_rec_widget", {
|
||||||
|
additionalContext: {
|
||||||
|
split_line_id: this.recordData.id,
|
||||||
|
default_journal_id: this.recordData.journal_id.id,
|
||||||
|
},
|
||||||
|
onClose: async () => {
|
||||||
|
this.env.model.load();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openPartner() {
|
||||||
|
this.action.doAction({
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
res_model: "res.partner",
|
||||||
|
res_id: this.partner.id,
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "current",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removePartner() {
|
||||||
|
await this.orm.write("account.bank.statement.line", [this.recordData.id], {
|
||||||
|
partner_id: false,
|
||||||
|
});
|
||||||
|
this.record.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// HELPER
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
get reconciledLineName() {
|
||||||
|
const reconciledLine = {};
|
||||||
|
for (const line of this.linesToReconcile) {
|
||||||
|
if (
|
||||||
|
line.reconciled_lines_excluding_exchange_diff_ids.records.length === 1 &&
|
||||||
|
line.reconciled_lines_excluding_exchange_diff_ids.records[0].data.move_name
|
||||||
|
) {
|
||||||
|
reconciledLine[line.id] = {
|
||||||
|
move: line.reconciled_lines_excluding_exchange_diff_ids.records[0].data
|
||||||
|
.move_name,
|
||||||
|
};
|
||||||
|
} else if (line.tax_ids.count) {
|
||||||
|
reconciledLine[line.id] = { tax: line.tax_ids.records };
|
||||||
|
} else {
|
||||||
|
reconciledLine[line.id] = { account: line.account_id.display_name };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reconciledLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
get record() {
|
||||||
|
return this.props.record;
|
||||||
|
}
|
||||||
|
|
||||||
|
get recordData() {
|
||||||
|
return this.props.record.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fold() {
|
||||||
|
if (this.state.isUnfolded) {
|
||||||
|
this.toggleUnfold();
|
||||||
|
}
|
||||||
|
this.selectStatementLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
unfold() {
|
||||||
|
if (!this.state.isUnfolded) {
|
||||||
|
this.toggleUnfold();
|
||||||
|
}
|
||||||
|
this.selectStatementLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleUnfold() {
|
||||||
|
this.state.isUnfolded = !this.isUnfolded;
|
||||||
|
this.selectStatementLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
selectStatementLine() {
|
||||||
|
// Update the chatter with the last selected element
|
||||||
|
this.bankReconciliation.selectStatementLine(this.record);
|
||||||
|
}
|
||||||
|
|
||||||
|
openChatter() {
|
||||||
|
this.selectStatementLine();
|
||||||
|
this.bankReconciliation.openChatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasInvalidAnalytics() {
|
||||||
|
return this.linesToReconcile.some((line) => line.has_invalid_analytics);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isUnfolded() {
|
||||||
|
return this.state.isUnfolded;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasStatementLine() {
|
||||||
|
return this.env.model.root.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedAmount() {
|
||||||
|
return formatMonetary(this.recordData.amount, {
|
||||||
|
currencyId: this.recordData.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedDate() {
|
||||||
|
return this.recordData.date.toLocaleString({
|
||||||
|
month: "short",
|
||||||
|
day: "2-digit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedFullDate() {
|
||||||
|
return this.recordData.date.toLocaleString({
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get partner() {
|
||||||
|
return this.recordData.partner_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get linesToReconcile() {
|
||||||
|
return this.accountMoveLines.filter((line) => {
|
||||||
|
return (
|
||||||
|
line.account_id.id !== this.recordData.journal_id?.suspense_account_id.id &&
|
||||||
|
line.account_id.id !== this.recordData.journal_id?.default_account_id.id
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get suspenseAccountLine() {
|
||||||
|
return this.accountMoveLines.filter((line) => {
|
||||||
|
return line.account_id.id === this.recordData.journal_id.suspense_account_id.id;
|
||||||
|
})?.[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
get accountMoveLines() {
|
||||||
|
return [...this.recordData.line_ids.records.map((line) => line.data)];
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasForeignCurrencyAndSameCurrencyForAllLines() {
|
||||||
|
return (
|
||||||
|
this.recordData.foreign_currency_id &&
|
||||||
|
this.linesToReconcile &&
|
||||||
|
this.linesToReconcile.filter((line) => {
|
||||||
|
return line.currency_id.id !== this.recordData.foreign_currency_id.id;
|
||||||
|
}).length === 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get suspenseAccountLineFormattedAmount() {
|
||||||
|
return formatMonetary(this.suspenseAccountLine.amount_currency, {
|
||||||
|
currencyId: this.suspenseAccountLine?.currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get activityNumber() {
|
||||||
|
return this.recordData.activity_ids.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if there is at least one attachment associated with the bank
|
||||||
|
* statement line or its related records. Aggregates attachment counts from
|
||||||
|
* the move, the related move lines, and the lines reconciled with them.
|
||||||
|
*
|
||||||
|
* @returns {number} Total attachments. > 0 indicates presence.
|
||||||
|
*/
|
||||||
|
get hasAttachment() {
|
||||||
|
const statementAttachment = this.recordData.bank_statement_attachment_ids.records.map(
|
||||||
|
(attachment) => attachment.data.id
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
this.recordData.attachment_ids.records.length +
|
||||||
|
this.linesToReconcile
|
||||||
|
.flatMap((line) => line.reconciled_lines_ids.records)
|
||||||
|
.filter((line) => line.data.move_attachment_ids?.count)
|
||||||
|
.reduce(
|
||||||
|
(accumulator, line) =>
|
||||||
|
parseInt(accumulator) + parseInt(line.data.move_attachment_ids.count),
|
||||||
|
0
|
||||||
|
) +
|
||||||
|
this.linesToReconcile
|
||||||
|
.filter(
|
||||||
|
(line) =>
|
||||||
|
line.move_attachment_ids?.count &&
|
||||||
|
!line.move_attachment_ids.records
|
||||||
|
.map((attachment) => attachment.data.id)
|
||||||
|
.every((id) => statementAttachment.includes(id))
|
||||||
|
)
|
||||||
|
.reduce(
|
||||||
|
(accumulator, line) =>
|
||||||
|
parseInt(accumulator) + parseInt(line.move_attachment_ids.count),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get amountClasses() {
|
||||||
|
const classes = this.recordData.foreign_currency_id ? "w-50" : "w-100";
|
||||||
|
if (this.recordData.amount > 0) {
|
||||||
|
return `${classes} fw-bold`;
|
||||||
|
}
|
||||||
|
if (this.recordData.amount < 0) {
|
||||||
|
return `${classes} text-danger fw-bold`;
|
||||||
|
}
|
||||||
|
return `${classes} text-secondary`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get buttonListProps() {
|
||||||
|
return {
|
||||||
|
statementLineRootRef: this.statementLineRootRef,
|
||||||
|
statementLine: this.record,
|
||||||
|
reconcileLineCount:
|
||||||
|
this.bankReconciliation.reconcileCountPerPartnerId[this.recordData.partner_id.id] ??
|
||||||
|
null,
|
||||||
|
reconcileModels:
|
||||||
|
this.bankReconciliation.reconcileModelPerStatementLineId[this.recordData.id] ?? [],
|
||||||
|
preSelectedReconciliationModel: this.accountMoveLines
|
||||||
|
.filter((line) => line.reconcile_model_id.id)
|
||||||
|
.map((line) => line.reconcile_model_id)?.[0],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get formattedAmountCurrencyInForeign() {
|
||||||
|
return formatMonetary(this.recordData.amount_currency, {
|
||||||
|
currencyId: this.recordData.foreign_currency_id.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSelected() {
|
||||||
|
return this.recordData.move_id.id === this.bankReconciliation.statementLineMoveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isChatterOpen() {
|
||||||
|
return this.bankReconciliation.chatterState.visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecStatementLine" t-inherit="web.KanbanRecord" t-inherit-mode="primary">
|
||||||
|
<xpath expr="//article" position="replace">
|
||||||
|
<article
|
||||||
|
t-att-class="getRecordClasses()"
|
||||||
|
t-att-data-id="record.id"
|
||||||
|
t-att-tabindex="record.model.useSampleModel ? -1 : 0"
|
||||||
|
t-custom-click="onGlobalClick"
|
||||||
|
t-on-touchstart="onTouchStart"
|
||||||
|
t-on-touchmove="onTouchMoveOrCancel"
|
||||||
|
t-on-touchcancel="onTouchMoveOrCancel"
|
||||||
|
t-on-touchend="onTouchEnd"
|
||||||
|
t-ref="root">
|
||||||
|
<div name="bank_statement_line" class="o_statement_line w-100 p-2" t-on-click="selectStatementLine" t-att-class="{'o_selected_statement_line': isSelected}">
|
||||||
|
<button t-if="!recordData.statement_id" type="button" class="o_statement_btn d-none d-md-block position-absolute top-0 end-0 btn btn-sm btn-secondary" t-on-click.stop="openStatementCreate">
|
||||||
|
Statement
|
||||||
|
</button>
|
||||||
|
<div class="o_grid_container">
|
||||||
|
<div class="o_row">
|
||||||
|
<div class="d-flex gap-3">
|
||||||
|
<div t-att-data-tooltip="formattedFullDate">
|
||||||
|
<t t-esc="formattedDate"/>
|
||||||
|
</div>
|
||||||
|
<div t-on-click.stop="openChatter" t-if="!ui.isSmall" class="o_chatter_icon btn-link text-action" t-att-class="{'visible': activityNumber or hasAttachment}">
|
||||||
|
<div t-if="activityNumber" class="activity-container position-relative">
|
||||||
|
<i class="fa fa-lg fa-clock-o" role="img" aria-label="Activities"/>
|
||||||
|
<span class="activity-badge badge rounded-pill" t-esc="activityNumber"/>
|
||||||
|
</div>
|
||||||
|
<i t-elif="hasAttachment"
|
||||||
|
class="fa fa-lg fa-paperclip"
|
||||||
|
role="img"
|
||||||
|
aria-label="Attachment"
|
||||||
|
/>
|
||||||
|
<i t-elif="!isChatterOpen"
|
||||||
|
class="fa fa-lg fa-comments-o"
|
||||||
|
role="img"
|
||||||
|
aria-label="Journal Entry"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="o_payment_ref user-select-text d-none d-md-block"
|
||||||
|
t-att-class="isUnfolded ? 'overflow-wrap' : 'text-truncate'">
|
||||||
|
<span class="d-inline">
|
||||||
|
<t t-if="partner">
|
||||||
|
<a class="fw-bold" href="#" t-on-click.prevent.stop="openPartner">
|
||||||
|
<span t-esc="partner.display_name" name="statement_line_partner_name"/>
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-link oi oi-close p-0 align-baseline" t-on-click.stop="removePartner" t-if="!linesToReconcile.length"/>
|
||||||
|
</t>
|
||||||
|
<t t-elif="recordData.partner_name">
|
||||||
|
<span class="fw-bold" t-esc="recordData.partner_name" name="statement_line_partner_name"/>
|
||||||
|
</t>
|
||||||
|
<span t-att-class="partner or recordData.partner_name ? 'ms-1' : undefined"
|
||||||
|
t-esc="recordData.payment_ref"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<!-- Only available on large screen -->
|
||||||
|
<div class="o_button_line d-none d-md-flex align-items-start text-truncate">
|
||||||
|
<BankRecButtonList t-props="buttonListProps" suspenseAccountLine="suspenseAccountLine" t-if="!recordData.is_reconciled or (userCanReview and !recordData.checked)"/>
|
||||||
|
<span class="badge rounded-pill py-1 ps-1" t-att-class="{ 'pe-1': !isUnfolded, 'text-success bg-success-subtle': !hasInvalidAnalytics, 'text-warning bg-warning-subtle': hasInvalidAnalytics}" t-if="recordData.is_reconciled">
|
||||||
|
<i t-if="hasInvalidAnalytics" class="fa fa-exclamation-triangle" data-tooltip="Some lines have invalid analytic distribution"/>
|
||||||
|
<i t-if="!hasInvalidAnalytics" class="fa fa-check"/>
|
||||||
|
<span t-if="isUnfolded" class="ms-1">
|
||||||
|
Reconciled
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<t t-if="recordData.is_reconciled and !isUnfolded">
|
||||||
|
<t t-foreach="Object.entries(reconciledLineName)" t-as="line" t-key="line_index">
|
||||||
|
<BankRecReconciledLineName statementLine="record" linesToReconcile="linesToReconcile" moveLineId="line[0]" valueToDisplay="line[1]"/>
|
||||||
|
<t t-if="line_index < Object.keys(reconciledLineName).length - 1">, </t>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-start justify-content-between o_line_amount">
|
||||||
|
<span class="text-muted w-50 text-end text-nowrap" t-if="recordData.foreign_currency_id">
|
||||||
|
<t t-esc="formattedAmountCurrencyInForeign"/>
|
||||||
|
</span>
|
||||||
|
<span t-att-class="amountClasses" class="text-end text-nowrap" t-esc="formattedAmount"/>
|
||||||
|
</div>
|
||||||
|
<div class="d-none d-md-block text-end" t-on-click="toggleUnfold" t-if="recordData.is_reconciled">
|
||||||
|
<i class="oi" t-att-class="{'oi-chevron-up': isUnfolded, 'oi-chevron-down': !isUnfolded}"/>
|
||||||
|
</div>
|
||||||
|
<div class="d-none d-md-block" t-else=""/> <!-- To keep empty space if no chevron -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Only available on small screen -->
|
||||||
|
<div class="o_row d-md-none">
|
||||||
|
<span class="text-truncate o_payment_ref"
|
||||||
|
t-esc="recordData.payment_ref"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<t t-if="isUnfolded or !recordData.is_reconciled">
|
||||||
|
<t t-foreach="linesToReconcile" t-as="line" t-key="line_index">
|
||||||
|
<BankRecLineToReconcile statementLine="record" line="line"/>
|
||||||
|
</t>
|
||||||
|
<div class="o_row" t-if="linesToReconcile.length">
|
||||||
|
<div t-if="suspenseAccountLine" class="d-none d-md-flex fw-bold text-muted align-items-center justify-content-end o_line_amount" t-att-class="hasForeignCurrencyAndSameCurrencyForAllLines ? 'w-50' : 'w-100'">
|
||||||
|
<t t-esc="suspenseAccountLineFormattedAmount"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
<div class="o_row d-md-none">
|
||||||
|
<div class="o_button_line">
|
||||||
|
<BankRecButtonList t-props="buttonListProps" suspenseAccountLine="suspenseAccountLine" t-if="!recordData.is_reconciled or (userCanReview and !recordData.checked)"/>
|
||||||
|
<span t-if="recordData.is_reconciled and !isUnfolded" class="text-start text-muted" t-esc="reconciledLineName"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</xpath>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mirrored from
|
||||||
|
* `account_accountant/.../statement_summary/statement_summary.js`.
|
||||||
|
* Phase 1 structural parity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
|
||||||
|
export class BankRecStatementSummary extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecStatementSummary";
|
||||||
|
|
||||||
|
static props = {
|
||||||
|
label: { type: String },
|
||||||
|
amount: { type: String, optional: true },
|
||||||
|
action: { type: Function },
|
||||||
|
journalId: { type: Number, optional: true },
|
||||||
|
isValid: { type: Boolean, optional: true },
|
||||||
|
journalIsInvalid: { type: Boolean, optional: true },
|
||||||
|
};
|
||||||
|
static defaultProps = {
|
||||||
|
isValid: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
actionApplyInvalidStatement() {
|
||||||
|
const facets = this.env.searchModel.facets;
|
||||||
|
const searchItems = this.env.searchModel.searchItems;
|
||||||
|
const invalidStatementFilter = Object.values(searchItems).find(
|
||||||
|
(i) => i.name == "invalid_statement"
|
||||||
|
);
|
||||||
|
const invalidStatementFacet = facets.filter(
|
||||||
|
(i) => i.groupId == invalidStatementFilter.groupId
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
invalidStatementFacet.length == 0 ||
|
||||||
|
!invalidStatementFacet[0].values.includes(invalidStatementFilter.description)
|
||||||
|
) {
|
||||||
|
this.env.searchModel.toggleSearchItem(invalidStatementFilter.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecStatementSummary">
|
||||||
|
<div class="o_statement_summary d-flex justify-content-between align-items-center w-100 p-2">
|
||||||
|
<div name="label_statement_summary" class="d-flex gap-2 align-items-center">
|
||||||
|
<h4 t-esc="props.label"
|
||||||
|
t-on-click="props.action"
|
||||||
|
class="m-0"
|
||||||
|
t-att-class="{'text-danger': !props.isValid}"/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 class="m-0"
|
||||||
|
t-if="props.journalIsInvalid"
|
||||||
|
t-on-click="actionApplyInvalidStatement">
|
||||||
|
Invalid Statement(s)
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div t-if="props.amount"
|
||||||
|
class="btn btn-link p-0 fw-bold fs-4"
|
||||||
|
t-on-click="props.action"
|
||||||
|
t-esc="props.amount"/>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
91
fusion_accounting_bank_rec/static/src/scss/_variables.scss
Normal file
91
fusion_accounting_bank_rec/static/src/scss/_variables.scss
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// Fusion bank reconciliation design tokens.
|
||||||
|
//
|
||||||
|
// Mirrors Enterprise's color/spacing scale where it makes sense, with
|
||||||
|
// fusion-specific additions for AI confidence bands and the suggestion
|
||||||
|
// strip. All values can be overridden in dark_mode.scss.
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Colors — semantic
|
||||||
|
// ============================================================
|
||||||
|
$fusion-color-bg-primary: #ffffff;
|
||||||
|
$fusion-color-bg-secondary: #f9fafb;
|
||||||
|
$fusion-color-bg-tertiary: #f3f4f6;
|
||||||
|
$fusion-color-border: #e5e7eb;
|
||||||
|
$fusion-color-border-strong: #d1d5db;
|
||||||
|
|
||||||
|
$fusion-color-text-primary: #111827;
|
||||||
|
$fusion-color-text-secondary: #6b7280;
|
||||||
|
$fusion-color-text-muted: #9ca3af;
|
||||||
|
$fusion-color-text-inverse: #ffffff;
|
||||||
|
|
||||||
|
$fusion-color-accent: #3b82f6; // primary brand blue
|
||||||
|
$fusion-color-accent-hover: #2563eb;
|
||||||
|
$fusion-color-accent-bg: #eff6ff;
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// AI Confidence band colors
|
||||||
|
// ============================================================
|
||||||
|
$fusion-confidence-high: #10b981; // green
|
||||||
|
$fusion-confidence-high-bg: #ecfdf5;
|
||||||
|
$fusion-confidence-medium: #f59e0b; // amber
|
||||||
|
$fusion-confidence-medium-bg: #fffbeb;
|
||||||
|
$fusion-confidence-low: #ef4444; // red
|
||||||
|
$fusion-confidence-low-bg: #fef2f2;
|
||||||
|
$fusion-confidence-none: #9ca3af; // gray
|
||||||
|
$fusion-confidence-none-bg: #f3f4f6;
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Reconciliation state colors
|
||||||
|
// ============================================================
|
||||||
|
$fusion-state-pending-bg: #fef3c7; // amber-100
|
||||||
|
$fusion-state-reconciled-bg: #d1fae5; // emerald-100
|
||||||
|
$fusion-state-partial-bg: #fde68a; // amber-200
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Spacing scale (4px increments)
|
||||||
|
// ============================================================
|
||||||
|
$fusion-space-1: 0.25rem; // 4px
|
||||||
|
$fusion-space-2: 0.5rem; // 8px
|
||||||
|
$fusion-space-3: 0.75rem; // 12px
|
||||||
|
$fusion-space-4: 1rem; // 16px
|
||||||
|
$fusion-space-5: 1.25rem; // 20px
|
||||||
|
$fusion-space-6: 1.5rem; // 24px
|
||||||
|
$fusion-space-8: 2rem; // 32px
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Typography
|
||||||
|
// ============================================================
|
||||||
|
$fusion-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
$fusion-font-size-xs: 0.75rem; // 12px
|
||||||
|
$fusion-font-size-sm: 0.875rem; // 14px
|
||||||
|
$fusion-font-size-base: 1rem; // 16px
|
||||||
|
$fusion-font-size-lg: 1.125rem; // 18px
|
||||||
|
$fusion-font-size-xl: 1.25rem; // 20px
|
||||||
|
|
||||||
|
$fusion-font-weight-normal: 400;
|
||||||
|
$fusion-font-weight-medium: 500;
|
||||||
|
$fusion-font-weight-semibold: 600;
|
||||||
|
$fusion-font-weight-bold: 700;
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Borders + radii
|
||||||
|
// ============================================================
|
||||||
|
$fusion-border-radius-sm: 0.25rem;
|
||||||
|
$fusion-border-radius: 0.375rem;
|
||||||
|
$fusion-border-radius-md: 0.5rem;
|
||||||
|
$fusion-border-radius-lg: 0.75rem;
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Shadows
|
||||||
|
// ============================================================
|
||||||
|
$fusion-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||||
|
$fusion-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
$fusion-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||||
|
$fusion-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Animation
|
||||||
|
// ============================================================
|
||||||
|
$fusion-transition-fast: 150ms ease-in-out;
|
||||||
|
$fusion-transition-base: 200ms ease-in-out;
|
||||||
|
$fusion-transition-slow: 300ms ease-in-out;
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
@import "variables";
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// AI Suggestion strip (inline, on each statement line card)
|
||||||
|
// ============================================================
|
||||||
|
.o_fusion_ai_suggestion {
|
||||||
|
margin-top: $fusion-space-3;
|
||||||
|
padding: $fusion-space-3;
|
||||||
|
border-radius: $fusion-border-radius;
|
||||||
|
border: 1px solid;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: $fusion-space-3;
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
transition: all $fusion-transition-base;
|
||||||
|
|
||||||
|
// Confidence bands — apply via [data-band="..."] attribute
|
||||||
|
&[data-band="high"] {
|
||||||
|
background: $fusion-confidence-high-bg;
|
||||||
|
border-color: $fusion-confidence-high;
|
||||||
|
|
||||||
|
.o_fusion_confidence_value { color: $fusion-confidence-high; }
|
||||||
|
}
|
||||||
|
&[data-band="medium"] {
|
||||||
|
background: $fusion-confidence-medium-bg;
|
||||||
|
border-color: $fusion-confidence-medium;
|
||||||
|
|
||||||
|
.o_fusion_confidence_value { color: $fusion-confidence-medium; }
|
||||||
|
}
|
||||||
|
&[data-band="low"] {
|
||||||
|
background: $fusion-confidence-low-bg;
|
||||||
|
border-color: $fusion-confidence-low;
|
||||||
|
|
||||||
|
.o_fusion_confidence_value { color: $fusion-confidence-low; }
|
||||||
|
}
|
||||||
|
&[data-band="none"] {
|
||||||
|
background: $fusion-confidence-none-bg;
|
||||||
|
border-color: $fusion-confidence-none;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_confidence_badge {
|
||||||
|
font-weight: $fusion-font-weight-bold;
|
||||||
|
font-size: $fusion-font-size-base;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_suggestion_text {
|
||||||
|
flex: 1;
|
||||||
|
color: $fusion-color-text-primary;
|
||||||
|
|
||||||
|
.o_fusion_reasoning {
|
||||||
|
color: $fusion-color-text-secondary;
|
||||||
|
font-style: italic;
|
||||||
|
margin-top: $fusion-space-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_suggestion_actions {
|
||||||
|
display: flex;
|
||||||
|
gap: $fusion-space-2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Alternatives panel (expandable list of other suggestions)
|
||||||
|
// ============================================================
|
||||||
|
.o_fusion_alternatives_panel {
|
||||||
|
margin-top: $fusion-space-2;
|
||||||
|
padding: $fusion-space-3;
|
||||||
|
background: $fusion-color-bg-secondary;
|
||||||
|
border: 1px solid $fusion-color-border;
|
||||||
|
border-radius: $fusion-border-radius;
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
|
||||||
|
.o_fusion_alternative {
|
||||||
|
padding: $fusion-space-2 0;
|
||||||
|
border-bottom: 1px solid $fusion-color-border;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&:last-child { border-bottom: none; }
|
||||||
|
|
||||||
|
.alt_confidence {
|
||||||
|
font-weight: $fusion-font-weight-medium;
|
||||||
|
margin-right: $fusion-space-2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
@import "variables";
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Bank reconciliation kanban container
|
||||||
|
// ============================================================
|
||||||
|
.o_fusion_bank_rec {
|
||||||
|
background: $fusion-color-bg-secondary;
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: $fusion-font-family;
|
||||||
|
color: $fusion-color-text-primary;
|
||||||
|
|
||||||
|
// Header bar with stats
|
||||||
|
&_header {
|
||||||
|
background: $fusion-color-bg-primary;
|
||||||
|
border-bottom: 1px solid $fusion-color-border;
|
||||||
|
padding: $fusion-space-4 $fusion-space-6;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: $fusion-font-size-xl;
|
||||||
|
font-weight: $fusion-font-weight-semibold;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_stats {
|
||||||
|
display: flex;
|
||||||
|
gap: $fusion-space-6;
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
color: $fusion-color-text-secondary;
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-weight: $fusion-font-weight-semibold;
|
||||||
|
color: $fusion-color-text-primary;
|
||||||
|
margin-left: $fusion-space-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Statement line cards (kanban tile)
|
||||||
|
&_line {
|
||||||
|
background: $fusion-color-bg-primary;
|
||||||
|
border: 1px solid $fusion-color-border;
|
||||||
|
border-radius: $fusion-border-radius-md;
|
||||||
|
padding: $fusion-space-4;
|
||||||
|
margin-bottom: $fusion-space-3;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all $fusion-transition-base;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: $fusion-color-accent;
|
||||||
|
box-shadow: $fusion-shadow-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.o_fusion_selected {
|
||||||
|
border-color: $fusion-color-accent;
|
||||||
|
background: $fusion-color-accent-bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
&_header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: $fusion-space-2;
|
||||||
|
|
||||||
|
.o_fusion_amount {
|
||||||
|
font-size: $fusion-font-size-lg;
|
||||||
|
font-weight: $fusion-font-weight-semibold;
|
||||||
|
|
||||||
|
&.negative {
|
||||||
|
color: $fusion-confidence-low;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_date {
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
color: $fusion-color-text-secondary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&_body {
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
color: $fusion-color-text-secondary;
|
||||||
|
|
||||||
|
.o_fusion_partner {
|
||||||
|
font-weight: $fusion-font-weight-medium;
|
||||||
|
color: $fusion-color-text-primary;
|
||||||
|
margin-right: $fusion-space-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_memo {
|
||||||
|
font-style: italic;
|
||||||
|
color: $fusion-color-text-muted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attachment count badge
|
||||||
|
.o_fusion_attachments_badge {
|
||||||
|
position: absolute;
|
||||||
|
top: $fusion-space-2;
|
||||||
|
right: $fusion-space-2;
|
||||||
|
background: $fusion-color-bg-tertiary;
|
||||||
|
border-radius: $fusion-border-radius;
|
||||||
|
padding: $fusion-space-1 $fusion-space-2;
|
||||||
|
font-size: $fusion-font-size-xs;
|
||||||
|
color: $fusion-color-text-secondary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detail/edit panel (right side)
|
||||||
|
&_detail {
|
||||||
|
background: $fusion-color-bg-primary;
|
||||||
|
border-left: 1px solid $fusion-color-border;
|
||||||
|
padding: $fusion-space-6;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: $fusion-font-size-lg;
|
||||||
|
font-weight: $fusion-font-weight-semibold;
|
||||||
|
margin: 0 0 $fusion-space-4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action buttons
|
||||||
|
.btn_fusion {
|
||||||
|
padding: $fusion-space-2 $fusion-space-4;
|
||||||
|
border-radius: $fusion-border-radius;
|
||||||
|
font-size: $fusion-font-size-sm;
|
||||||
|
font-weight: $fusion-font-weight-medium;
|
||||||
|
border: 1px solid $fusion-color-border;
|
||||||
|
background: $fusion-color-bg-primary;
|
||||||
|
color: $fusion-color-text-primary;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all $fusion-transition-fast;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: $fusion-color-bg-tertiary;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.btn_fusion_primary {
|
||||||
|
background: $fusion-color-accent;
|
||||||
|
border-color: $fusion-color-accent;
|
||||||
|
color: $fusion-color-text-inverse;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: $fusion-color-accent-hover;
|
||||||
|
border-color: $fusion-color-accent-hover;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
fusion_accounting_bank_rec/static/src/scss/dark_mode.scss
Normal file
64
fusion_accounting_bank_rec/static/src/scss/dark_mode.scss
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
@import "variables";
|
||||||
|
|
||||||
|
// Activated via [data-color-scheme="dark"] on body or any ancestor.
|
||||||
|
// Mirrors Odoo's standard dark-mode trigger pattern.
|
||||||
|
|
||||||
|
[data-color-scheme="dark"] .o_fusion_bank_rec {
|
||||||
|
background: #1f2937;
|
||||||
|
color: #f9fafb;
|
||||||
|
|
||||||
|
&_header,
|
||||||
|
&_line,
|
||||||
|
&_detail {
|
||||||
|
background: #111827;
|
||||||
|
border-color: #374151;
|
||||||
|
color: #f9fafb;
|
||||||
|
}
|
||||||
|
|
||||||
|
&_line {
|
||||||
|
&:hover { border-color: #60a5fa; }
|
||||||
|
&.o_fusion_selected {
|
||||||
|
background: #1e3a8a;
|
||||||
|
border-color: #60a5fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
&_header .o_fusion_date,
|
||||||
|
&_body { color: #d1d5db; }
|
||||||
|
|
||||||
|
.o_fusion_attachments_badge {
|
||||||
|
background: #374151;
|
||||||
|
color: #d1d5db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn_fusion {
|
||||||
|
background: #374151;
|
||||||
|
border-color: #4b5563;
|
||||||
|
color: #f9fafb;
|
||||||
|
|
||||||
|
&:hover { background: #4b5563; }
|
||||||
|
|
||||||
|
&.btn_fusion_primary {
|
||||||
|
background: #3b82f6;
|
||||||
|
border-color: #3b82f6;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #2563eb;
|
||||||
|
border-color: #2563eb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AI suggestion strip — soften background colors for dark mode
|
||||||
|
.o_fusion_ai_suggestion {
|
||||||
|
&[data-band="high"] { background: rgba(16, 185, 129, 0.1); }
|
||||||
|
&[data-band="medium"] { background: rgba(245, 158, 11, 0.1); }
|
||||||
|
&[data-band="low"] { background: rgba(239, 68, 68, 0.1); }
|
||||||
|
&[data-band="none"] { background: rgba(156, 163, 175, 0.1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_fusion_alternatives_panel {
|
||||||
|
background: #1f2937;
|
||||||
|
border-color: #374151;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank reconciliation service.
|
||||||
|
*
|
||||||
|
* Central data layer + reactive state for the OWL bank-rec widget.
|
||||||
|
* Components inject this service via useService("fusion_bank_reconciliation")
|
||||||
|
* and read/write state through its methods.
|
||||||
|
*
|
||||||
|
* Wraps the 10 JSON-RPC endpoints from controllers/bank_rec_controller.py.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { reactive, useState, EventBus } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { browser } from "@web/core/browser/browser";
|
||||||
|
|
||||||
|
const ENDPOINT_BASE = "/fusion/bank_rec";
|
||||||
|
|
||||||
|
export class BankReconciliationService {
|
||||||
|
constructor(env, services) {
|
||||||
|
this.env = env;
|
||||||
|
this.rpc = services.rpc;
|
||||||
|
this.notification = services.notification;
|
||||||
|
this.orm = services.orm;
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Enterprise-compat surface (mirrored OWL components rely on this)
|
||||||
|
// ============================================================
|
||||||
|
// Mirrored components from account_accountant expect these
|
||||||
|
// attributes/methods on the service. Most are implemented as
|
||||||
|
// stubs that no-op or return sensible defaults; structural
|
||||||
|
// parity now, behaviour wired up in fusion-only Tasks 34-36.
|
||||||
|
this.bus = new EventBus();
|
||||||
|
this.chatterState = reactive({
|
||||||
|
visible: this._readChatterPref(),
|
||||||
|
statementLine: null,
|
||||||
|
});
|
||||||
|
this.reconcileCountPerPartnerId = reactive({});
|
||||||
|
this.reconcileModelPerStatementLineId = reactive({});
|
||||||
|
|
||||||
|
// Reactive state — components depend on it via useState/reactive
|
||||||
|
this.state = reactive({
|
||||||
|
journalId: null,
|
||||||
|
companyId: null,
|
||||||
|
unreconciledCount: 0,
|
||||||
|
totalPendingAmount: 0,
|
||||||
|
lines: [],
|
||||||
|
lineCache: {}, // {lineId: {detail, suggestions, attachments}}
|
||||||
|
selectedLineId: null,
|
||||||
|
isLoading: false,
|
||||||
|
isReconciling: false,
|
||||||
|
offset: 0,
|
||||||
|
limit: 50,
|
||||||
|
filters: {},
|
||||||
|
// Cache of recently-applied actions for optimistic UI
|
||||||
|
recentActions: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Initialization
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async initForJournal(journalId, companyId) {
|
||||||
|
this.state.journalId = journalId;
|
||||||
|
this.state.companyId = companyId;
|
||||||
|
this.state.isLoading = true;
|
||||||
|
try {
|
||||||
|
const stateInfo = await this.rpc(`${ENDPOINT_BASE}/get_state`, {
|
||||||
|
journal_id: journalId, company_id: companyId,
|
||||||
|
});
|
||||||
|
this.state.unreconciledCount = stateInfo.unreconciled_count;
|
||||||
|
this.state.totalPendingAmount = stateInfo.total_pending_amount;
|
||||||
|
await this.loadLines({ reset: true });
|
||||||
|
} finally {
|
||||||
|
this.state.isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// List + pagination
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async loadLines({ reset = false } = {}) {
|
||||||
|
if (reset) {
|
||||||
|
this.state.offset = 0;
|
||||||
|
this.state.lines = [];
|
||||||
|
}
|
||||||
|
this.state.isLoading = true;
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/list_unreconciled`, {
|
||||||
|
journal_id: this.state.journalId,
|
||||||
|
company_id: this.state.companyId,
|
||||||
|
limit: this.state.limit,
|
||||||
|
offset: this.state.offset,
|
||||||
|
...this.state.filters,
|
||||||
|
});
|
||||||
|
if (reset) {
|
||||||
|
this.state.lines = result.lines;
|
||||||
|
} else {
|
||||||
|
this.state.lines = [...this.state.lines, ...result.lines];
|
||||||
|
}
|
||||||
|
this.state.unreconciledCount = result.total;
|
||||||
|
} finally {
|
||||||
|
this.state.isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadMore() {
|
||||||
|
this.state.offset += this.state.limit;
|
||||||
|
await this.loadLines({ reset: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
setFilter(key, value) {
|
||||||
|
if (value === null || value === undefined || value === "") {
|
||||||
|
delete this.state.filters[key];
|
||||||
|
} else {
|
||||||
|
this.state.filters[key] = value;
|
||||||
|
}
|
||||||
|
this.loadLines({ reset: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Line detail + suggestions
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async selectLine(lineId) {
|
||||||
|
this.state.selectedLineId = lineId;
|
||||||
|
if (!this.state.lineCache[lineId]) {
|
||||||
|
await this.loadLineDetail(lineId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadLineDetail(lineId) {
|
||||||
|
const detail = await this.rpc(`${ENDPOINT_BASE}/get_line_detail`, {
|
||||||
|
statement_line_id: lineId,
|
||||||
|
});
|
||||||
|
this.state.lineCache[lineId] = detail;
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshLineDetail(lineId) {
|
||||||
|
delete this.state.lineCache[lineId];
|
||||||
|
return await this.loadLineDetail(lineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async suggestMatches(lineIds, limitPerLine = 3) {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/suggest_matches`, {
|
||||||
|
statement_line_ids: lineIds,
|
||||||
|
limit_per_line: limitPerLine,
|
||||||
|
});
|
||||||
|
// Refresh cache for each line
|
||||||
|
for (const lineId of lineIds) {
|
||||||
|
await this.refreshLineDetail(lineId);
|
||||||
|
}
|
||||||
|
return result.suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Reconciliation actions
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async acceptSuggestion(suggestionId) {
|
||||||
|
this.state.isReconciling = true;
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/accept_suggestion`, {
|
||||||
|
suggestion_id: suggestionId,
|
||||||
|
});
|
||||||
|
this._removeReconciledLineFromState(this.state.selectedLineId);
|
||||||
|
this.state.unreconciledCount = result.unreconciled_count_after;
|
||||||
|
this.notification.add("Reconciliation accepted", { type: "success" });
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
this.notification.add(`Accept failed: ${err.message || err}`, { type: "danger" });
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
this.state.isReconciling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async reconcileManual(statementLineId, againstMoveLineIds) {
|
||||||
|
this.state.isReconciling = true;
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/reconcile_manual`, {
|
||||||
|
statement_line_id: statementLineId,
|
||||||
|
against_move_line_ids: againstMoveLineIds,
|
||||||
|
});
|
||||||
|
this._removeReconciledLineFromState(statementLineId);
|
||||||
|
this.notification.add("Reconciled", { type: "success" });
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
this.notification.add(`Reconcile failed: ${err.message || err}`, { type: "danger" });
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
this.state.isReconciling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async unreconcile(partialReconcileIds) {
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/unreconcile`, {
|
||||||
|
partial_reconcile_ids: partialReconcileIds,
|
||||||
|
});
|
||||||
|
// Reload list since unreconciled lines come back
|
||||||
|
await this.loadLines({ reset: true });
|
||||||
|
this.notification.add("Unreconciled", { type: "info" });
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
this.notification.add(`Unreconcile failed: ${err.message || err}`, { type: "danger" });
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeOff({ statementLineId, accountId, amount, label, taxId = null }) {
|
||||||
|
this.state.isReconciling = true;
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/write_off`, {
|
||||||
|
statement_line_id: statementLineId,
|
||||||
|
account_id: accountId,
|
||||||
|
amount: amount,
|
||||||
|
label: label,
|
||||||
|
tax_id: taxId,
|
||||||
|
});
|
||||||
|
this._removeReconciledLineFromState(statementLineId);
|
||||||
|
this.notification.add("Write-off applied", { type: "success" });
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
this.notification.add(`Write-off failed: ${err.message || err}`, { type: "danger" });
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
this.state.isReconciling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async bulkReconcile(statementLineIds, strategy = "auto") {
|
||||||
|
this.state.isReconciling = true;
|
||||||
|
try {
|
||||||
|
const result = await this.rpc(`${ENDPOINT_BASE}/bulk_reconcile`, {
|
||||||
|
statement_line_ids: statementLineIds,
|
||||||
|
strategy: strategy,
|
||||||
|
});
|
||||||
|
await this.loadLines({ reset: true });
|
||||||
|
const msg = `${result.reconciled_count} reconciled, ${result.skipped} skipped`;
|
||||||
|
this.notification.add(msg, { type: "success" });
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
this.notification.add(`Bulk failed: ${err.message || err}`, { type: "danger" });
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
this.state.isReconciling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Partner history (right-side panel)
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async getPartnerHistory(partnerId, limit = 20) {
|
||||||
|
return await this.rpc(`${ENDPOINT_BASE}/get_partner_history`, {
|
||||||
|
partner_id: partnerId,
|
||||||
|
limit: limit,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Helpers
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
_removeReconciledLineFromState(lineId) {
|
||||||
|
if (!lineId) return;
|
||||||
|
this.state.lines = this.state.lines.filter((l) => l.id !== lineId);
|
||||||
|
if (this.state.selectedLineId === lineId) {
|
||||||
|
this.state.selectedLineId = null;
|
||||||
|
}
|
||||||
|
delete this.state.lineCache[lineId];
|
||||||
|
if (this.state.unreconciledCount > 0) {
|
||||||
|
this.state.unreconciledCount -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confidence band helper for templates
|
||||||
|
getBandClass(line) {
|
||||||
|
return `band-${line.fusion_confidence_band || "none"}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Enterprise-compat methods (stubs — wired up later)
|
||||||
|
// ============================================================
|
||||||
|
// The following surface is required by mirrored components from
|
||||||
|
// account_accountant. They are primarily no-ops or thin wrappers
|
||||||
|
// around the legacy/V19 ORM. Phase 1 prioritizes structural parity;
|
||||||
|
// fusion-only Tasks 34-36 will replace these with native
|
||||||
|
// implementations driven by our JSON-RPC endpoints.
|
||||||
|
|
||||||
|
_readChatterPref() {
|
||||||
|
try {
|
||||||
|
return (
|
||||||
|
JSON.parse(
|
||||||
|
browser.sessionStorage.getItem("isFusionBankRecChatterOpened")
|
||||||
|
) ?? false
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleChatter() {
|
||||||
|
this.chatterState.visible = !this.chatterState.visible;
|
||||||
|
try {
|
||||||
|
browser.sessionStorage.setItem(
|
||||||
|
"isFusionBankRecChatterOpened",
|
||||||
|
this.chatterState.visible
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
// Session storage unavailable — non-fatal.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openChatter() {
|
||||||
|
this.chatterState.visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectStatementLine(statementLine) {
|
||||||
|
this.chatterState.statementLine = statementLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadChatter() {
|
||||||
|
this.bus.trigger("MAIL:RELOAD-THREAD", {
|
||||||
|
model: "account.move",
|
||||||
|
id: this.statementLineMoveId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async computeReconcileLineCountPerPartnerId(records) {
|
||||||
|
// Stub: real impl to be added in fusion-only task.
|
||||||
|
// Components call this after partner edits to refresh the per-partner
|
||||||
|
// count badge. Returning empty here keeps the badge silent.
|
||||||
|
if (!this.orm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const partnerIds = (records || [])
|
||||||
|
.map((r) => r?.data?.partner_id?.id)
|
||||||
|
.filter(Boolean);
|
||||||
|
if (!partnerIds.length) {
|
||||||
|
this.reconcileCountPerPartnerId = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Best-effort: keep a zero map so templates don't blow up.
|
||||||
|
const out = {};
|
||||||
|
for (const pid of partnerIds) {
|
||||||
|
out[pid] = this.reconcileCountPerPartnerId[pid] ?? 0;
|
||||||
|
}
|
||||||
|
this.reconcileCountPerPartnerId = out;
|
||||||
|
} catch {
|
||||||
|
// Non-fatal; templates fall back to defaults.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async computeAvailableReconcileModels(records) {
|
||||||
|
// Stub: components show these as quick-action buttons. Empty for now.
|
||||||
|
const out = {};
|
||||||
|
for (const r of records || []) {
|
||||||
|
const id = r?.data?.id;
|
||||||
|
if (id) {
|
||||||
|
out[id] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.reconcileModelPerStatementLineId = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAvailableReconcileModels(recordId) {
|
||||||
|
if (recordId) {
|
||||||
|
this.reconcileModelPerStatementLineId[recordId] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async reloadRecords(records) {
|
||||||
|
await Promise.all(
|
||||||
|
(records || []).map((record) => record?.load ? record.load() : null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get statementLineMove() {
|
||||||
|
return this.chatterState.statementLine?.data?.move_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get statementLineMoveId() {
|
||||||
|
return this.statementLineMove?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get statementLine() {
|
||||||
|
return this.chatterState.statementLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
get statementLineId() {
|
||||||
|
return this.statementLine?.data?.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const bankReconciliationService = {
|
||||||
|
dependencies: ["rpc", "notification", "orm"],
|
||||||
|
start(env, services) {
|
||||||
|
return new BankReconciliationService(env, services);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
registry.category("services").add("fusion_bank_reconciliation", bankReconciliationService);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for OWL components mirrored from Enterprise.
|
||||||
|
*
|
||||||
|
* Enterprise's components import `useBankReconciliation` from
|
||||||
|
* `../bank_reconciliation_service`; we expose the same hook here so
|
||||||
|
* mirrored code works unmodified after the relative-import rewrite.
|
||||||
|
*/
|
||||||
|
export function useBankReconciliation() {
|
||||||
|
return useState(useService("fusion_bank_reconciliation"));
|
||||||
|
}
|
||||||
109
fusion_accounting_bank_rec/static/src/tours/bank_rec_tours.js
Normal file
109
fusion_accounting_bank_rec/static/src/tours/bank_rec_tours.js
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5 OWL tours for fusion_accounting_bank_rec smoke testing.
|
||||||
|
*
|
||||||
|
* Each tour scripts a user interaction with the bank-rec widget and
|
||||||
|
* is invoked from Python via HttpCase.start_tour(). Useful for catching
|
||||||
|
* UI regressions that asset-bundle compilation alone won't catch.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Tour 1: Open the kanban widget and confirm it loads
|
||||||
|
registry.category("web_tour.tours").add("fusion_bank_rec_smoke", {
|
||||||
|
test: true,
|
||||||
|
url: "/odoo/action-fusion_accounting_bank_rec.action_fusion_bank_rec_widget",
|
||||||
|
steps: () => [
|
||||||
|
{
|
||||||
|
content: "Wait for header to appear",
|
||||||
|
trigger: ".o_fusion_bank_rec_header h1:contains(Bank Reconciliation)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Confirm stats are visible",
|
||||||
|
trigger: ".o_fusion_stats",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tour 2: Select a line and confirm detail panel loads
|
||||||
|
registry.category("web_tour.tours").add("fusion_bank_rec_select_line", {
|
||||||
|
test: true,
|
||||||
|
url: "/odoo/action-fusion_accounting_bank_rec.action_fusion_bank_rec_widget",
|
||||||
|
steps: () => [
|
||||||
|
{
|
||||||
|
content: "Wait for at least one line card",
|
||||||
|
trigger: ".o_fusion_bank_rec_line:first",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Click the first line",
|
||||||
|
trigger: ".o_fusion_bank_rec_line:first",
|
||||||
|
run: "click",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Detail panel shows selected line",
|
||||||
|
trigger: ".o_fusion_bank_rec_detail h2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tour 3: Trigger AI suggestion and accept
|
||||||
|
registry.category("web_tour.tours").add("fusion_bank_rec_accept_suggestion", {
|
||||||
|
test: true,
|
||||||
|
url: "/odoo/action-fusion_accounting_bank_rec.action_fusion_bank_rec_widget",
|
||||||
|
steps: () => [
|
||||||
|
{
|
||||||
|
content: "Click first line with a partner",
|
||||||
|
trigger: ".o_fusion_bank_rec_line:has(.o_fusion_partner):first",
|
||||||
|
run: "click",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Click 'Get AI suggestions' button",
|
||||||
|
trigger: ".o_fusion_bank_rec_detail .btn_fusion_primary:contains(Get AI)",
|
||||||
|
run: "click",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Wait for at least one suggestion to appear",
|
||||||
|
trigger: ".o_fusion_ai_suggestion",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tour 4: Open auto-reconcile wizard
|
||||||
|
registry.category("web_tour.tours").add("fusion_bank_rec_auto_reconcile_wizard", {
|
||||||
|
test: true,
|
||||||
|
url: "/odoo/action-fusion_accounting_bank_rec.action_fusion_auto_reconcile_wizard",
|
||||||
|
steps: () => [
|
||||||
|
{
|
||||||
|
content: "Wizard form opens",
|
||||||
|
trigger: ".modal-dialog .o_form_view",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Strategy field exists",
|
||||||
|
trigger: ".modal-dialog [name='strategy']",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: "Close wizard",
|
||||||
|
trigger: ".modal-dialog .btn-secondary",
|
||||||
|
run: "click",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tour 5: Load more (pagination)
|
||||||
|
registry.category("web_tour.tours").add("fusion_bank_rec_load_more", {
|
||||||
|
test: true,
|
||||||
|
url: "/odoo/action-fusion_accounting_bank_rec.action_fusion_bank_rec_widget",
|
||||||
|
steps: () => [
|
||||||
|
{
|
||||||
|
content: "Wait for kanban container",
|
||||||
|
trigger: ".o_fusion_bank_rec",
|
||||||
|
},
|
||||||
|
// Pagination button only appears if there are more lines than `limit`.
|
||||||
|
// This tour is a no-op if the dataset is small — that's fine for smoke.
|
||||||
|
{
|
||||||
|
content: "Confirm app loaded (regardless of pagination state)",
|
||||||
|
trigger: ".o_fusion_bank_rec_header h1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecKanbanController">
|
||||||
|
<div class="o_fusion_bank_rec">
|
||||||
|
<div class="o_fusion_bank_rec_header">
|
||||||
|
<div>
|
||||||
|
<h1>Bank Reconciliation</h1>
|
||||||
|
<div t-if="state.journalId" class="text-muted">
|
||||||
|
Journal #<t t-esc="state.journalId"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_stats">
|
||||||
|
<div>
|
||||||
|
Unreconciled:
|
||||||
|
<span class="stat-value"><t t-esc="state.unreconciledCount"/></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
Total pending:
|
||||||
|
<span class="stat-value">
|
||||||
|
$<t t-esc="formatCurrency(state.totalPendingAmount)"/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex" style="gap: 1rem; padding: 1rem;">
|
||||||
|
<div style="flex: 1 1 60%; max-width: 60%;">
|
||||||
|
<div t-if="state.isLoading" class="text-center p-4 text-muted">
|
||||||
|
Loading…
|
||||||
|
</div>
|
||||||
|
<div t-elif="state.lines.length === 0" class="text-center p-4 text-muted">
|
||||||
|
Nothing to reconcile.
|
||||||
|
</div>
|
||||||
|
<div t-else="">
|
||||||
|
<BankRecLineCard
|
||||||
|
t-foreach="state.lines"
|
||||||
|
t-as="line"
|
||||||
|
t-key="line.id"
|
||||||
|
line="line"
|
||||||
|
selected="state.selectedLineId === line.id"
|
||||||
|
onSelect="() => onSelectLine(line.id)"
|
||||||
|
formatCurrency="formatCurrency.bind(this)"
|
||||||
|
/>
|
||||||
|
<div t-if="state.lines.length lt state.unreconciledCount"
|
||||||
|
class="text-center mt-3">
|
||||||
|
<button class="btn_fusion" t-on-click="onLoadMore">
|
||||||
|
Load more
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="flex: 1 1 40%; max-width: 40%;" class="o_fusion_bank_rec_detail">
|
||||||
|
<t t-if="state.selectedLineId">
|
||||||
|
<t t-set="detail" t-value="state.lineCache[state.selectedLineId]"/>
|
||||||
|
<div t-if="!detail" class="text-muted">Loading detail…</div>
|
||||||
|
<div t-else="">
|
||||||
|
<h2>
|
||||||
|
<t t-esc="detail.line.payment_ref || 'No reference'"/>
|
||||||
|
</h2>
|
||||||
|
<div class="text-muted mb-3">
|
||||||
|
<span><t t-esc="detail.line.date"/></span>
|
||||||
|
<span class="ms-2">
|
||||||
|
$<t t-esc="formatCurrency(detail.line.amount)"/>
|
||||||
|
</span>
|
||||||
|
<span t-if="detail.line.partner_name" class="ms-2">
|
||||||
|
· <t t-esc="detail.line.partner_name"/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div t-if="detail.suggestions.length === 0">
|
||||||
|
<button class="btn_fusion btn_fusion_primary"
|
||||||
|
t-on-click="() => onSuggestForLine(detail.line.id)">
|
||||||
|
Get AI suggestions
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div t-else="">
|
||||||
|
<h5>AI Suggestions</h5>
|
||||||
|
<div t-foreach="detail.suggestions" t-as="sug" t-key="sug.id"
|
||||||
|
class="o_fusion_ai_suggestion"
|
||||||
|
t-att-data-band="confidenceBandLabel(sug.confidence >= 0.85 ? 'high' : sug.confidence >= 0.6 ? 'medium' : sug.confidence > 0 ? 'low' : 'none').toLowerCase()">
|
||||||
|
<div class="o_fusion_confidence_badge">
|
||||||
|
<t t-esc="(sug.confidence * 100).toFixed(0)"/>%
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_suggestion_text">
|
||||||
|
<div><t t-esc="sug.reasoning"/></div>
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_suggestion_actions">
|
||||||
|
<button class="btn_fusion btn_fusion_primary"
|
||||||
|
t-on-click="() => onAcceptSuggestion(sug.id)">
|
||||||
|
Accept
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
<t t-else="">
|
||||||
|
<div class="text-muted">
|
||||||
|
Select a bank line on the left to see details.
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
<t t-name="fusion_accounting_bank_rec.BankRecLineCard">
|
||||||
|
<div class="o_fusion_bank_rec_line"
|
||||||
|
t-att-class="props.selected ? 'o_fusion_selected' : ''"
|
||||||
|
t-on-click="props.onSelect">
|
||||||
|
<div class="o_fusion_bank_rec_line_header">
|
||||||
|
<div class="o_fusion_amount" t-att-class="props.line.amount lt 0 ? 'negative' : ''">
|
||||||
|
$<t t-esc="props.formatCurrency(props.line.amount)"/>
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_date">
|
||||||
|
<t t-esc="props.line.date"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="o_fusion_bank_rec_line_body">
|
||||||
|
<span t-if="props.line.partner_name" class="o_fusion_partner">
|
||||||
|
<t t-esc="props.line.partner_name"/>
|
||||||
|
</span>
|
||||||
|
<span class="o_fusion_memo">
|
||||||
|
<t t-esc="props.line.payment_ref || 'No memo'"/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div t-if="props.line.attachment_count" class="o_fusion_attachments_badge">
|
||||||
|
📎 <t t-esc="props.line.attachment_count"/>
|
||||||
|
</div>
|
||||||
|
<div t-if="props.line.fusion_confidence_band and props.line.fusion_confidence_band !== 'none'"
|
||||||
|
t-att-class="'o_fusion_ai_suggestion ' + 'band-' + props.line.fusion_confidence_band"
|
||||||
|
t-att-data-band="props.line.fusion_confidence_band">
|
||||||
|
<div class="o_fusion_confidence_badge">
|
||||||
|
AI Suggestion Available
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
|
||||||
|
</templates>
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank reconciliation kanban controller.
|
||||||
|
*
|
||||||
|
* Top-level OWL component for the fusion bank-rec widget. Hosts:
|
||||||
|
* - Header bar (journal name, unreconciled count, total pending amount)
|
||||||
|
* - Left column: list of unreconciled bank line cards
|
||||||
|
* - Right column: detail panel for the selected line
|
||||||
|
*
|
||||||
|
* Reads journal_id + company_id from action context. Wires up the
|
||||||
|
* fusion_bank_reconciliation service for all data + reactivity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component, useState, onWillStart } from "@odoo/owl";
|
||||||
|
import { useService } from "@web/core/utils/hooks";
|
||||||
|
import { BankRecLineCard } from "./bank_rec_kanban_renderer";
|
||||||
|
|
||||||
|
export class BankRecKanbanController extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecKanbanController";
|
||||||
|
static components = { BankRecLineCard };
|
||||||
|
static props = {
|
||||||
|
action: { type: Object, optional: true },
|
||||||
|
actionId: { type: [Number, String], optional: true },
|
||||||
|
className: { type: String, optional: true },
|
||||||
|
"*": true,
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.bankRec = useService("fusion_bank_reconciliation");
|
||||||
|
this.notification = useService("notification");
|
||||||
|
this.state = useState(this.bankRec.state);
|
||||||
|
|
||||||
|
const ctx = this.props.action?.context || {};
|
||||||
|
const journalId = ctx.default_journal_id || ctx.active_id;
|
||||||
|
const companyId = ctx.allowed_company_ids?.[0]
|
||||||
|
|| this.env.services.user?.context?.allowed_company_ids?.[0];
|
||||||
|
|
||||||
|
onWillStart(async () => {
|
||||||
|
if (journalId && companyId) {
|
||||||
|
await this.bankRec.initForJournal(journalId, companyId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectLine(lineId) {
|
||||||
|
this.bankRec.selectLine(lineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onLoadMore() {
|
||||||
|
await this.bankRec.loadMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
async onSuggestForLine(lineId) {
|
||||||
|
await this.bankRec.suggestMatches([lineId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onAcceptSuggestion(suggestionId) {
|
||||||
|
await this.bankRec.acceptSuggestion(suggestionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onUnreconcile(partialIds) {
|
||||||
|
await this.bankRec.unreconcile(partialIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
formatCurrency(amount) {
|
||||||
|
return new Intl.NumberFormat(undefined, {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
}).format(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
confidenceBandLabel(band) {
|
||||||
|
return {
|
||||||
|
high: "High",
|
||||||
|
medium: "Medium",
|
||||||
|
low: "Low",
|
||||||
|
none: "None",
|
||||||
|
}[band] || "—";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank reconciliation line-card renderer.
|
||||||
|
*
|
||||||
|
* Renders one unreconciled bank line as a card in the kanban list.
|
||||||
|
* Owned by BankRecKanbanController; receives line + selected flag as props.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from "@odoo/owl";
|
||||||
|
|
||||||
|
export class BankRecLineCard extends Component {
|
||||||
|
static template = "fusion_accounting_bank_rec.BankRecLineCard";
|
||||||
|
static props = {
|
||||||
|
line: { type: Object },
|
||||||
|
selected: { type: Boolean, optional: true },
|
||||||
|
onSelect: { type: Function },
|
||||||
|
formatCurrency: { type: Function },
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom view type "fusion_bank_rec_kanban" — registers the controller
|
||||||
|
* with the views registry so window actions can specify
|
||||||
|
* <field name="view_mode">fusion_bank_rec_kanban</field>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { registry } from "@web/core/registry";
|
||||||
|
import { BankRecKanbanController } from "./bank_rec_kanban_controller";
|
||||||
|
|
||||||
|
export const fusionBankRecKanbanView = {
|
||||||
|
type: "fusion_bank_rec_kanban",
|
||||||
|
Controller: BankRecKanbanController,
|
||||||
|
display_name: "Bank Reconciliation",
|
||||||
|
icon: "fa-exchange",
|
||||||
|
multiRecord: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
registry.category("views").add("fusion_bank_rec_kanban", fusionBankRecKanbanView);
|
||||||
@@ -9,3 +9,17 @@ from . import test_reconcile_engine_unit
|
|||||||
from . import test_reconcile_engine_property
|
from . import test_reconcile_engine_property
|
||||||
from . import test_factories
|
from . import test_factories
|
||||||
from . import test_reconcile_engine_integration
|
from . import test_reconcile_engine_integration
|
||||||
|
from . import test_bank_rec_prompt
|
||||||
|
from . import test_bank_rec_adapter
|
||||||
|
from . import test_bank_rec_tools
|
||||||
|
from . import test_legacy_tools_refactor
|
||||||
|
from . import test_mv_unreconciled
|
||||||
|
from . import test_cron_methods
|
||||||
|
from . import test_controller
|
||||||
|
from . import test_auto_reconcile_wizard
|
||||||
|
from . import test_bulk_reconcile_wizard
|
||||||
|
from . import test_migration_round_trip
|
||||||
|
from . import test_coexistence
|
||||||
|
from . import test_bank_rec_tours
|
||||||
|
from . import test_performance_benchmarks
|
||||||
|
from . import test_local_llm_compat
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
"""Tests for fusion.auto.reconcile.wizard."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestAutoReconcileWizard(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Auto Wizard Partner'})
|
||||||
|
self.journal = f.make_bank_journal(self.env, name='Auto Bank', code='AUBK')
|
||||||
|
|
||||||
|
def test_wizard_runs_and_reconciles_matchable_lines(self):
|
||||||
|
statement = f.make_bank_statement(self.env, journal=self.journal)
|
||||||
|
for amount in [100.00, 200.00]:
|
||||||
|
f.make_invoice(self.env, partner=self.partner, amount=amount)
|
||||||
|
f.make_bank_line(
|
||||||
|
self.env, statement=statement, amount=amount, partner=self.partner)
|
||||||
|
|
||||||
|
wizard = self.env['fusion.auto.reconcile.wizard'].create({
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'strategy': 'auto',
|
||||||
|
'only_with_partner': True,
|
||||||
|
})
|
||||||
|
wizard.action_run()
|
||||||
|
self.assertEqual(wizard.state, 'done')
|
||||||
|
self.assertGreaterEqual(wizard.reconciled_count, 2)
|
||||||
|
|
||||||
|
def test_wizard_filters_by_date_range(self):
|
||||||
|
wizard = self.env['fusion.auto.reconcile.wizard'].create({
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'date_from': '2099-01-01',
|
||||||
|
'date_to': '2099-12-31',
|
||||||
|
'strategy': 'auto',
|
||||||
|
})
|
||||||
|
wizard.action_run()
|
||||||
|
self.assertEqual(wizard.reconciled_count, 0)
|
||||||
|
|
||||||
|
def test_wizard_skips_when_only_with_partner_excludes_orphans(self):
|
||||||
|
statement = f.make_bank_statement(self.env, journal=self.journal)
|
||||||
|
f.make_bank_line(self.env, statement=statement, amount=999, partner=None)
|
||||||
|
wizard = self.env['fusion.auto.reconcile.wizard'].create({
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'strategy': 'auto',
|
||||||
|
'only_with_partner': True,
|
||||||
|
})
|
||||||
|
wizard.action_run()
|
||||||
|
self.assertEqual(wizard.reconciled_count, 0)
|
||||||
81
fusion_accounting_bank_rec/tests/test_bank_rec_adapter.py
Normal file
81
fusion_accounting_bank_rec/tests/test_bank_rec_adapter.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
"""Tests for BankRecAdapter's fusion paths."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from odoo.addons.fusion_accounting_ai.services.data_adapters.bank_rec import BankRecAdapter
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestBankRecAdapter(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Adapter Test Partner'})
|
||||||
|
self.adapter = BankRecAdapter(self.env)
|
||||||
|
|
||||||
|
def test_list_unreconciled_via_fusion_returns_base_fields(self):
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=100.00, partner=self.partner, memo='Adapter base test')
|
||||||
|
result = self.adapter.list_unreconciled_via_fusion(
|
||||||
|
company_id=self.env.company.id, limit=50)
|
||||||
|
ours = [r for r in result if r['id'] == bank_line.id]
|
||||||
|
self.assertEqual(len(ours), 1)
|
||||||
|
row = ours[0]
|
||||||
|
for f_name in ['id', 'date', 'payment_ref', 'amount', 'partner_id', 'journal_id']:
|
||||||
|
self.assertIn(f_name, row)
|
||||||
|
self.assertIn('fusion_top_suggestion_id', row)
|
||||||
|
self.assertIn('fusion_confidence_band', row)
|
||||||
|
self.assertIn('attachment_count', row)
|
||||||
|
|
||||||
|
def test_list_unreconciled_via_community_omits_fusion_fields(self):
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=200.00, partner=self.partner)
|
||||||
|
result = self.adapter.list_unreconciled_via_community(
|
||||||
|
company_id=self.env.company.id, limit=50)
|
||||||
|
ours = [r for r in result if r['id'] == bank_line.id]
|
||||||
|
self.assertEqual(len(ours), 1)
|
||||||
|
self.assertNotIn('fusion_top_suggestion_id', ours[0])
|
||||||
|
|
||||||
|
def test_suggest_matches_via_fusion_returns_dict(self):
|
||||||
|
partner = self.env['res.partner'].create({'name': 'Suggest Adapter'})
|
||||||
|
invoice = f.make_invoice(self.env, partner=partner, amount=350.00)
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=350.00, partner=partner)
|
||||||
|
result = self.adapter.suggest_matches_via_fusion(
|
||||||
|
statement_line_ids=[bank_line.id], limit_per_line=3)
|
||||||
|
self.assertIsInstance(result, dict)
|
||||||
|
self.assertIn(bank_line.id, result)
|
||||||
|
self.assertGreater(len(result[bank_line.id]), 0)
|
||||||
|
|
||||||
|
def test_suggest_matches_via_community_returns_empty(self):
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=100.00, partner=self.partner)
|
||||||
|
result = self.adapter.suggest_matches_via_community(
|
||||||
|
statement_line_ids=[bank_line.id])
|
||||||
|
self.assertEqual(result, {})
|
||||||
|
|
||||||
|
def test_accept_suggestion_via_fusion(self):
|
||||||
|
partner = self.env['res.partner'].create({'name': 'Accept Adapter'})
|
||||||
|
invoice = f.make_invoice(self.env, partner=partner, amount=425.00)
|
||||||
|
recv_lines = invoice.line_ids.filtered(
|
||||||
|
lambda l: l.account_id.account_type == 'asset_receivable')
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=425.00, partner=partner)
|
||||||
|
sug = f.make_suggestion(
|
||||||
|
self.env, statement_line=bank_line,
|
||||||
|
candidate_move_lines=recv_lines, confidence=0.95)
|
||||||
|
result = self.adapter.accept_suggestion_via_fusion(suggestion_id=sug.id)
|
||||||
|
self.assertIn('partial_ids', result)
|
||||||
|
self.assertGreater(len(result['partial_ids']), 0)
|
||||||
|
|
||||||
|
def test_accept_suggestion_via_community_raises(self):
|
||||||
|
with self.assertRaises(NotImplementedError):
|
||||||
|
self.adapter.accept_suggestion_via_community(suggestion_id=1)
|
||||||
|
|
||||||
|
def test_unreconcile_via_fusion(self):
|
||||||
|
partner = self.env['res.partner'].create({'name': 'Unrec Adapter'})
|
||||||
|
bank_line, recv_lines = f.make_reconcileable_pair(
|
||||||
|
self.env, amount=275.00, partner=partner)
|
||||||
|
rec_result = self.env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
bank_line, against_lines=recv_lines)
|
||||||
|
partial_ids = rec_result['partial_ids']
|
||||||
|
result = self.adapter.unreconcile_via_fusion(
|
||||||
|
partial_reconcile_ids=partial_ids)
|
||||||
|
self.assertIn('unreconciled_line_ids', result)
|
||||||
|
self.assertGreater(len(result['unreconciled_line_ids']), 0)
|
||||||
92
fusion_accounting_bank_rec/tests/test_bank_rec_prompt.py
Normal file
92
fusion_accounting_bank_rec/tests/test_bank_rec_prompt.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
"""Smoke tests for bank_rec_prompt module."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from odoo.addons.fusion_accounting_ai.services.prompts.bank_rec_prompt import (
|
||||||
|
SYSTEM_PROMPT,
|
||||||
|
build_prompt,
|
||||||
|
)
|
||||||
|
from odoo.addons.fusion_accounting_bank_rec.services.confidence_scoring import (
|
||||||
|
ScoredCandidate,
|
||||||
|
)
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestBankRecPrompt(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Prompt Test Partner'})
|
||||||
|
self.bank_line = f.make_bank_line(
|
||||||
|
self.env,
|
||||||
|
amount=1847.50,
|
||||||
|
partner=self.partner,
|
||||||
|
memo='RBC ETF DEP REF 4831',
|
||||||
|
)
|
||||||
|
self.scored = [
|
||||||
|
ScoredCandidate(
|
||||||
|
candidate_id=101,
|
||||||
|
confidence=0.92,
|
||||||
|
reasoning='Exact amount match',
|
||||||
|
score_amount_match=1.0,
|
||||||
|
score_partner_pattern=0.5,
|
||||||
|
score_precedent_similarity=0.85,
|
||||||
|
),
|
||||||
|
ScoredCandidate(
|
||||||
|
candidate_id=102,
|
||||||
|
confidence=0.71,
|
||||||
|
reasoning='Close amount',
|
||||||
|
score_amount_match=0.95,
|
||||||
|
score_partner_pattern=0.5,
|
||||||
|
score_precedent_similarity=0.6,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_system_prompt_requires_json_output(self):
|
||||||
|
self.assertIn('JSON', SYSTEM_PROMPT)
|
||||||
|
self.assertIn('"ranked"', SYSTEM_PROMPT)
|
||||||
|
|
||||||
|
def test_build_prompt_returns_tuple(self):
|
||||||
|
result = build_prompt(self.bank_line, self.scored)
|
||||||
|
self.assertEqual(len(result), 2)
|
||||||
|
system, user = result
|
||||||
|
self.assertIsInstance(system, str)
|
||||||
|
self.assertIsInstance(user, str)
|
||||||
|
|
||||||
|
def test_user_prompt_includes_bank_line_details(self):
|
||||||
|
_, user = build_prompt(self.bank_line, self.scored)
|
||||||
|
self.assertIn('1847.5', user)
|
||||||
|
self.assertIn('RBC ETF DEP REF 4831', user)
|
||||||
|
self.assertIn('Prompt Test Partner', user)
|
||||||
|
|
||||||
|
def test_user_prompt_includes_all_candidates(self):
|
||||||
|
_, user = build_prompt(self.bank_line, self.scored)
|
||||||
|
self.assertIn('candidate_id=101', user)
|
||||||
|
self.assertIn('candidate_id=102', user)
|
||||||
|
|
||||||
|
def test_user_prompt_omits_pattern_section_when_none(self):
|
||||||
|
_, user = build_prompt(self.bank_line, self.scored, pattern=None)
|
||||||
|
self.assertNotIn('PARTNER PATTERN', user)
|
||||||
|
|
||||||
|
def test_user_prompt_includes_pattern_section_when_provided(self):
|
||||||
|
pattern = f.make_pattern(self.env, partner=self.partner, reconcile_count=15)
|
||||||
|
_, user = build_prompt(self.bank_line, self.scored, pattern=pattern)
|
||||||
|
self.assertIn('PARTNER PATTERN', user)
|
||||||
|
self.assertIn('15', user)
|
||||||
|
|
||||||
|
def test_user_prompt_includes_precedents_when_provided(self):
|
||||||
|
from odoo.addons.fusion_accounting_bank_rec.services.precedent_lookup import (
|
||||||
|
PrecedentMatch,
|
||||||
|
)
|
||||||
|
precedents = [
|
||||||
|
PrecedentMatch(
|
||||||
|
precedent_id=1,
|
||||||
|
amount=1847.50,
|
||||||
|
memo_tokens='RBC,ETF',
|
||||||
|
matched_move_line_count=1,
|
||||||
|
similarity_score=0.95,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
_, user = build_prompt(self.bank_line, self.scored, precedents=precedents)
|
||||||
|
self.assertIn('RECENT PRECEDENTS', user)
|
||||||
|
self.assertIn('0.95', user)
|
||||||
84
fusion_accounting_bank_rec/tests/test_bank_rec_tools.py
Normal file
84
fusion_accounting_bank_rec/tests/test_bank_rec_tools.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
"""Smoke tests for the 5 new fusion bank-rec AI tools."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from odoo.addons.fusion_accounting_ai.services.tools import bank_reconciliation as tools
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestFusionBankRecTools(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Tools Test Partner'})
|
||||||
|
|
||||||
|
def test_fusion_suggest_matches_returns_suggestions(self):
|
||||||
|
invoice = f.make_invoice(self.env, partner=self.partner, amount=550.00)
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=550.00, partner=self.partner, memo='Tool test')
|
||||||
|
result = tools.fusion_suggest_matches(self.env, {
|
||||||
|
'statement_line_ids': [bank_line.id],
|
||||||
|
'limit_per_line': 3,
|
||||||
|
})
|
||||||
|
self.assertIn('suggestions', result)
|
||||||
|
self.assertIn('count', result)
|
||||||
|
self.assertGreater(result['count'], 0)
|
||||||
|
|
||||||
|
def test_fusion_accept_suggestion_reconciles(self):
|
||||||
|
invoice = f.make_invoice(self.env, partner=self.partner, amount=625.00)
|
||||||
|
recv_lines = invoice.line_ids.filtered(
|
||||||
|
lambda l: l.account_id.account_type == 'asset_receivable')
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=625.00, partner=self.partner)
|
||||||
|
sug = f.make_suggestion(
|
||||||
|
self.env, statement_line=bank_line,
|
||||||
|
candidate_move_lines=recv_lines, confidence=0.94)
|
||||||
|
result = tools.fusion_accept_suggestion(self.env, {'suggestion_id': sug.id})
|
||||||
|
self.assertEqual(result['status'], 'accepted')
|
||||||
|
self.assertGreater(len(result['partial_ids']), 0)
|
||||||
|
|
||||||
|
def test_fusion_reconcile_bank_line(self):
|
||||||
|
bank_line, recv_lines = f.make_reconcileable_pair(
|
||||||
|
self.env, amount=375.00, partner=self.partner)
|
||||||
|
result = tools.fusion_reconcile_bank_line(self.env, {
|
||||||
|
'statement_line_id': bank_line.id,
|
||||||
|
'against_move_line_ids': recv_lines.ids,
|
||||||
|
})
|
||||||
|
self.assertEqual(result['status'], 'reconciled')
|
||||||
|
self.assertTrue(result['is_reconciled'])
|
||||||
|
|
||||||
|
def test_fusion_unreconcile(self):
|
||||||
|
bank_line, recv_lines = f.make_reconcileable_pair(
|
||||||
|
self.env, amount=275.00, partner=self.partner)
|
||||||
|
rec = self.env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
bank_line, against_lines=recv_lines)
|
||||||
|
partial_ids = rec['partial_ids']
|
||||||
|
result = tools.fusion_unreconcile(self.env, {
|
||||||
|
'partial_reconcile_ids': partial_ids,
|
||||||
|
})
|
||||||
|
self.assertEqual(result['status'], 'unreconciled')
|
||||||
|
self.assertGreater(result['count'], 0)
|
||||||
|
|
||||||
|
def test_fusion_get_pending_suggestions(self):
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=100.00, partner=self.partner)
|
||||||
|
sug = f.make_suggestion(
|
||||||
|
self.env, statement_line=bank_line,
|
||||||
|
candidate_move_lines=self.env['account.move.line'],
|
||||||
|
confidence=0.88, state='pending')
|
||||||
|
result = tools.fusion_get_pending_suggestions(self.env, {})
|
||||||
|
self.assertIn('count', result)
|
||||||
|
self.assertGreater(result['count'], 0)
|
||||||
|
ids = [s['id'] for s in result['suggestions']]
|
||||||
|
self.assertIn(sug.id, ids)
|
||||||
|
|
||||||
|
def test_fusion_get_pending_suggestions_filters_by_min_confidence(self):
|
||||||
|
bank_line = f.make_bank_line(self.env, amount=100.00, partner=self.partner)
|
||||||
|
# One low-confidence suggestion
|
||||||
|
f.make_suggestion(self.env, statement_line=bank_line,
|
||||||
|
confidence=0.30, state='pending')
|
||||||
|
# One high-confidence
|
||||||
|
high = f.make_suggestion(self.env, statement_line=bank_line,
|
||||||
|
confidence=0.95, state='pending')
|
||||||
|
result = tools.fusion_get_pending_suggestions(
|
||||||
|
self.env, {'min_confidence': 0.80})
|
||||||
|
ids = [s['id'] for s in result['suggestions']]
|
||||||
|
self.assertIn(high.id, ids)
|
||||||
42
fusion_accounting_bank_rec/tests/test_bank_rec_tours.py
Normal file
42
fusion_accounting_bank_rec/tests/test_bank_rec_tours.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"""Python wrappers that run the OWL tours via HttpCase.start_tour.
|
||||||
|
|
||||||
|
Tours require an HTTP server + headless browser. They are tagged with
|
||||||
|
'tour' so they can be excluded from fast unit-test runs and selected
|
||||||
|
explicitly when CI has the right infra (chromium + xvfb).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from odoo.tests.common import HttpCase, tagged
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install', 'tour')
|
||||||
|
class TestBankRecTours(HttpCase):
|
||||||
|
|
||||||
|
def test_smoke_tour(self):
|
||||||
|
# Just verify the smoke tour runs without crashing
|
||||||
|
self.start_tour("/odoo", "fusion_bank_rec_smoke", login="admin")
|
||||||
|
|
||||||
|
def test_select_line_tour(self):
|
||||||
|
# Need a bank line to select — create one
|
||||||
|
partner = self.env['res.partner'].create({'name': 'Tour Partner'})
|
||||||
|
journal = self.env['account.journal'].create({
|
||||||
|
'name': 'Tour Bank', 'type': 'bank', 'code': 'TOURB',
|
||||||
|
})
|
||||||
|
statement = self.env['account.bank.statement'].create({
|
||||||
|
'name': 'Tour Stmt', 'journal_id': journal.id,
|
||||||
|
})
|
||||||
|
self.env['account.bank.statement.line'].create({
|
||||||
|
'statement_id': statement.id, 'journal_id': journal.id,
|
||||||
|
'date': '2026-04-19', 'payment_ref': 'Tour line',
|
||||||
|
'amount': 100, 'partner_id': partner.id,
|
||||||
|
})
|
||||||
|
self.start_tour("/odoo", "fusion_bank_rec_select_line", login="admin")
|
||||||
|
|
||||||
|
def test_accept_suggestion_tour(self):
|
||||||
|
# Skip if too slow / dataset issues — tour itself is the smoke
|
||||||
|
self.skipTest("Tour 3 requires AI provider config; skipping in CI smoke")
|
||||||
|
|
||||||
|
def test_auto_reconcile_wizard_tour(self):
|
||||||
|
self.start_tour("/odoo", "fusion_bank_rec_auto_reconcile_wizard", login="admin")
|
||||||
|
|
||||||
|
def test_load_more_tour(self):
|
||||||
|
self.start_tour("/odoo", "fusion_bank_rec_load_more", login="admin")
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
"""Tests for fusion.bulk.reconcile.wizard."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestBulkReconcileWizard(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Bulk Wizard Partner'})
|
||||||
|
self.journal = f.make_bank_journal(self.env, name='Bulk Bank', code='BLKBK')
|
||||||
|
self.statement = f.make_bank_statement(self.env, journal=self.journal)
|
||||||
|
|
||||||
|
def test_wizard_default_picks_active_ids(self):
|
||||||
|
line1 = f.make_bank_line(
|
||||||
|
self.env, statement=self.statement, amount=100, partner=self.partner)
|
||||||
|
line2 = f.make_bank_line(
|
||||||
|
self.env, statement=self.statement, amount=200, partner=self.partner)
|
||||||
|
wizard = self.env['fusion.bulk.reconcile.wizard'].with_context(
|
||||||
|
active_model='account.bank.statement.line',
|
||||||
|
active_ids=[line1.id, line2.id],
|
||||||
|
).create({})
|
||||||
|
self.assertEqual(set(wizard.statement_line_ids.ids), {line1.id, line2.id})
|
||||||
|
self.assertEqual(wizard.selected_count, 2)
|
||||||
|
|
||||||
|
def test_wizard_auto_mode_runs_engine_batch(self):
|
||||||
|
line_ids = []
|
||||||
|
for amount in [110.00, 220.00]:
|
||||||
|
f.make_invoice(self.env, partner=self.partner, amount=amount)
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, statement=self.statement, amount=amount, partner=self.partner)
|
||||||
|
line_ids.append(line.id)
|
||||||
|
wizard = self.env['fusion.bulk.reconcile.wizard'].create({
|
||||||
|
'statement_line_ids': [(6, 0, line_ids)],
|
||||||
|
'mode': 'auto',
|
||||||
|
'strategy': 'auto',
|
||||||
|
})
|
||||||
|
wizard.action_run()
|
||||||
|
self.assertEqual(wizard.state, 'done')
|
||||||
|
self.assertGreaterEqual(wizard.reconciled_count, 2)
|
||||||
86
fusion_accounting_bank_rec/tests/test_coexistence.py
Normal file
86
fusion_accounting_bank_rec/tests/test_coexistence.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
"""Coexistence tests: fusion_accounting_bank_rec menus only visible
|
||||||
|
when Enterprise's account_accountant is absent.
|
||||||
|
|
||||||
|
Strategy: mock the install state by toggling the group's user list directly,
|
||||||
|
then verify the recompute method aligns it with module presence."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestCoexistence(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.group = self.env.ref(
|
||||||
|
'fusion_accounting_core.group_fusion_show_when_enterprise_absent')
|
||||||
|
|
||||||
|
def _account_accountant_installed(self):
|
||||||
|
return bool(self.env['ir.module.module'].sudo().search([
|
||||||
|
('name', '=', 'account_accountant'),
|
||||||
|
('state', '=', 'installed'),
|
||||||
|
]))
|
||||||
|
|
||||||
|
def test_group_exists(self):
|
||||||
|
self.assertTrue(self.group, "Coexistence group must exist")
|
||||||
|
|
||||||
|
def test_recompute_when_enterprise_present(self):
|
||||||
|
"""When account_accountant is installed, group should be empty."""
|
||||||
|
if not self._account_accountant_installed():
|
||||||
|
self.skipTest(
|
||||||
|
"Local DB doesn't have account_accountant installed; "
|
||||||
|
"this test only meaningful in Enterprise-present scenario"
|
||||||
|
)
|
||||||
|
self.env['res.users']._fusion_recompute_coexistence_group()
|
||||||
|
self.assertEqual(
|
||||||
|
len(self.group.user_ids), 0,
|
||||||
|
"Coexistence group should be empty when Enterprise is installed",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_recompute_when_enterprise_absent(self):
|
||||||
|
"""When account_accountant is uninstalled, all internal users get the group."""
|
||||||
|
if self._account_accountant_installed():
|
||||||
|
# Simulate by mocking the enterprise-installed check.
|
||||||
|
with patch.object(
|
||||||
|
type(self.env['ir.module.module']),
|
||||||
|
'_fusion_is_enterprise_accounting_installed',
|
||||||
|
return_value=False,
|
||||||
|
):
|
||||||
|
self.env['res.users']._fusion_recompute_coexistence_group()
|
||||||
|
internal_users = self.env['res.users'].search([
|
||||||
|
('share', '=', False),
|
||||||
|
])
|
||||||
|
self.assertGreater(
|
||||||
|
len(self.group.user_ids & internal_users), 0,
|
||||||
|
"Coexistence group should contain internal users when "
|
||||||
|
"Enterprise is absent",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.env['res.users']._fusion_recompute_coexistence_group()
|
||||||
|
internal = self.env['res.users'].search([('share', '=', False)])
|
||||||
|
self.assertGreater(len(self.group.user_ids & internal), 0)
|
||||||
|
|
||||||
|
def test_menu_has_coexistence_group(self):
|
||||||
|
"""The fusion bank-rec root menu must have the coexistence group attached."""
|
||||||
|
menu = self.env.ref(
|
||||||
|
'fusion_accounting_bank_rec.menu_fusion_bank_rec_root',
|
||||||
|
raise_if_not_found=False,
|
||||||
|
)
|
||||||
|
if not menu:
|
||||||
|
self.skipTest("Menu not yet loaded — Task 42 must run first")
|
||||||
|
# Odoo 19 renamed ir.ui.menu.groups_id -> group_ids; tolerate either.
|
||||||
|
groups_field = getattr(menu, 'group_ids', None) or menu.groups_id
|
||||||
|
self.assertIn(
|
||||||
|
self.group, groups_field,
|
||||||
|
"Menu must require the coexistence group",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_engine_works_regardless_of_coexistence(self):
|
||||||
|
"""The reconcile engine must work even when Enterprise is installed
|
||||||
|
(it's the AI tools/menu that gate; the engine is always available)."""
|
||||||
|
self.assertIn(
|
||||||
|
'fusion.reconcile.engine', self.env.registry,
|
||||||
|
"Engine must always be available when fusion_accounting_bank_rec "
|
||||||
|
"is installed",
|
||||||
|
)
|
||||||
333
fusion_accounting_bank_rec/tests/test_controller.py
Normal file
333
fusion_accounting_bank_rec/tests/test_controller.py
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
"""Tests for the fusion bank-rec HTTP controller (Task 26).
|
||||||
|
|
||||||
|
Uses ``HttpCase`` so we exercise the full Werkzeug stack -- the JSON-RPC
|
||||||
|
dispatcher, auth check, and route resolution all run for real. Tests
|
||||||
|
authenticate as a Fusion Accounting administrator (the realistic role
|
||||||
|
for a user driving the bank-rec widget); a separate test confirms the
|
||||||
|
``auth='user'`` decorator rejects anonymous traffic.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from odoo.tests.common import HttpCase, new_test_user, tagged
|
||||||
|
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestBankRecController(HttpCase):
|
||||||
|
"""End-to-end coverage of the 10 JSON-RPC endpoints."""
|
||||||
|
|
||||||
|
USER_LOGIN = 'ctrl_test_user'
|
||||||
|
USER_PASSWORD = 'ctrl_test_user'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
# group_account_user grants accounting write perms AND auto-implies
|
||||||
|
# fusion_accounting_user via the security XML's implied_ids hook;
|
||||||
|
# group_fusion_accounting_admin grants full CRUD on the fusion
|
||||||
|
# suggestion / precedent / pattern models the engine writes to.
|
||||||
|
self.user = new_test_user(
|
||||||
|
self.env,
|
||||||
|
login=self.USER_LOGIN,
|
||||||
|
password=self.USER_PASSWORD,
|
||||||
|
groups=(
|
||||||
|
'base.group_user,'
|
||||||
|
'account.group_account_user,'
|
||||||
|
'fusion_accounting_core.group_fusion_accounting_admin'
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.partner = self.env['res.partner'].create(
|
||||||
|
{'name': 'Controller Test Partner'})
|
||||||
|
self.journal = f.make_bank_journal(
|
||||||
|
self.env, name='Ctrl Bank', code='CBNK')
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# helpers
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _jsonrpc(self, endpoint, params, *, authenticate=True):
|
||||||
|
"""POST a JSON-RPC envelope to ``/fusion/bank_rec/<endpoint>``.
|
||||||
|
|
||||||
|
Returns the ``result`` dict on success and fails the test if
|
||||||
|
the body has an ``error`` key (so endpoint test failures show
|
||||||
|
the actual server-side exception, not just the HTTP status).
|
||||||
|
"""
|
||||||
|
if authenticate:
|
||||||
|
self.authenticate(self.USER_LOGIN, self.USER_PASSWORD)
|
||||||
|
url = f'/fusion/bank_rec/{endpoint}'
|
||||||
|
body = {
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'method': 'call',
|
||||||
|
'params': params,
|
||||||
|
'id': 1,
|
||||||
|
}
|
||||||
|
response = self.url_open(
|
||||||
|
url,
|
||||||
|
data=json.dumps(body),
|
||||||
|
headers={'Content-Type': 'application/json'},
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
response.status_code, 200,
|
||||||
|
f"Endpoint {endpoint} returned {response.status_code}: "
|
||||||
|
f"{response.text[:300]}")
|
||||||
|
payload = response.json()
|
||||||
|
if 'error' in payload:
|
||||||
|
self.fail(
|
||||||
|
f"Endpoint {endpoint} errored: "
|
||||||
|
f"{json.dumps(payload['error'])[:600]}")
|
||||||
|
return payload.get('result', {})
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 1. get_state
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_get_state(self):
|
||||||
|
result = self._jsonrpc('get_state', {
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'company_id': self.env.company.id,
|
||||||
|
})
|
||||||
|
self.assertIn('journal', result)
|
||||||
|
self.assertEqual(result['journal']['id'], self.journal.id)
|
||||||
|
self.assertIn('unreconciled_count', result)
|
||||||
|
self.assertIn('total_pending_amount', result)
|
||||||
|
self.assertIn('last_statement_date', result)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 2. list_unreconciled
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_list_unreconciled(self):
|
||||||
|
# Reuse a single statement so we don't trip the
|
||||||
|
# (journal_id, name) uniqueness or hit the parent-move autocreate
|
||||||
|
# path twice in the same flush window.
|
||||||
|
statement = f.make_bank_statement(
|
||||||
|
self.env, journal=self.journal, name='List Stmt')
|
||||||
|
f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, statement=statement,
|
||||||
|
amount=100, partner=self.partner, memo='List 1')
|
||||||
|
f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, statement=statement,
|
||||||
|
amount=200, partner=self.partner, memo='List 2')
|
||||||
|
result = self._jsonrpc('list_unreconciled', {
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'limit': 50,
|
||||||
|
'offset': 0,
|
||||||
|
'company_id': self.env.company.id,
|
||||||
|
})
|
||||||
|
self.assertIn('lines', result)
|
||||||
|
self.assertGreaterEqual(len(result['lines']), 2)
|
||||||
|
self.assertGreaterEqual(result['total'], 2)
|
||||||
|
first = result['lines'][0]
|
||||||
|
for key in ('id', 'amount', 'fusion_top_suggestion_id',
|
||||||
|
'fusion_confidence_band', 'attachment_count'):
|
||||||
|
self.assertIn(key, first)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 3. get_line_detail
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_get_line_detail(self):
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, amount=100, partner=self.partner)
|
||||||
|
f.make_suggestion(
|
||||||
|
self.env, statement_line=line, confidence=0.85)
|
||||||
|
result = self._jsonrpc(
|
||||||
|
'get_line_detail', {'statement_line_id': line.id})
|
||||||
|
self.assertEqual(result['line']['id'], line.id)
|
||||||
|
self.assertEqual(result['line']['amount'], 100.0)
|
||||||
|
self.assertGreaterEqual(len(result['suggestions']), 1)
|
||||||
|
sug = result['suggestions'][0]
|
||||||
|
for key in ('id', 'candidate_ids', 'confidence', 'rank',
|
||||||
|
'reasoning', 'scores'):
|
||||||
|
self.assertIn(key, sug)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 4. suggest_matches
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_suggest_matches(self):
|
||||||
|
f.make_invoice(self.env, partner=self.partner, amount=300)
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, amount=300, partner=self.partner)
|
||||||
|
result = self._jsonrpc('suggest_matches', {
|
||||||
|
'statement_line_ids': [line.id],
|
||||||
|
'limit_per_line': 3,
|
||||||
|
})
|
||||||
|
self.assertIn('suggestions', result)
|
||||||
|
self.assertIsInstance(result['suggestions'], dict)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 5. accept_suggestion
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_accept_suggestion(self):
|
||||||
|
invoice = f.make_invoice(
|
||||||
|
self.env, partner=self.partner, amount=400)
|
||||||
|
recv = invoice.line_ids.filtered(
|
||||||
|
lambda l: l.account_id.account_type == 'asset_receivable')
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, amount=400, partner=self.partner)
|
||||||
|
sug = f.make_suggestion(
|
||||||
|
self.env, statement_line=line,
|
||||||
|
candidate_move_lines=recv, confidence=0.92)
|
||||||
|
result = self._jsonrpc(
|
||||||
|
'accept_suggestion', {'suggestion_id': sug.id})
|
||||||
|
self.assertEqual(result['status'], 'accepted')
|
||||||
|
self.assertGreater(len(result['partial_ids']), 0)
|
||||||
|
self.assertIn('unreconciled_count_after', result)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 6. reconcile_manual
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _make_pair(self, *, amount, statement=None):
|
||||||
|
"""Inline reconcile-able pair against ``self.journal``.
|
||||||
|
|
||||||
|
The shared ``make_reconcileable_pair`` factory creates a fresh bank
|
||||||
|
journal per call (default code 'TEST'), which collides with the
|
||||||
|
unique (code, company) constraint when used multiple times in one
|
||||||
|
test. Reusing ``self.journal`` (and optionally a shared statement)
|
||||||
|
keeps every pair on the same journal.
|
||||||
|
"""
|
||||||
|
invoice = f.make_invoice(
|
||||||
|
self.env, partner=self.partner, amount=amount)
|
||||||
|
recv = invoice.line_ids.filtered(
|
||||||
|
lambda l: l.account_id.account_type == 'asset_receivable')
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, statement=statement,
|
||||||
|
amount=amount, partner=self.partner)
|
||||||
|
return line, recv
|
||||||
|
|
||||||
|
def test_reconcile_manual(self):
|
||||||
|
line, recv = self._make_pair(amount=550)
|
||||||
|
result = self._jsonrpc('reconcile_manual', {
|
||||||
|
'statement_line_id': line.id,
|
||||||
|
'against_move_line_ids': recv.ids,
|
||||||
|
})
|
||||||
|
self.assertEqual(result['status'], 'reconciled')
|
||||||
|
self.assertGreater(len(result['partial_ids']), 0)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 7. unreconcile
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_unreconcile(self):
|
||||||
|
line, recv = self._make_pair(amount=625)
|
||||||
|
rec = self.env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
line, against_lines=recv)
|
||||||
|
result = self._jsonrpc('unreconcile', {
|
||||||
|
'partial_reconcile_ids': rec['partial_ids'],
|
||||||
|
})
|
||||||
|
self.assertEqual(result['status'], 'unreconciled')
|
||||||
|
self.assertGreater(len(result['unreconciled_line_ids']), 0)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 8. write_off -- smoke only (Task 12 deferred full coverage)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_write_off_smoke(self):
|
||||||
|
line = f.make_bank_line(
|
||||||
|
self.env, journal=self.journal, amount=12.34,
|
||||||
|
partner=self.partner)
|
||||||
|
# Pick any expense-type account that exists in the chart.
|
||||||
|
wo_account = self.env['account.account'].search([
|
||||||
|
('account_type', '=', 'expense'),
|
||||||
|
('company_ids', 'in', self.env.company.id),
|
||||||
|
], limit=1)
|
||||||
|
if not wo_account:
|
||||||
|
self.skipTest("No expense account available for write-off smoke")
|
||||||
|
# Endpoint must respond without 500-erroring; engine may legitimately
|
||||||
|
# raise a ValidationError for an over-allocation, in which case the
|
||||||
|
# JSON-RPC response will include an 'error' key. We accept either
|
||||||
|
# success or a structured error -- what we are guarding against is a
|
||||||
|
# routing-layer regression (NameError, missing import, etc.).
|
||||||
|
url = '/fusion/bank_rec/write_off'
|
||||||
|
self.authenticate(self.USER_LOGIN, self.USER_PASSWORD)
|
||||||
|
body = {
|
||||||
|
'jsonrpc': '2.0', 'method': 'call', 'id': 1,
|
||||||
|
'params': {
|
||||||
|
'statement_line_id': line.id,
|
||||||
|
'account_id': wo_account.id,
|
||||||
|
'amount': line.amount,
|
||||||
|
'label': 'Smoke write-off',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
response = self.url_open(
|
||||||
|
url, data=json.dumps(body),
|
||||||
|
headers={'Content-Type': 'application/json'})
|
||||||
|
self.assertEqual(
|
||||||
|
response.status_code, 200,
|
||||||
|
f"write_off returned {response.status_code}: "
|
||||||
|
f"{response.text[:300]}")
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 9. bulk_reconcile
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_bulk_reconcile(self):
|
||||||
|
statement = f.make_bank_statement(
|
||||||
|
self.env, journal=self.journal, name='Bulk Stmt')
|
||||||
|
line_ids = []
|
||||||
|
for amt in (110, 220, 330):
|
||||||
|
line, _recv = self._make_pair(amount=amt, statement=statement)
|
||||||
|
line_ids.append(line.id)
|
||||||
|
result = self._jsonrpc('bulk_reconcile', {
|
||||||
|
'statement_line_ids': line_ids,
|
||||||
|
'strategy': 'auto',
|
||||||
|
})
|
||||||
|
self.assertIn('reconciled_count', result)
|
||||||
|
self.assertGreaterEqual(result['reconciled_count'], 3)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 10. get_partner_history
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_get_partner_history(self):
|
||||||
|
for d in (5, 12, 20):
|
||||||
|
f.make_precedent(
|
||||||
|
self.env, partner=self.partner, days_ago=d, amount=1000)
|
||||||
|
f.make_pattern(
|
||||||
|
self.env, partner=self.partner, reconcile_count=3)
|
||||||
|
result = self._jsonrpc('get_partner_history', {
|
||||||
|
'partner_id': self.partner.id,
|
||||||
|
'limit': 10,
|
||||||
|
})
|
||||||
|
self.assertEqual(result['partner']['id'], self.partner.id)
|
||||||
|
self.assertGreaterEqual(len(result['recent_reconciles']), 3)
|
||||||
|
self.assertIsNotNone(result['pattern'])
|
||||||
|
self.assertEqual(result['pattern']['reconcile_count'], 3)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 11. unauthenticated traffic is blocked
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def test_unauthenticated_request_blocked(self):
|
||||||
|
# Use a fresh session by creating a new opener -- self.url_open
|
||||||
|
# reuses the test session, which `authenticate()` would mutate.
|
||||||
|
url = '/fusion/bank_rec/get_state'
|
||||||
|
body = {
|
||||||
|
'jsonrpc': '2.0', 'method': 'call', 'id': 1,
|
||||||
|
'params': {
|
||||||
|
'journal_id': self.journal.id,
|
||||||
|
'company_id': self.env.company.id,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
# No call to self.authenticate() -> session has no uid.
|
||||||
|
response = self.url_open(
|
||||||
|
url, data=json.dumps(body),
|
||||||
|
headers={'Content-Type': 'application/json'},
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
# Odoo's auth='user' on a JSON-RPC route returns a 200 with an
|
||||||
|
# error envelope (SessionExpiredException) when not authenticated;
|
||||||
|
# what must NOT happen is the handler running and returning our
|
||||||
|
# success payload.
|
||||||
|
if response.status_code == 200:
|
||||||
|
payload = response.json()
|
||||||
|
self.assertIn(
|
||||||
|
'error', payload,
|
||||||
|
"Unauthenticated request should not return a success result")
|
||||||
|
else:
|
||||||
|
# 3xx redirect or 4xx are also acceptable rejections.
|
||||||
|
self.assertGreaterEqual(response.status_code, 300)
|
||||||
85
fusion_accounting_bank_rec/tests/test_cron_methods.py
Normal file
85
fusion_accounting_bank_rec/tests/test_cron_methods.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
"""Smoke tests for the cron handler methods.
|
||||||
|
|
||||||
|
We don't test the Odoo cron scheduler itself (it works) — we test that
|
||||||
|
calling the cron methods directly does what they're supposed to do."""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestFusionBankRecCron(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Cron Test Partner'})
|
||||||
|
self.cron = self.env['fusion.bank.rec.cron']
|
||||||
|
|
||||||
|
def test_cron_suggest_pending_creates_suggestions_for_new_line(self):
|
||||||
|
f.make_invoice(self.env, partner=self.partner, amount=420.00)
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=420.00, partner=self.partner)
|
||||||
|
|
||||||
|
Sug = self.env['fusion.reconcile.suggestion']
|
||||||
|
self.assertEqual(
|
||||||
|
Sug.search_count([('statement_line_id', '=', bank_line.id)]), 0)
|
||||||
|
|
||||||
|
self.cron._cron_suggest_pending(batch_size=10)
|
||||||
|
|
||||||
|
self.assertGreater(
|
||||||
|
Sug.search_count([('statement_line_id', '=', bank_line.id)]), 0)
|
||||||
|
|
||||||
|
def test_cron_suggest_pending_skips_lines_with_recent_suggestions(self):
|
||||||
|
f.make_invoice(self.env, partner=self.partner, amount=510.00)
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=510.00, partner=self.partner)
|
||||||
|
f.make_suggestion(
|
||||||
|
self.env, statement_line=bank_line, confidence=0.5)
|
||||||
|
|
||||||
|
Sug = self.env['fusion.reconcile.suggestion']
|
||||||
|
before = Sug.search_count(
|
||||||
|
[('statement_line_id', '=', bank_line.id)])
|
||||||
|
self.cron._cron_suggest_pending(batch_size=10)
|
||||||
|
after = Sug.search_count(
|
||||||
|
[('statement_line_id', '=', bank_line.id)])
|
||||||
|
self.assertEqual(
|
||||||
|
before, after,
|
||||||
|
"Cron should skip lines with a recent pending suggestion")
|
||||||
|
|
||||||
|
def test_cron_refresh_patterns_creates_pattern_for_partner_with_precedents(self):
|
||||||
|
for d in [10, 24, 38]:
|
||||||
|
f.make_precedent(
|
||||||
|
self.env, partner=self.partner, days_ago=d, amount=1000)
|
||||||
|
|
||||||
|
Pattern = self.env['fusion.reconcile.pattern']
|
||||||
|
Pattern.search([('partner_id', '=', self.partner.id)]).unlink()
|
||||||
|
|
||||||
|
self.cron._cron_refresh_patterns()
|
||||||
|
|
||||||
|
pattern = Pattern.search(
|
||||||
|
[('partner_id', '=', self.partner.id)], limit=1)
|
||||||
|
self.assertTrue(
|
||||||
|
pattern, "Cron should create pattern for partner with precedents")
|
||||||
|
self.assertEqual(pattern.reconcile_count, 3)
|
||||||
|
|
||||||
|
def test_cron_refresh_patterns_updates_existing_pattern(self):
|
||||||
|
Pattern = self.env['fusion.reconcile.pattern']
|
||||||
|
Pattern.search([('partner_id', '=', self.partner.id)]).unlink()
|
||||||
|
f.make_pattern(
|
||||||
|
self.env, partner=self.partner, reconcile_count=99)
|
||||||
|
|
||||||
|
for d in [5, 15]:
|
||||||
|
f.make_precedent(
|
||||||
|
self.env, partner=self.partner, days_ago=d, amount=500)
|
||||||
|
|
||||||
|
self.cron._cron_refresh_patterns()
|
||||||
|
|
||||||
|
pattern = Pattern.search(
|
||||||
|
[('partner_id', '=', self.partner.id)], limit=1)
|
||||||
|
self.assertEqual(
|
||||||
|
pattern.reconcile_count, 2,
|
||||||
|
"Cron should update existing pattern with fresh precedent count")
|
||||||
|
|
||||||
|
def test_cron_refresh_mv_does_not_raise(self):
|
||||||
|
# Just verify it runs — full MV behaviour is tested in Task 24
|
||||||
|
self.cron._cron_refresh_mv()
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
"""Tests verifying legacy tools route through fusion.reconcile.engine when present.
|
||||||
|
|
||||||
|
These tests run in the fusion_accounting_bank_rec context where the engine IS
|
||||||
|
available, so they assert the engine path is taken and produces correct
|
||||||
|
results. The fallback path is exercised by the existing fusion_accounting_ai
|
||||||
|
tests when fusion_accounting_bank_rec is not installed."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from odoo.addons.fusion_accounting_ai.services.tools import bank_reconciliation as tools
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestLegacyToolsRefactor(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({'name': 'Refactor Test Partner'})
|
||||||
|
|
||||||
|
def test_match_bank_line_to_payments_uses_engine(self):
|
||||||
|
"""When engine is present, match_bank_line_to_payments must produce
|
||||||
|
a partial reconcile via the engine, not via set_line_bank_statement_line."""
|
||||||
|
bank_line, recv_lines = f.make_reconcileable_pair(
|
||||||
|
self.env, amount=180.00, partner=self.partner)
|
||||||
|
result = tools.match_bank_line_to_payments(self.env, {
|
||||||
|
'statement_line_id': bank_line.id,
|
||||||
|
'move_line_ids': recv_lines.ids,
|
||||||
|
})
|
||||||
|
self.assertEqual(result.get('status'), 'matched')
|
||||||
|
bank_line.invalidate_recordset(['is_reconciled'])
|
||||||
|
self.assertTrue(bank_line.is_reconciled)
|
||||||
|
# Verify a precedent was recorded - engine-only behaviour
|
||||||
|
Precedent = self.env['fusion.reconcile.precedent']
|
||||||
|
precedents = Precedent.search([('partner_id', '=', self.partner.id)])
|
||||||
|
self.assertGreater(len(precedents), 0,
|
||||||
|
"Engine path should record a precedent; legacy path would not")
|
||||||
|
|
||||||
|
def test_auto_reconcile_bank_lines_uses_engine(self):
|
||||||
|
"""When engine is present, auto_reconcile_bank_lines must call
|
||||||
|
fusion.reconcile.engine.reconcile_batch (not the Enterprise-only
|
||||||
|
_try_auto_reconcile_statement_lines fallback). We patch
|
||||||
|
reconcile_batch to verify routing without running the real engine
|
||||||
|
across every legacy unreconciled line in the test DB."""
|
||||||
|
Engine = type(self.env['fusion.reconcile.engine'])
|
||||||
|
with patch.object(
|
||||||
|
Engine, 'reconcile_batch', autospec=True,
|
||||||
|
return_value={'reconciled_count': 2, 'skipped': 0, 'errors': []},
|
||||||
|
) as engine_call:
|
||||||
|
result = tools.auto_reconcile_bank_lines(self.env, {
|
||||||
|
'company_id': self.env.company.id,
|
||||||
|
})
|
||||||
|
self.assertEqual(result['status'], 'completed')
|
||||||
|
self.assertTrue(engine_call.called,
|
||||||
|
"Engine path must invoke fusion.reconcile.engine.reconcile_batch")
|
||||||
|
# Verify the engine was passed the strategy='auto' kwarg per spec
|
||||||
|
_self, _lines = engine_call.call_args.args[0], engine_call.call_args.args[1]
|
||||||
|
self.assertEqual(engine_call.call_args.kwargs.get('strategy'), 'auto')
|
||||||
102
fusion_accounting_bank_rec/tests/test_local_llm_compat.py
Normal file
102
fusion_accounting_bank_rec/tests/test_local_llm_compat.py
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
"""Local LLM compatibility test (LM Studio, Ollama, etc.).
|
||||||
|
|
||||||
|
Skips if no local OpenAI-compatible LLM server is reachable. When one is
|
||||||
|
running (LM Studio at :1234, Ollama at :11434), runs an end-to-end:
|
||||||
|
|
||||||
|
1. Configure ``ir.config_parameter`` to point at the local server.
|
||||||
|
2. Trigger ``engine.suggest_matches`` with the 'openai' provider.
|
||||||
|
3. Assert the call did not crash and produced at least one suggestion.
|
||||||
|
|
||||||
|
The smoke is intentionally lenient: local models often emit malformed
|
||||||
|
JSON, in which case ``confidence_scoring`` falls back to statistical-only
|
||||||
|
ranking. We assert end-to-end happiness, not AI re-rank quality.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
def _server_reachable(host, port, timeout=1.0):
|
||||||
|
try:
|
||||||
|
with socket.create_connection((host, port), timeout=timeout):
|
||||||
|
return True
|
||||||
|
except (OSError, socket.timeout):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _detect_local_llm():
|
||||||
|
"""Return (base_url, model_name) tuple, or (None, None) if no server.
|
||||||
|
|
||||||
|
Tries LM Studio (:1234) and Ollama (:11434) on both
|
||||||
|
``host.docker.internal`` (so the container can reach the host) and
|
||||||
|
``localhost`` (so a non-containerised run finds the same servers).
|
||||||
|
"""
|
||||||
|
candidates = (
|
||||||
|
('host.docker.internal', 1234, 'local-model'), # LM Studio
|
||||||
|
('host.docker.internal', 11434, 'llama3.1:8b'), # Ollama
|
||||||
|
('localhost', 1234, 'local-model'),
|
||||||
|
('localhost', 11434, 'llama3.1:8b'),
|
||||||
|
)
|
||||||
|
for host, port, default_model in candidates:
|
||||||
|
if _server_reachable(host, port, timeout=0.5):
|
||||||
|
return (f'http://{host}:{port}/v1', default_model)
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install', 'local_llm')
|
||||||
|
class TestLocalLLMCompat(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.base_url, self.model = _detect_local_llm()
|
||||||
|
if not self.base_url:
|
||||||
|
self.skipTest(
|
||||||
|
"No local LLM server detected "
|
||||||
|
"(LM Studio :1234 / Ollama :11434)")
|
||||||
|
|
||||||
|
def test_suggest_matches_with_local_llm(self):
|
||||||
|
params = self.env['ir.config_parameter'].sudo()
|
||||||
|
prior = {
|
||||||
|
'fusion_accounting.openai_base_url': params.get_param(
|
||||||
|
'fusion_accounting.openai_base_url'),
|
||||||
|
'fusion_accounting.openai_model': params.get_param(
|
||||||
|
'fusion_accounting.openai_model'),
|
||||||
|
'fusion_accounting.openai_api_key': params.get_param(
|
||||||
|
'fusion_accounting.openai_api_key'),
|
||||||
|
'fusion_accounting.provider.bank_rec_suggest': params.get_param(
|
||||||
|
'fusion_accounting.provider.bank_rec_suggest'),
|
||||||
|
}
|
||||||
|
|
||||||
|
params.set_param('fusion_accounting.openai_base_url', self.base_url)
|
||||||
|
params.set_param('fusion_accounting.openai_model', self.model)
|
||||||
|
# Local servers ignore the key but the adapter requires *some* value.
|
||||||
|
params.set_param('fusion_accounting.openai_api_key', 'lm-studio')
|
||||||
|
params.set_param(
|
||||||
|
'fusion_accounting.provider.bank_rec_suggest', 'openai')
|
||||||
|
|
||||||
|
try:
|
||||||
|
partner = self.env['res.partner'].create(
|
||||||
|
{'name': 'Local LLM Partner'})
|
||||||
|
f.make_invoice(self.env, partner=partner, amount=750)
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=750, partner=partner,
|
||||||
|
memo='REF 12345 Local LLM test')
|
||||||
|
|
||||||
|
result = self.env['fusion.reconcile.engine'].suggest_matches(
|
||||||
|
bank_line, limit_per_line=3)
|
||||||
|
|
||||||
|
self.assertIn(bank_line.id, result)
|
||||||
|
suggestions = self.env['fusion.reconcile.suggestion'].search([
|
||||||
|
('statement_line_id', '=', bank_line.id),
|
||||||
|
])
|
||||||
|
self.assertGreater(
|
||||||
|
len(suggestions), 0,
|
||||||
|
"Local LLM run should still produce at least one suggestion "
|
||||||
|
"(statistical fallback if AI re-rank fails)")
|
||||||
|
finally:
|
||||||
|
for key, value in prior.items():
|
||||||
|
if value is not None:
|
||||||
|
params.set_param(key, value)
|
||||||
115
fusion_accounting_bank_rec/tests/test_migration_round_trip.py
Normal file
115
fusion_accounting_bank_rec/tests/test_migration_round_trip.py
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"""Migration round-trip: bootstrap step backfills precedents from
|
||||||
|
existing account.partial.reconcile rows.
|
||||||
|
|
||||||
|
Exercises Task 39's _bank_rec_bootstrap_step end-to-end:
|
||||||
|
1. Set up a bank-line / invoice reconciliation via the engine. This
|
||||||
|
creates an account.partial.reconcile row.
|
||||||
|
2. Wipe the auto-recorded fusion.reconcile.precedent rows so the
|
||||||
|
backfill has work to do.
|
||||||
|
3. Run wizard._bank_rec_bootstrap_step().
|
||||||
|
4. Assert at least one precedent was created with source='backfill',
|
||||||
|
the wizard reports successful pattern + MV refresh, and that a
|
||||||
|
second run is a no-op (idempotent).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestMigrationRoundTrip(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({
|
||||||
|
'name': 'Migration Round-Trip Partner',
|
||||||
|
})
|
||||||
|
self.journal = f.make_bank_journal(
|
||||||
|
self.env, name='Migration Bank', code='MIGBK')
|
||||||
|
self.statement = f.make_bank_statement(
|
||||||
|
self.env, journal=self.journal, name='Migration Statement')
|
||||||
|
|
||||||
|
def _seed_partial_reconciles(self, amounts):
|
||||||
|
"""Create one reconciled bank-line/invoice pair per amount, reusing
|
||||||
|
a single bank journal so we don't violate the
|
||||||
|
account_journal_code_company_uniq constraint.
|
||||||
|
|
||||||
|
Each call here produces one account.partial.reconcile row.
|
||||||
|
Returns the partial recordset.
|
||||||
|
"""
|
||||||
|
Engine = self.env['fusion.reconcile.engine']
|
||||||
|
partials = self.env['account.partial.reconcile']
|
||||||
|
for amount in amounts:
|
||||||
|
invoice = f.make_invoice(
|
||||||
|
self.env, partner=self.partner, amount=amount)
|
||||||
|
recv_lines = invoice.line_ids.filtered(
|
||||||
|
lambda l: l.account_id.account_type == 'asset_receivable')
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, statement=self.statement, amount=amount,
|
||||||
|
partner=self.partner)
|
||||||
|
result = Engine.reconcile_one(
|
||||||
|
bank_line, against_lines=recv_lines)
|
||||||
|
partials |= self.env['account.partial.reconcile'].browse(
|
||||||
|
result['partial_ids'])
|
||||||
|
return partials
|
||||||
|
|
||||||
|
def _wipe_precedents(self):
|
||||||
|
self.env['fusion.reconcile.precedent'].search([
|
||||||
|
('partner_id', '=', self.partner.id),
|
||||||
|
]).unlink()
|
||||||
|
|
||||||
|
def test_bootstrap_creates_precedents_from_existing_reconciles(self):
|
||||||
|
partials = self._seed_partial_reconciles([125.00, 275.00])
|
||||||
|
self.assertTrue(partials,
|
||||||
|
"Test setup should produce account.partial.reconcile rows")
|
||||||
|
|
||||||
|
self._wipe_precedents()
|
||||||
|
before_backfill = self.env['fusion.reconcile.precedent'].search_count([
|
||||||
|
('partner_id', '=', self.partner.id),
|
||||||
|
('source', '=', 'backfill'),
|
||||||
|
])
|
||||||
|
self.assertEqual(before_backfill, 0,
|
||||||
|
"Precondition: no backfill precedents should exist before bootstrap")
|
||||||
|
|
||||||
|
wizard = self.env['fusion.migration.wizard'].create({})
|
||||||
|
result = wizard._bank_rec_bootstrap_step()
|
||||||
|
|
||||||
|
self.assertEqual(result['step'], 'bank_rec_bootstrap')
|
||||||
|
self.assertGreaterEqual(result['precedents_created'], 1,
|
||||||
|
"Bootstrap should backfill at least one precedent from the "
|
||||||
|
"partial.reconcile rows produced in setUp")
|
||||||
|
self.assertTrue(result['mv_refreshed'],
|
||||||
|
"Bootstrap should report successful MV refresh")
|
||||||
|
|
||||||
|
after_backfill = self.env['fusion.reconcile.precedent'].search_count([
|
||||||
|
('partner_id', '=', self.partner.id),
|
||||||
|
('source', '=', 'backfill'),
|
||||||
|
])
|
||||||
|
self.assertGreaterEqual(after_backfill, 1,
|
||||||
|
"At least one source='backfill' precedent should exist post-bootstrap")
|
||||||
|
|
||||||
|
def test_bootstrap_step_idempotent(self):
|
||||||
|
self._seed_partial_reconciles([411.00])
|
||||||
|
self._wipe_precedents()
|
||||||
|
|
||||||
|
wizard = self.env['fusion.migration.wizard'].create({})
|
||||||
|
result1 = wizard._bank_rec_bootstrap_step()
|
||||||
|
created_first_run = result1['precedents_created']
|
||||||
|
self.assertGreaterEqual(created_first_run, 1)
|
||||||
|
|
||||||
|
result2 = wizard._bank_rec_bootstrap_step()
|
||||||
|
self.assertEqual(result2['precedents_created'], 0,
|
||||||
|
"Second bootstrap should create zero precedents (idempotent)")
|
||||||
|
self.assertGreaterEqual(result2['precedents_skipped'], created_first_run,
|
||||||
|
"Second bootstrap should skip at least what the first one created")
|
||||||
|
|
||||||
|
def test_bootstrap_refreshes_mv_without_error(self):
|
||||||
|
"""The bootstrap call must not raise even when there's nothing to do."""
|
||||||
|
wizard = self.env['fusion.migration.wizard'].create({})
|
||||||
|
try:
|
||||||
|
result = wizard._bank_rec_bootstrap_step()
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
self.fail(f"Bootstrap raised: {e}")
|
||||||
|
self.assertIn('mv_refreshed', result)
|
||||||
|
self.assertIn('patterns_refreshed', result)
|
||||||
82
fusion_accounting_bank_rec/tests/test_mv_unreconciled.py
Normal file
82
fusion_accounting_bank_rec/tests/test_mv_unreconciled.py
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
"""Smoke tests for the fusion_unreconciled_bank_line_mv materialized view.
|
||||||
|
|
||||||
|
Notes on transactional semantics:
|
||||||
|
- REFRESH MATERIALIZED VIEW (non-CONCURRENTLY) IS transactional and runs
|
||||||
|
inside the current transaction. Postgres always shows a transaction
|
||||||
|
its own (uncommitted) writes, so an INSERT followed by a REFRESH in
|
||||||
|
the same transaction picks up the new row — no `cr.commit()` needed.
|
||||||
|
- Odoo's TransactionCase forbids cr.commit() anyway (it would break the
|
||||||
|
per-test savepoint rollback). We rely on rollback to clean up both
|
||||||
|
the test fixtures and the MV-table mutations from the refresh.
|
||||||
|
- REFRESH MATERIALIZED VIEW CONCURRENTLY must run OUTSIDE a transaction
|
||||||
|
block; we always pass concurrently=False from tests. The production
|
||||||
|
cron path (Task 25) will open a dedicated autocommit cursor for the
|
||||||
|
concurrent refresh.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase, tagged
|
||||||
|
from . import _factories as f
|
||||||
|
|
||||||
|
|
||||||
|
@tagged('post_install', '-at_install')
|
||||||
|
class TestUnreconciledBankLineMV(TransactionCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.partner = self.env['res.partner'].create({
|
||||||
|
'name': 'MV Test Partner',
|
||||||
|
})
|
||||||
|
# Refresh once at the start so the MV reflects the current snapshot
|
||||||
|
# (including any rows inserted earlier in this savepoint chain).
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
|
||||||
|
def test_mv_exists_and_is_queryable(self):
|
||||||
|
# Smoke: the model can be searched without error.
|
||||||
|
rows = self.env['fusion.unreconciled.bank.line.mv'].search(
|
||||||
|
[], limit=10)
|
||||||
|
self.assertIsNotNone(rows)
|
||||||
|
|
||||||
|
def test_mv_includes_unreconciled_line(self):
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=999.99, partner=self.partner)
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
mv_row = self.env['fusion.unreconciled.bank.line.mv'].search([
|
||||||
|
('id', '=', bank_line.id),
|
||||||
|
])
|
||||||
|
self.assertTrue(
|
||||||
|
mv_row,
|
||||||
|
"MV should contain freshly-inserted unreconciled line")
|
||||||
|
self.assertAlmostEqual(mv_row.amount, 999.99, places=2)
|
||||||
|
# No suggestion yet -> band 'none', confidence 0.
|
||||||
|
self.assertEqual(mv_row.confidence_band, 'none')
|
||||||
|
self.assertEqual(mv_row.attachment_count, 0)
|
||||||
|
|
||||||
|
def test_mv_excludes_reconciled_line(self):
|
||||||
|
bank_line, recv_lines = f.make_reconcileable_pair(
|
||||||
|
self.env, amount=100.00, partner=self.partner)
|
||||||
|
self.env['fusion.reconcile.engine'].reconcile_one(
|
||||||
|
bank_line, against_lines=recv_lines)
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
mv_row = self.env['fusion.unreconciled.bank.line.mv'].search([
|
||||||
|
('id', '=', bank_line.id),
|
||||||
|
])
|
||||||
|
self.assertFalse(
|
||||||
|
mv_row, "Reconciled line should be excluded from MV")
|
||||||
|
|
||||||
|
def test_mv_confidence_band_high_for_high_conf_suggestion(self):
|
||||||
|
bank_line = f.make_bank_line(
|
||||||
|
self.env, amount=500.00, partner=self.partner)
|
||||||
|
f.make_suggestion(
|
||||||
|
self.env, statement_line=bank_line, confidence=0.92)
|
||||||
|
self.env['fusion.unreconciled.bank.line.mv']._refresh(
|
||||||
|
concurrently=False)
|
||||||
|
mv_row = self.env['fusion.unreconciled.bank.line.mv'].search([
|
||||||
|
('id', '=', bank_line.id),
|
||||||
|
])
|
||||||
|
self.assertTrue(mv_row, "MV row should exist for suggestion line")
|
||||||
|
# 0.92 falls in the 'high' band per the SQL CASE (>= 0.85).
|
||||||
|
self.assertEqual(mv_row.confidence_band, 'high')
|
||||||
|
self.assertAlmostEqual(mv_row.top_confidence, 0.92, places=2)
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user