[REF] onboarding: return meaningful response at step validation

The purpose of this commit is to return meaningful responses when
validating steps and leave the caller to decide what to do with them.

We also introduce a public action enabling the validation of a step
from its xmlid and handle the different cases including the missing
step.

Note: these features are currently used in appointment (See Ent PR).

Additionally, returning the newly validated `onboarding_steps` from
`onboarding_step.action_set_just_done` makes more sense than returning
the `onboarding_progress_steps` records.

Tests are updated to make sure of this.

Task-3074112

closes odoo/odoo#114572

Related: odoo/enterprise#37870
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Florian Charlier
2023-04-05 19:02:42 +02:00
parent f23d0fedfa
commit 67148eff95
2 changed files with 12 additions and 2 deletions
+8 -1
View File
@@ -61,7 +61,14 @@ class OnboardingStep(models.Model):
# Make sure progress records exist for the current context (company)
steps_without_progress = self.filtered(lambda step: not step.current_progress_step_id)
steps_without_progress._create_progress_steps()
return self.current_progress_step_id.action_set_just_done()
return self.current_progress_step_id.action_set_just_done().step_id
@api.model
def action_validate_step(self, xml_id):
step = self.env.ref(xml_id, raise_if_not_found=False)
if not step:
return "NOT_FOUND"
return "JUST_DONE" if step.action_set_just_done() else "WAS_DONE"
def _create_progress_steps(self):
onboarding_progress_records = self.env['onboarding.progress'].search([
+4 -1
View File
@@ -15,7 +15,8 @@ class TestOnboarding(TestOnboardingCommon):
self.onboarding_1.current_progress_id._get_and_update_onboarding_state(),
{self.onboarding_1_step_1.id: 'not_done', self.onboarding_1_step_2.id: 'not_done'})
self.onboarding_1_step_1.action_set_just_done()
self.assertEqual(self.onboarding_1_step_1.action_set_just_done(), self.onboarding_1_step_1,
"The onboarding step just validated should have been returned.")
# Test completed step state consolidation from `just_done` to `done`
self.assertDictEqual(
self.onboarding_1.current_progress_id._get_and_update_onboarding_state(),
@@ -24,6 +25,8 @@ class TestOnboarding(TestOnboardingCommon):
self.onboarding_1.current_progress_id._get_and_update_onboarding_state(),
{self.onboarding_1_step_1.id: 'done', self.onboarding_1_step_2.id: 'not_done'})
self.assert_step_is_done(self.onboarding_1_step_1, self.company_2)
self.assertFalse(self.onboarding_1_step_1.action_set_just_done(),
"The onboarding step already validated should not have been returned.")
self.assert_onboarding_is_not_done(self.onboarding_1, self.company_2)
self.onboarding_1_step_2.action_set_just_done()