Permalink
Browse files

[IMP]improve the code

  • Loading branch information...
mba-odoo committed Dec 6, 2018
1 parent 1529d20 commit a97fbb8d66f9b6fcf3daa9778a16d75982648f9e
@@ -432,35 +432,32 @@ def get_activity_data(self, res_model, domain, options):
['res_id', 'activity_type_id', 'res_name:max(res_name)', 'ids:array_agg(id)', 'date_deadline:min(date_deadline)'],
['res_id', 'activity_type_id'],
lazy=False)
activity_type_ids = self.env['mail.activity.type']
res_id_to_name = {}
res_id_to_deadline = {}
activity_data = defaultdict(dict)
for group in grouped_activities:
res_id = group['res_id']
res_name = group['res_name']
activity_type_id = group['activity_type_id'][0]
activity_type_ids |= self.env['mail.activity.type'].browse(activity_type_id) # we will get the name when reading mail_template_ids
res_id_to_name[res_id] = res_name
res_id_to_deadline[res_id] = group['date_deadline'] if (res_id not in res_id_to_deadline or group['date_deadline'] < res_id_to_deadline[res_id]) else res_id_to_deadline[res_id]
state = self._compute_state_from_date(group['date_deadline'], self.user_id.sudo().tz)
activity_data[res_id][activity_type_id] = {
activity_data[res_id][group['activity_type_id'][0]] = {
'count': group['__count'],
'ids': group['ids'],
'state': state,
'o_closest_deadline': group['date_deadline'],
}
res_ids_sorted = sorted(res_id_to_deadline, key=lambda item: res_id_to_deadline[item])
activity_type_infos = []
for elem in sorted(self.env['mail.activity.type'].search(['|', ('res_model_id.model', '=', res_model), ('res_model_id', '=', False)]), key=lambda item: item.sequence):
activity_type_ids = self.env['mail.activity.type'].search(['|', ('res_model_id.model', '=', res_model), ('res_model_id', '=', False)])
for elem in sorted(activity_type_ids, key=lambda item: item.sequence):
mail_template_info = []
for mail_template_id in elem.mail_template_ids:
mail_template_info.append({"id": mail_template_id.id, "name": mail_template_id.name})
activity_type_infos.append({
'id': elem.id,
'name': elem.name,
'template_list': mail_template_info,
'progressbar_enabled': elem.id in activity_type_ids.ids and True or False,
})
data_subtitle = options.get('data_subtitle')
@@ -67,9 +67,12 @@ var ActivityRenderer = AbstractRenderer.extend({
*/
_renderHeader: function () {
var self = this;
var activityTypeIDs = _.unique(_.map(self.state.data.grouped_activities, function(item) {
return parseInt(_.keys(item)[0]);
}));
var $cells = _.map(this.state.data.activity_types, function (type) {
var $th = $(self._renderHeaderCell(type));
if (type.progressbar_enabled) {
if (_.contains(activityTypeIDs, type.id)) {
core.bus.on('tweak_activity_records', self, self._onTweakActivityRecords);
var colors = {planned: 'success', today: 'warning', overdue: 'danger'};
var availColors = {};
@@ -50,22 +50,18 @@ var ACTIVITY_DATA = {
"name":"Task: Reception Acknowledgment"
}
],
'progressbar_enabled': true,
},{
'id': 2,
'name': "Call",
'template_list': [],
'progressbar_enabled': true,
},{
'id': 3,
'name': "Call for Demo",
'template_list': [],
'progressbar_enabled': false,
},{
'id': 4,
'name': "To Do",
'template_list': [],
'progressbar_enabled': false,
}
],
"model":"task",

0 comments on commit a97fbb8

Please sign in to comment.