Rational
Following Generic support for cache fields, I found that we have 3 common pattern that requires to extend ModelStorage.create
, ModelStorage.write
and ModelStorage.delete
which may be tricky to extend correctly (see Verify access right only for RPC):
- apply some modification to the
values
used forModelStorage.create
andModelStorage.write
(ex: standardize the format of email, put in uppercase the country code, set number from a sequence etc.) - trigger an action on modified records (ex: clear a cache, call workflow transition of linked record etc.)
- check if record can be modified (ex: forbid modification of posted move)
Proposal
I propose to add 3 new hooks in ModelStorage
:
preprocess_values(cls, mode, values)
which is called byModelStorage.create
andModelStorage.write
with each values and must return the modified value (preferably a copy if modified).on_modification(cls, mode, records, field_names=None)
which is called byModelStorage.create
,ModelStorage.write
at the end and byModelStorage.delete
at the beginning. Thefield_names
contains at least all the fields that have been modified.check_modification(cls, records, values)
which is called only byModelStorage.write
at the beginning.