generic_condition: Deny unlink if used
Idea
Generic Conditions are usualy linked as many2many lists to objects. And we need to prevent deletion of condition that is used by some objects (For example when condition is used by base_automation
rules)
Example of usage
Conditions are used by module generic_condition_automation
. Thus, if generic condition is used by at least one automation rule, then error have is raise when condition to be deleted!
To Do
-
Add Postgresql View that will list conditions with info about objects that use these conditions
-
Create SQL view with conlums
condition_id
model_id
model_name
-
field_id
: field that points to condition -
field_name
: name of field that points to condition -
relation
: it it is many2many field that place here name of relation table (*_rel
) -
record_id
: ID of record that points to this condition.
-
Create model to wrap this view
- all fields are readonly
- access rights: readonly for all
-
Add list (tree) view for this model
- create=false,
- delete=false,
- edit=false,
- copy=false
-
On generic condition form add stat-button Used by:
- show number of object that uses this condition
- on click open that objects in list (list view for model based on created Postgresql View)
- On generic condition tree view show number of objects that use this condition.
-
Create SQL view with conlums
-
In condition
unlink
method check if condition is used somewhere. If so, then raiseUserError
with information about objects that use that condition. -
Add context key
_force_unlink_condition_
that allows to ignore condition usage check on delete (unlink). - Add tests for this bechavior.