add project_task_analytic_account_sync

This commit is contained in:
Luis 2026-06-16 10:56:18 +02:00
parent 5247938b86
commit 0f2c8c0565
9 changed files with 203 additions and 0 deletions

View file

@ -0,0 +1,22 @@
# Project Task Analytic Account Sync
This module forces the analytic account of every project task to always be the same as the one defined on its project. It removes the possibility of manual divergences introduced by the `is_analytic_account_id_changed` flag in Odoo core.
## Behavior
- **Task creation**: When a task is created and assigned to a project, its `analytic_account_id` is set to the project's analytic account.
- **Project change**: When a task is moved to another project, its analytic account is updated to the new project's account.
- **Project analytic account change**: When a project's analytic account is modified, the change is propagated to **all** existing tasks (active and archived).
- **Manual override ignored**: Writing a different analytic account directly on a task is immediately reverted.
- **Analytic account auto-creation**: When Odoo auto-creates a project analytic account, the existing tasks are synchronized.
## Usage
No user action is required. The synchronization is transparent and enforced server-side.
## Technical notes
- The `analytic_account_id` field on `project.task` is kept as a computed stored field but the compute is overridden to always ignore `is_analytic_account_id_changed`.
- `project.project.write` detects changes in `analytic_account_id` and propagates them in batch.
- `project.task.write` detects changes in `project_id` or `analytic_account_id` and corrects the value immediately.
- The task form view makes the analytic account field readonly to avoid confusion.