Repository navigation
Conversation
Adding some more info to the description for when exceptions are checked.
Currently translated at 100.0% (28 of 28 strings) Translation: stock-logistics-warehouse-17.0/stock-logistics-warehouse-17.0-stock_exception Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-warehouse-17-0/stock-logistics-warehouse-17-0-stock_exception/it/
Adding some more info to the description for when exceptions are checked.
detect_exceptions() no longer returns the exceptions: it stores them and raises BaseExceptionError, and the popup is opened by the client error handler through action_popup_exceptions(). - action_confirm() and button_validate() just run the detection and let the error stop the flow, instead of reading its return and opening the popup themselves, which with the new mechanism never happened. - _must_popup_exception() returns True. Without it the default False turns the error into a soft reload: the transfer stays in draft and the user is never told why. - The tests follow the new flow: the confirmation raises and the popup is asked for afterwards, as the client does.
|
The following commit authors need to sign the Contributor License Agreement: |
bosd
left a comment
There was a problem hiding this comment.
Thanks for picking this up. I ran the tests locally with base_exception from OCA/server-tools#3879: the 4 existing tests pass, so the red CI only comes from the missing dependency.
CI fix: until #3879 is merged, add a test-requirements.txt at the repository root (remove it again before merging):
odoo-addon-base_exception @ git+https://github.com/OCA/server-tools.git@refs/pull/3879/head#subdirectory=base_exception
Two more things the new flow breaks, with inline suggestions and tests below. I checked each one locally both ways: the new tests fail without the fix and pass with it (6/6).
stock_check_exceptionruns the detection from thestateconstraint. A picking confirmed in the same transaction that created it (sale or purchase confirmation, procurement) is not committed yet. When a rule matches, the detection writes the exceptions through a second cursor and fails withMissingError: Record does not exist or has been deleted, so the sale order cannot be confirmed. Withbase_exception_no_rollbackthe detection stays in the current transaction, and you get the sameValidationErroras on 17.0.test_all_draft_pickings(the cron) now raisesBaseExceptionErroras soon as one draft picking matches a rule.
| @api.model | ||
| def test_all_draft_pickings(self): | ||
| picking_set = self.search([("state", "=", "draft")]) | ||
| picking_set.detect_exceptions() |
There was a problem hiding this comment.
The cron would now raise BaseExceptionError on the first picking with an exception. Store the exceptions without rolling back:
| picking_set.detect_exceptions() | |
| picking_set.with_context( | |
| base_exception_no_rollback={self._name: picking_set.ids} | |
| ).detect_exceptions() |
| lambda s: s.state in ["waiting", "confirmed", "assigned"] | ||
| ) | ||
| if pickings: | ||
| pickings._check_exception() |
There was a problem hiding this comment.
This is reached from the state constraint, also for pickings that were created earlier in the same transaction and are not committed yet (for example when a sale order is confirmed). The detection then writes the exceptions through a new cursor that cannot see the picking, and fails with MissingError. Keep it in the current transaction:
| pickings._check_exception() | |
| # The pickings may not be committed yet (e.g. created by a sale | |
| # order confirmation): detect in the current transaction. | |
| pickings.with_context( | |
| base_exception_no_rollback={self._name: pickings.ids} | |
| )._check_exception() |
| @@ -0,0 +1,129 @@ | |||
| # Copyright 2024 Open Source Integrators | |||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | |||
| from odoo.tests import Form | |||
There was a problem hiding this comment.
Needed for the new tests below:
| from odoo.tests import Form | |
| from odoo.exceptions import ValidationError | |
| from odoo.tests import Form |
| def test_confirm_picking(self): | ||
| self.assertEqual(self.picking.state, "draft") | ||
| self.picking.action_confirm() | ||
| self.assertEqual(self.picking.state, "assigned") |
There was a problem hiding this comment.
Regression tests for the two fixes in stock.py. Both raise BaseExceptionError without them:
| self.assertEqual(self.picking.state, "assigned") | |
| self.assertEqual(self.picking.state, "assigned") | |
| def test04_confirm_moves_of_new_picking(self): | |
| """A picking confirmed through its moves, in the transaction that | |
| created it (as a sale order confirmation does), reports the exception | |
| instead of failing on the uncommitted picking.""" | |
| self.exception_rule.create( | |
| { | |
| "name": "No Partner", | |
| "model": "stock.picking", | |
| "exception_type": "by_py_code", | |
| "code": "if not self.partner_id: failed=True", | |
| } | |
| ) | |
| picking = self.picking.copy() | |
| self.assertTrue(picking.move_ids) | |
| with self.assertRaisesRegex(ValidationError, "No Partner"): | |
| picking.move_ids._action_confirm() | |
| self.env.flush_all() | |
| def test05_cron_stores_exceptions(self): | |
| self.exception_rule.create( | |
| { | |
| "name": "No Partner", | |
| "model": "stock.picking", | |
| "exception_type": "by_py_code", | |
| "code": "if not self.partner_id: failed=True", | |
| } | |
| ) | |
| self.env["stock.picking"].test_all_draft_pickings() | |
| self.assertTrue(self.picking.exception_ids) |
The state constraint runs the detection for pickings that may not be committed yet, e.g. created by a sale order confirmation. The detection then writes the exceptions through a second cursor that cannot see them, and fails with MissingError. The cron raised BaseExceptionError on the first picking with an exception. Both now store the exceptions without rolling back.
Found by odoo-lint (PO101): these msgids are no longer in the .pot, so Odoo ignores them.
The detection on the pickings now raises as soon as one of their rules applies, so the rules on the stock moves were never checked in that case: only the exceptions of the picking were shown, and a blocking rule on a move could be ignored together with them. Check the moves before raising.
Add demo rules that only apply to a demo customer on credit hold, one that warns on the picking and one that blocks on its moves, and a draft delivery to try them. Describe when the rules are checked, how to configure them, and where and with which text the exceptions are shown: the name and description of the rule, in the popup, the banner on the transfer and the list of transfers.
|
I put my review suggestions, plus a few more improvements, in adhoc-dev#2 against this branch:
Each commit stands on its own. |
The exceptions detected on the moves are stored on their picking, but the error carried the move as target model, so the client did a soft reload instead of opening the popup: the transfer stayed in draft and the user was not told why. Point the target model to the picking, as sale_exception does with the order lines.
|
Thanks @bosd, all six commits are in, each one as it was. That includes the On top of yours I added one fix. A move exception carried That also covers the one doubt I had about check the moves when the picking has an exception: if the move detection raises inside the Agreed on Ignore Exceptions after Validate. I left the behaviour as it was and noted it in the PR body as a known limitation, so it is not lost. |
bosd
left a comment
There was a problem hiding this comment.
Code review and functional test LGTM. The target_model fix for move exceptions matches what sale_exception does for order lines.
Before merging: drop the [DO NOT MERGE] commit once OCA/server-tools#3879 is merged and released. The CLA failure is for authors of commits carried over from 14.0.
A picking confirmed in the transaction that created it (a sale order confirmation, a procurement) is not committed yet, so the cursor that base_exception opens to store the exceptions cannot see it: the write fails and no sale order with a delivery can be confirmed. Check those pickings in the current transaction and raise here, so the exception is still reported. The committed ones keep storing their exceptions through the other cursor, which is what the popup reads after the rollback.
Migration of
stock_exceptionto 19.0, adapted to the currentbase_exception.Why this instead of #2185
#2185 by @JordiMForgeFlow did the migration, and the stale bot closed it on 2026-09-27 without anyone reviewing it. This PR carries its commits unchanged, rebased on the current 19.0, and adds on top the adaptation the module needs: as it stood,
stock_exceptionstill drives the pre-refactor mechanism and silently stops working once thebase_exceptionchanges of #3590 and the ones that followed are in (forward ported in #3879).@JordiMForgeFlow, happy to close this one if you would rather reopen yours and take the last commit.
The adaptation
detect_exceptions()no longer returns the exceptions: it stores them and raisesBaseExceptionError, and the popup is opened by the client error handler throughaction_popup_exceptions().action_confirm()andbutton_validate()just run the detection and let the error stop the flow, instead of reading its return and opening the popup themselves, which with the new mechanism never happened._must_popup_exception()returns True. Without it the defaultFalseturns the error into a soft reload: the transfer stays in draft and the user is never told why.stateconstraint (the transfer may not be committed yet, for example one created by a sale order confirmation, and the second cursor would fail withMissingError) and the cron, which otherwise stopped on the first transfer with an exception.super().detect_exceptions()now raises as soon as it finds one, so they were skipped and a blocking move exception could be ignored together with the others.sale_exceptiondoes with the order lines. Otherwise the client falls back to a soft reload and the user is not told why.base_exception_no_rollback, since the normal flow keeps them in a transaction of its own and rolls this one back.On top of the migration the module also gets demo data (a customer on credit hold with a warning rule on the transfer and a blocking one on its moves, so runboat has something to show: every shipped rule is archived), the CONFIGURE and USAGE fragments, the new OCA icon and a
.pocleanup.Thanks @bosd for the review, the fixes and the documentation: adhoc-dev#2, merged here commit by commit.
Test plan
Run on an Odoo 19 database with
base_exceptionat the state of #3879:CI runs them with
base_exceptionfrom #3879, see Depends on: 10 tests, no failures, with Odoo and with OCB.Depends on
_must_popup_exception(),base_exception_no_rollbackandBaseExceptionErrorcome from #3879, the forward port of thebase_exceptioncommits that are in 18.0 and missing in 19.0. Until that is merged, CI and runboat take it from the PR through the first commit of this one,[DO NOT MERGE] test-requirements.txt, which has to be dropped before merging. That is what makes the test jobs and runboat meaningful here, at the price of Detect unreleased dependencies, which is red by design while that commit is in.Known limitation
After Ignore Exceptions in the popup, the wizard always calls
action_confirm(). When the popup came from Validate, the transfer is not validated and the user has to click Validate again. This is the behaviour of the module as it was, kept as is here and described in USAGE.