Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] statechart: improve _compute_sc_has_allowed_events #40

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from

Conversation

jdoutreloux
Copy link
Contributor

@jdoutreloux jdoutreloux commented Jul 28, 2023

This commits makes it possible to ignore some events when computing has_allowed_events by passing them in the context key ignore_for_has_allowed_events.
For example, our record has a cancel action on each state but we don't want to take that action into account when getting the records with allowed_events
Our use case is showing all the records that need an action in a dashboard. But the records with a cancel action are not actually in need of an action.

@jdoutreloux jdoutreloux requested review from sbejaoui and sbidoul July 28, 2023 14:47
Copy link
Contributor

@sbejaoui sbejaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a somewhat tricky solution. I didn't like the fact that it depends on the context.

As I understand it, we are trying to exclude certain events from the user notification/dashboard. I prefer a more explicit field than the priority. For example: "exclude_from_allowed_event." takes true or false.

statechart/models/statechart_mixin.py Outdated Show resolved Hide resolved
@api.depends("sc_state")
def _compute_sc_has_allowed_events(self):
priorities = self.env.context.get("priorities")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
priorities = self.env.context.get("priorities")
priorities = self.env.context.get("priorities", [])

statechart/models/statechart_mixin.py Outdated Show resolved Hide resolved
@jdoutreloux jdoutreloux force-pushed the 14.0-imp_has_allowed_events-jdo branch 2 times, most recently from 1c52070 to e37e365 Compare August 8, 2023 11:44
@@ -316,7 +316,8 @@ class can override the statechart with another one adding new events,

@api.model
def _get_sc_event_allowed_field_names(self):
event_names = self._statechart.events_for()
ignore_for_has_allowed_events = self.env.context.get("ignore_for_has_allowed_events", [])
event_names = [name for name in self._statechart.events_for() if name not in ignore_for_has_allowed_events]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can put the if name not in ignore_for_has_allowed_events in the return statement, to avoid creating a temporary list.

Comment on lines 321 to 326
return [
_sc_make_event_allowed_field_name(event_name) for event_name in event_names
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [
_sc_make_event_allowed_field_name(event_name) for event_name in event_names
]
return [
_sc_make_event_allowed_field_name(event_name) for event_name in event_names if event_name not in ignore_for_has_allowed_event
]

@jdoutreloux jdoutreloux force-pushed the 14.0-imp_has_allowed_events-jdo branch from e37e365 to ee7254d Compare August 8, 2023 12:40
@jdoutreloux jdoutreloux requested a review from sbejaoui October 25, 2023 09:14
Copy link
Contributor

@sbejaoui sbejaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sbidoul
Copy link
Member

sbidoul commented Dec 15, 2023

This needs a test. It should be easy to add in test_basic.py. Don't hesitate to add events to test_statechart.yml to make the test more relevant.

@jdoutreloux jdoutreloux force-pushed the 14.0-imp_has_allowed_events-jdo branch from ee7254d to c21bb32 Compare April 24, 2024 13:33
@jdoutreloux
Copy link
Contributor Author

This needs a test. It should be easy to add in test_basic.py. Don't hesitate to add events to test_statechart.yml to make the test more relevant.

Sorry for the delay, I'm just now seeing your review. I've added the test as you asked.

@acsone-git-bot
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

1 similar comment
@acsone-git-bot
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants