diff --git a/fieldservice_account_analytic/__init__.py b/fieldservice_account_analytic/__init__.py index a60aec2546..06968e6867 100644 --- a/fieldservice_account_analytic/__init__.py +++ b/fieldservice_account_analytic/__init__.py @@ -3,4 +3,4 @@ from . import models from . import wizard -from .init_hook import pre_init_hook +from .init_hook import pre_init_hook, post_init_hook diff --git a/fieldservice_account_analytic/__manifest__.py b/fieldservice_account_analytic/__manifest__.py index 850a8bfd81..e471bf42b9 100644 --- a/fieldservice_account_analytic/__manifest__.py +++ b/fieldservice_account_analytic/__manifest__.py @@ -31,6 +31,7 @@ "demo/fsm_location.xml", ], "pre_init_hook": "pre_init_hook", + "post_init_hook": "post_init_hook", "license": "AGPL-3", "development_status": "Beta", "maintainers": [ diff --git a/fieldservice_account_analytic/init_hook.py b/fieldservice_account_analytic/init_hook.py index 11dcaed476..216390328c 100644 --- a/fieldservice_account_analytic/init_hook.py +++ b/fieldservice_account_analytic/init_hook.py @@ -8,3 +8,15 @@ def pre_init_hook(env): """UPDATE "fsm_location" SET customer_id = owner_id WHERE customer_id IS NULL;""" ) + + +def post_init_hook(env): + group_analytic_accounting = env.ref( + "analytic.group_analytic_accounting", raise_if_not_found=False + ) + + if group_analytic_accounting: + users = env["res.users"].search([]) + + for user in users: + user.write({"groups_id": [(4, group_analytic_accounting.id)]}) diff --git a/fieldservice_account_analytic/models/fsm_order.py b/fieldservice_account_analytic/models/fsm_order.py index 12a394f795..325cd3fe66 100644 --- a/fieldservice_account_analytic/models/fsm_order.py +++ b/fieldservice_account_analytic/models/fsm_order.py @@ -76,9 +76,10 @@ def create(self, vals_list): } ) record.analytic_account_id = analytic_account - - if "contractor_cost_ids" in vals: - for line in record.contractor_cost_ids: - line.analytic_distribution = line._default_analytic_distribution() + if "contractor_cost_ids" in vals: + for line in record.contractor_cost_ids: + line.analytic_distribution = ( + line._default_analytic_distribution() + ) return record diff --git a/fieldservice_account_analytic/views/res_config_settings.xml b/fieldservice_account_analytic/views/res_config_settings.xml index 9f37abb4f7..1f1e36e874 100644 --- a/fieldservice_account_analytic/views/res_config_settings.xml +++ b/fieldservice_account_analytic/views/res_config_settings.xml @@ -13,15 +13,6 @@ - - - - - - -