summaryrefslogtreecommitdiff
path: root/addons/note/controllers/note.py
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2019-04-02 13:13:02 +0000
committerThibault Delavallée <tde@odoo.com>2019-11-25 14:17:31 +0000
commit0eadc0aa5ea53943738e43b3ec1c9bff3ef30922 (patch)
tree1a3358a721e1c5d6d6d537f84a97153f6a00a8d3 /addons/note/controllers/note.py
parentb7983df87a97765b83d5c012c9f252a501d94d77 (diff)
[IMP] mail: better prevent activity type removal and add a fallback mechanism
Current activity types master data cannot be unlinked through a quite harsh override of unlink using xml id existence, introduced at 2602642a78dff6c15d615fadf4c55a6b6ca315df. Some of them are real master data, other could be unlinked if users want it. Finally custom activity types may cause errors when removed if used in some side models like server actions or automated actions. To allow more flexibility we remove the removal constraint and implement a fallback mechanism. It is implemented in mail.activity.mixin when calling activity_schedule(xmlid, ...). If the given xmlid is not found _default_activity_type() specifies the default activity to use. It can be overridden in modules if some specific behavior is wanted. e.g. def _default_activity_type(self): """Define a default fallback activity type when xml id not found only used in in activity_schedule() for now. """ try: return self.env.ref('mail.mail_activity_data_todo') except Exception: return False In this commit we also * restrict deletion of activity type (hr.plan and ir.actions.server); * fallback on default activity type if xmlid ref not found in activity_schedule; * correct calls to activity_schedule and replace some manual creation calls by activity_schedule; Task ID 1961156 PR #39013 Related: odoo/enterprise#6238 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Co-authored-by: Victor Feyens <vfe@odoo.com> Co-authored-by: Michaël Mattiello <mcm@odoo.com>
Diffstat (limited to 'addons/note/controllers/note.py')
-rw-r--r--addons/note/controllers/note.py17
1 files changed, 5 insertions, 12 deletions
diff --git a/addons/note/controllers/note.py b/addons/note/controllers/note.py
index bdcf2e85059..6cafea730cf 100644
--- a/addons/note/controllers/note.py
+++ b/addons/note/controllers/note.py
@@ -12,16 +12,9 @@ class NoteController(http.Controller):
""" Route to create note and their activity directly from the systray """
note = request.env['note.note'].create({'memo': note})
if date_deadline:
- activity_values = {
- 'note': note.memo,
- 'date_deadline': date_deadline,
- 'res_model_id': request.env.ref("note.model_note_note").id,
- 'res_id': note.id,
- 'note_id': note.id,
- }
- if not activity_type_id:
- activity_type_id = request.env['mail.activity.type'].sudo().search([('category', '=', 'reminder')], limit=1).id
- if activity_type_id:
- activity_values['activity_type_id'] = activity_type_id
- request.env['mail.activity'].create(activity_values)
+ note.activity_schedule(
+ activity_type_id=activity_type_id or request.env['mail.activity.type'].sudo().search([('category', '=', 'reminder')], limit=1).id,
+ note=note.memo,
+ date_deadline=date_deadline
+ )
return note.id