From 22051dcc1b308ad05fc08e6d14cb9b87ffede78c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 9 Feb 2016 16:55:39 +0100 Subject: [PATCH] [FIX] calendar: To avoid duplicate contacts Before the fix dda8e2211a2f1d99a2994689b8544dd6b7f03a62, the duplicate records were erased thanks to the index used in the dictionary(id of the partner). After this fix, to avoid this this problem, the label of each record is used as key in the dictionary. --- addons/calendar/contacts.py | 2 -- addons/calendar/static/src/js/base_calendar.js | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/addons/calendar/contacts.py b/addons/calendar/contacts.py index 7a32dc4d1a1..4fe5cdf6097 100644 --- a/addons/calendar/contacts.py +++ b/addons/calendar/contacts.py @@ -5,13 +5,11 @@ from openerp.osv import fields, osv class calendar_contacts(osv.osv): _name = 'calendar.contacts' - _order = "name" _columns = { 'user_id': fields.many2one('res.users','Me'), 'partner_id': fields.many2one('res.partner','Employee',required=True, domain=[]), 'active':fields.boolean('active'), - 'name': fields.related('partner_id', 'display_name', type='char', string='Partner Contact Name', readonly=True), } _defaults = { 'user_id': lambda self, cr, uid, ctx: uid, diff --git a/addons/calendar/static/src/js/base_calendar.js b/addons/calendar/static/src/js/base_calendar.js index 42beb31aded..44e94d32f19 100644 --- a/addons/calendar/static/src/js/base_calendar.js +++ b/addons/calendar/static/src/js/base_calendar.js @@ -38,8 +38,8 @@ function reload_favorite_list(result) { is_checked: true, is_remove: false, }; - sidebar_items[0] = filter_item ; - + sidebar_items[1] = filter_item ; + filter_item = { value: -1, label: _lt("Everybody's calendars"), @@ -50,7 +50,7 @@ function reload_favorite_list(result) { sidebar_items[-1] = filter_item ; //Get my coworkers/contacts new Model("calendar.contacts").query(["partner_id"]).filter([["user_id", "=",self.dataset.context.uid]]).all().then(function(result) { - var i = 1; + var unsorted_res = {}; _.each(result, function(item) { filter_value = item.partner_id[0]; filter_item = { @@ -60,8 +60,13 @@ function reload_favorite_list(result) { avatar_model: self.avatar_model, is_checked: true }; - sidebar_items[i++] = filter_item ; + unsorted_res[filter_item.label + " " +filter_value] = filter_item; }); + var i = 2; + _.keys(unsorted_res).sort().forEach(function(key){ + sidebar_items[i++] = unsorted_res[key]; + }); + self.all_filters = sidebar_items; self.now_filter_ids = $.map(self.all_filters, function(o) { return o.value; });