-
- Downloads
[FIX] account: unique constraint in sequence mixin
Change the way the uniqueness of the sequence numbers is ensured.
Instead of using a `SELECT FOR UPDATE` approach inspired from the
`ir.sequence`, or even a true UPDATE, we can use a constraint approach.
SELECT FOR UPDATE
=================
By doing a FOR UPDATE NO WAIT, we are throwing an exception when another
transaction is creating a move using the same sequence as this one, by
locking the row that holds the current greatest sequence.
Since the row doesn't change, the lock is released and the following
UPDATE is allowed. Because of this, a "useless" UPDATE was always done
on the previous row to ensure a SerializationFailureError if two
concurrent transactions were trying to assign the same number.
This means that in a database with a lot of concurrent transactions
(typically with an online shop), many transactions were
aborted/rollbacked.
This approach also has the drawback of having the constraint implemented
python side, which is less robust.
UNIQUE CONSTRAINT
=================
Using a constraint on the database level means that the database knows
when some transactions will try to do something similar. It will
therefore make the concurrent transactions wait instead of aborting the
transaction.
It is however harder to have the constraint customized by different
modules/localization because it is now done directly in the database and
not in python. Changing the constraint means deleting/recreating the
index. For now, this only happens for Latin America l10n, so a simple
hardcoded approach is implemented.
In order to achieve this, the business code is trying to use the
sequence incrementally until it gets a number it can use for when
multiple transactions are concurrent.
closes odoo/odoo#104606
Related: odoo/enterprise#34236
Signed-off-by:
Quentin De Paoli <qdp@odoo.com>
Showing
- addons/account/models/account_move.py 7 additions, 64 deletionsaddons/account/models/account_move.py
- addons/account/tests/test_sequence_mixin.py 5 additions, 5 deletionsaddons/account/tests/test_sequence_mixin.py
- addons/account_sequence/__init__.py 1 addition, 0 deletionsaddons/account_sequence/__init__.py
- addons/account_sequence/__manifest__.py 16 additions, 0 deletionsaddons/account_sequence/__manifest__.py
- addons/account_sequence/models/__init__.py 2 additions, 0 deletionsaddons/account_sequence/models/__init__.py
- addons/account_sequence/models/account_move.py 54 additions, 0 deletionsaddons/account_sequence/models/account_move.py
- addons/account_sequence/models/sequence_mixin.py 42 additions, 0 deletionsaddons/account_sequence/models/sequence_mixin.py
- addons/l10n_latam_account_sequence/__init__.py 1 addition, 0 deletionsaddons/l10n_latam_account_sequence/__init__.py
- addons/l10n_latam_account_sequence/__manifest__.py 16 additions, 0 deletionsaddons/l10n_latam_account_sequence/__manifest__.py
- addons/l10n_latam_account_sequence/models/__init__.py 1 addition, 0 deletionsaddons/l10n_latam_account_sequence/models/__init__.py
- addons/l10n_latam_account_sequence/models/account_move.py 32 additions, 0 deletionsaddons/l10n_latam_account_sequence/models/account_move.py
Loading