Skip to content

[14.0][IMP] stachechart_mixin: make it possible to ignore some events in the has_allowed_event compute#40

Open
jdoutreloux wants to merge 2 commits into
14.0from
14.0-imp_has_allowed_events-jdo
Open

[14.0][IMP] stachechart_mixin: make it possible to ignore some events in the has_allowed_event compute#40
jdoutreloux wants to merge 2 commits into
14.0from
14.0-imp_has_allowed_events-jdo

Conversation

@jdoutreloux
Copy link
Copy Markdown

@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
Copy Markdown
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.

Comment thread statechart/models/statechart_mixin.py Outdated
Comment thread statechart/models/statechart_mixin.py Outdated

@api.depends("sc_state")
def _compute_sc_has_allowed_events(self):
priorities = self.env.context.get("priorities")
Copy link
Copy Markdown
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", [])

Comment thread statechart/models/statechart_mixin.py Outdated
@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
Comment thread statechart/models/statechart_mixin.py Outdated
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
Copy Markdown
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.

return [
_sc_make_event_allowed_field_name(event_name) for event_name in event_names
]
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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). 🤖

@sbidoul sbidoul changed the title [IMP] statechart: improve _compute_sc_has_allowed_events [14.0][IMP] stachechat_mixin: make it possible to ignore some events in the has_allowed_event compute Aug 13, 2025
@sbidoul sbidoul changed the title [14.0][IMP] stachechat_mixin: make it possible to ignore some events in the has_allowed_event compute [14.0][IMP] stachechart_mixin: make it possible to ignore some events in the has_allowed_event compute Aug 13, 2025
Justine Doutreloux and others added 2 commits August 13, 2025 13:21
There is no need to leak this context handling to
_get_sc_event_allowed_field_names, where
this can be handled with a new argument.
@sbidoul sbidoul force-pushed the 14.0-imp_has_allowed_events-jdo branch from 209e40f to 4634de1 Compare August 13, 2025 11:21
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