summaryrefslogtreecommitdiff
path: root/addons/note
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-04-23 13:52:59 +0200
committerThibault Delavallée <tde@odoo.com>2018-04-26 16:44:22 +0200
commit1d7c12f9bf44cdd9961031676628f740f18fc837 (patch)
tree9af685111171b23e859ba5b8691bb8ef4ece38b6 /addons/note
parent535490a073934a1950989dcb56461dc6db326780 (diff)
[FIX][IMP] note: create default note columns for existing users
Otherwise users that already exist when installing note module do not have any default columns for note leading to an incoherent behavior, especially with reminders. Done after feedback from saas-11.3 internal testing phase. This commit is linked to task ID 1838917.
Diffstat (limited to 'addons/note')
-rw-r--r--addons/note/__manifest__.py1
-rw-r--r--addons/note/data/res_users_data.xml9
-rw-r--r--addons/note/models/res_users.py40
3 files changed, 44 insertions, 6 deletions
diff --git a/addons/note/__manifest__.py b/addons/note/__manifest__.py
index 02cb893ca1d..809bc36847b 100644
--- a/addons/note/__manifest__.py
+++ b/addons/note/__manifest__.py
@@ -17,6 +17,7 @@
'security/ir.model.access.csv',
'data/mail_activity_data.xml',
'data/note_data.xml',
+ 'data/res_users_data.xml',
'views/note_views.xml',
'views/note_templates.xml',
'views/mail_activity_views.xml',
diff --git a/addons/note/data/res_users_data.xml b/addons/note/data/res_users_data.xml
new file mode 100644
index 00000000000..874982a310b
--- /dev/null
+++ b/addons/note/data/res_users_data.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<odoo>
+ <data noupdate="1">
+ <function id="init_data_user_note_stages"
+ model="res.users"
+ name="_init_data_user_note_stages"
+ eval="[]"/>
+ </data>
+</odoo>
diff --git a/addons/note/models/res_users.py b/addons/note/models/res_users.py
index be218c27b28..ed71c702f7c 100644
--- a/addons/note/models/res_users.py
+++ b/addons/note/models/res_users.py
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import logging
+
from odoo import api, models, modules, _
+_logger = logging.getLogger(__name__)
-class Users(models.Model):
+class Users(models.Model):
_name = 'res.users'
_inherit = ['res.users']
@@ -14,20 +17,45 @@ class Users(models.Model):
user = super(Users, self).create(values)
# for new employee, create his own 5 base note stages
if user.has_group('base.group_user'):
- for num in range(4):
- stage = self.env.ref('note.note_stage_%02d' % (num,), raise_if_not_found=False)
- if stage:
- stage.sudo().copy(default={'user_id': user.id})
+ user._create_note_stages()
return user
@api.model
+ def _init_data_user_note_stages(self):
+ emp_group_id = self.env.ref('base.group_user').id
+ query = """
+SELECT res_users.id
+FROM res_users
+WHERE res_users.active IS TRUE AND EXISTS (
+ SELECT 1 FROM res_groups_users_rel WHERE res_groups_users_rel.gid = %s AND res_groups_users_rel.uid = res_users.id
+) AND NOT EXISTS (
+ SELECT 1 FROM note_stage stage WHERE stage.user_id = res_users.id
+)
+GROUP BY id"""
+ self.env.cr.execute(query, (emp_group_id,))
+ uids = [res[0] for res in self.env.cr.fetchall()]
+ self.browse(uids)._create_note_stages()
+
+ def _create_note_stages(self):
+ data_found = False
+ for num in range(4):
+ stage = self.env.ref('note.note_stage_%02d' % (num,), raise_if_not_found=False)
+ data_found = True
+ if stage:
+ for user in self:
+ stage.sudo().copy(default={'user_id': user.id})
+ if data_found:
+ for user in self:
+ _logger.info('Note default columns created for user id %s', user.id)
+
+ @api.model
def activity_user_count(self):
""" If user have not scheduled any note, it will not appear in activity menu.
Making note activity always visible with number of notes on label. If there is no notes,
activity menu not visible for note.
"""
activities = super(Users, self).activity_user_count()
- notes_count = self.env['note.note'].search_count([('user_id', '=', self.env.uid), ('open', '=', True)])
+ notes_count = self.env['note.note'].search_count([('user_id', '=', self.env.uid)])
if notes_count:
note_index = next((index for (index, a) in enumerate(activities) if a["model"] == "note.note"), None)
note_label = ("%s (%d)") % (_('Notes'), notes_count)