-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[18.0][FIX] base_exception: Rollback transaction if we detect exceptions #3590
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
Open
grindtildeath
wants to merge
14
commits into
OCA:18.0
Choose a base branch
from
camptocamp:18.0-fix-base_exception_rollback_transaction_fix_ui
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
61eed8a
[FIX] base_exception: Rollback transaction if we detect exceptions
grindtildeath 9a1c94c
Fix tests
grindtildeath 08266fe
[REF] base_exception: Handle the exception popup at client level
grindtildeath e1b81f8
[REF] base_exception: Use a client action to reload smoothly
grindtildeath 1a2e3c6
fixup! [REF] base_exception: Use a client action to reload smoothly
grindtildeath 9857533
fixup! fixup! [REF] base_exception: Use a client action to reload smo…
grindtildeath c008459
[TEST] base_exception: Test exception rollbacking
grindtildeath e9c8a9d
fixup! fixup! fixup! [REF] base_exception: Use a client action to rel…
grindtildeath c548c60
fixup! fixup! fixup! fixup! [REF] base_exception: Use a client action…
grindtildeath 190597f
fixup! [FIX] base_exception: Rollback transaction if we detect except…
grindtildeath 20a2885
fixup! fixup! fixup! fixup! fixup! [REF] base_exception: Use a client…
grindtildeath c309ca0
Make test decorator available for import in other modules
grindtildeath f1b8586
fixup! fixup! fixup! fixup! fixup! fixup! [REF] base_exception: Use a…
grindtildeath 78412ea
Avoid using new env for unrelated tests
grindtildeath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright 2025 Camptocamp SA | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
|
||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class BaseExceptionError(UserError): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import {patch} from "@web/core/utils/patch"; | ||
| import {rpc} from "@web/core/network/rpc"; | ||
| import {FormController} from "@web/views/form/form_controller"; | ||
|
|
||
| // keep track of the current FormController by storing it | ||
| const activeForm = { | ||
| controller: null, | ||
| }; | ||
|
|
||
| patch(FormController.prototype, { | ||
| setup() { | ||
| super.setup(); | ||
| activeForm.controller = this; | ||
| }, | ||
| willUnmount() { | ||
| if (activeForm.controller === this) { | ||
| activeForm.controller = null; | ||
| } | ||
| super.willUnmount(); | ||
| }, | ||
| }); | ||
|
|
||
| function getActiveRecordInfo(controller) { | ||
| const model = controller.model; | ||
| const root = model?.root; | ||
| return { | ||
| root, | ||
| resModel: root?.resModel, | ||
| resId: root?.resId, | ||
| }; | ||
| } | ||
|
|
||
| async function popUpException() { | ||
| const controller = activeForm.controller; | ||
| const orm = controller.env.services.orm; | ||
|
|
||
| const {resModel, resId} = getActiveRecordInfo(controller); | ||
| if (!resModel || !resId) return false; | ||
| const actionService = controller.env.services.action; | ||
| const action = await orm.call(resModel, "action_popup_exceptions", [[resId]]); | ||
| if (!action) return false; | ||
|
|
||
| await actionService.doAction(action); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| async function refreshExceptionIdsField() { | ||
| const controller = activeForm.controller; | ||
| if (!controller) return false; | ||
|
|
||
| const {root, resModel, resId} = getActiveRecordInfo(controller); | ||
| if (!resModel || !resId) return false; | ||
| const orm = controller.env.services.orm; | ||
|
|
||
| // Read the latest value for just that field | ||
| await orm.read(resModel, [resId], ["exception_ids"]); | ||
| // Reload the record; OWL will re-render the field | ||
| await root.load(); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| patch(rpc, { | ||
| async _rpc(url, params = {}, settings = {}) { | ||
| try { | ||
| return await super._rpc(url, params, settings); | ||
| } catch (error) { | ||
| if ( | ||
| error.exceptionName === | ||
| "odoo.addons.base_exception.exceptions.BaseExceptionError" | ||
| ) { | ||
| await refreshExceptionIdsField(); | ||
| await popUpException(); | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.