Files
Odoo-Modules/fusion_accounting_bank_rec/models/fusion_migration_wizard.py
gsinghpal 9d8db0f9b1 fix(bank_rec): don't shadow Odoo's _() translation function in action_run_migration
Line 77 was `_ = super().action_run_migration()`, using `_` as a
throwaway variable name. That rebinds the module-level `_` (Odoo's
translation function imported at the top) to whatever super() returns
\u2014 in our case the parent's notification dict.

Lines 84/85 then call `_('Bank-Rec Migration Complete')` which is
now `some_dict('Bank-Rec Migration Complete')` \u2192
TypeError: 'dict' object is not callable.

User hit this when running the migration wizard from the menu.

Fix: drop the assignment; we don't actually use super()'s return value.
Made-with: Cursor
2026-04-19 23:34:45 -04:00

100 lines
3.6 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.
"""
# Don't bind super()'s return value to `_` \u2014 that shadows the
# imported translation function and breaks the _("...") calls below.
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,
},
}