[FIX] Force safer ondelete=restrict on the `alias_id` _inherits FK on models with...
authorOlivier Dony <odo@openerp.com>
Tue, 27 Aug 2013 15:07:08 +0000 (17:07 +0200)
committerOlivier Dony <odo@openerp.com>
Tue, 27 Aug 2013 15:07:08 +0000 (17:07 +0200)
The delete-rule was initially set to `cascade` in revision
6897.16.13 revid:odo@openerp.com-20120705141706-5gm5mmqode3bvkuc
because the ORM would not allow anything else for the FK of
an _inherits relationship.
This constraint was later lifted in 7.0 server at revision
4681 revid:odo@openerp.com-20121212210247-emrz5rf9ewcwdggu
so we can now switch to the intended default behavior:
when deleting mail aliases we never want to cascade delete
the child records, as that could lead to unwanted deletions.
On the other hand the aliases are automatically deleted when
the record they belong to is deleted, as a kind of internal
dependency. This is the intended safe way to delete them.

There is a special case when the same alias is manually set
on multiple records, in which case you will not be able to
delete any of those records. This is an acceptable exception
and should be manually handled if ever needed, by temporarily
linking the records to delete to new dummy aliases.

bzr revid: odo@openerp.com-20130827150708-62hqk8p7twd527n0

addons/crm/crm.py
addons/hr_recruitment/hr_recruitment.py
addons/mail/mail_group.py
addons/mail/res_users.py
addons/project/project.py

index df6d5e1..5953500 100644 (file)
@@ -125,7 +125,7 @@ class crm_case_section(osv.osv):
         'note': fields.text('Description'),
         'working_hours': fields.float('Working Hours', digits=(16,2 )),
         'stage_ids': fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'),
-        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
                                     help="The email address associated with this team. New emails received will automatically "
                                          "create new leads assigned to the team."),
     }
index 6dfc086..d97a6ee 100644 (file)
@@ -496,7 +496,7 @@ class hr_job(osv.osv):
     _inherits = {'mail.alias': 'alias_id'}
     _columns = {
         'survey_id': fields.many2one('survey', 'Interview Form', help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job"),
-        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
                                     help="Email alias for this job position. New emails will automatically "
                                          "create new applicants for this job position."),
     }
index 977608f..481109a 100644 (file)
@@ -76,7 +76,7 @@ class mail_group(osv.Model):
             help="Small-sized photo of the group. It is automatically "\
                  "resized as a 64x64px image, with aspect ratio preserved. "\
                  "Use this field anywhere a small image is required."),
-        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
             help="The email address associated with this group. New emails received will automatically "
                  "create new topics."),
     }
index f7c9193..c6a935a 100644 (file)
@@ -34,7 +34,7 @@ class res_users(osv.Model):
     _inherits = {'mail.alias': 'alias_id'}
 
     _columns = {
-        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
             help="Email address internally associated with this user. Incoming "\
                  "emails will appear in the user's notifications."),
     }
index 8ffd64e..d7794a0 100644 (file)
@@ -281,7 +281,7 @@ class project(osv.osv):
         'type_ids': fields.many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
         'task_count': fields.function(_task_count, type='integer', string="Open Tasks"),
         'color': fields.integer('Color Index'),
-        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+        'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
                                     help="Internal email associated with this project. Incoming emails are automatically synchronized"
                                          "with Tasks (or optionally Issues if the Issue Tracker module is installed)."),
         'alias_model': fields.selection(_alias_models, "Alias Model", select=True, required=True,