Adds bank_rec_bootstrap step that backfills fusion.reconcile.precedent from existing account.partial.reconcile rows during migration. This gives the AI memory from past Enterprise reconciles. Also triggers pattern refresh + MV refresh for immediate UI readiness. - New service services/precedent_backfill.py walks account.partial.reconcile rows, identifies the bank-statement-line side, and creates a precedent per qualifying partial. Idempotent via (statement_line, account, amount, source='backfill') signature. - New model models/fusion_migration_wizard.py inherits fusion.migration.wizard, exposes _bank_rec_bootstrap_step() (callable from tests/audit), and overrides action_run_migration() to call super() + the bootstrap. - Adds 'backfill' to fusion.reconcile.precedent.source selection. - Adds fusion_accounting_migration to depends. Made-with: Cursor
98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
"""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,
|
|
},
|
|
}
|