Files
odoo_source/addons/project/models
Sarah Bellefroid 9dde5a64e9 [FIX] project, hr_timesheet: use correct analytic plan setting
Currently, the `plan_id` used to create analytic accounts is not the one set in the settings.

Steps to reproduce:
-------------------
* Go to the **Settings**
* Enable developper mode
* Select **User & Companies** > **Groups**
* Select `Technical/Analytic Accounting`
* Add user
* Go to the **Project** app
* Select **Configuration** > **Settings**
* Under **Time Management**, enable Timesheets
* Under **Analytics** > **Analytic Plan**, select Projects
* Create a new project
* Go into the settings of the project
* Under the **Settings** tab, select the internal link for the **Analytic Account**
  > **Observation**: The Plan is set to Projects
* Go to **Conffiguration** > **Settings**
* Under **Analytics** > **Analytic Plan**, change Projects to Departments
* Create a new project
* Go into the settings of the project
* Under the **Settings** tab, select the internal link for the **Analytic Account**
  > **Observation**: The Plan is still set to Projects

Why the fix:
------------
When creating, an analytic account, the plan is computed with `_get_all_plans()`.
https://github.com/odoo/odoo/blob/e365e22485dc45f1cbe87ae93395b022a4724a3c/addons/project/models/project_project.py#L894-L903

Inside `__get_all_plans()` the plan is computed as follows:
https://github.com/odoo/odoo/blob/e365e22485dc45f1cbe87ae93395b022a4724a3c/addons/analytic/models/analytic_plan.py#L106-L07

However, the setting that the user changes in the frontend corresponds to `analytic.analytic_plan_projects`.
https://github.com/odoo/odoo/blob/e365e22485dc45f1cbe87ae93395b022a4724a3c/addons/project/models/res_config_settings.py#L18-L22

This seeting is not company-related. It can be used on projects even if they have a `company_id` set to false. We fallback on `_get_all_plans()` if the user did not specifically choose a plan in the settings.

opw-3751661

closes odoo/odoo#157247

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
2024-03-18 16:22:38 +00:00
..