mirror of https://github.com/OCA/social.git
[11.0][IMP] mail_activity_widget
parent
978145e969
commit
c3b3dffe97
|
@ -14,10 +14,15 @@
|
|||
'mail_activity_board',
|
||||
],
|
||||
'data': [
|
||||
'views/assets_backend.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'security/mail_activity_team_security.xml',
|
||||
'views/mail_activity_team_views.xml',
|
||||
'views/mail_activity_views.xml',
|
||||
'views/res_users_views.xml',
|
||||
],
|
||||
|
||||
'qweb': [
|
||||
'static/src/xml/systray.xml',
|
||||
],
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from . import mail_activity_team
|
||||
from . import mail_activity
|
||||
from . import res_users
|
||||
from . import mail_activity_mixin
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import api, models, fields, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MailActivityMixin(models.AbstractModel):
|
||||
_inherit = 'mail.activity.mixin'
|
||||
|
||||
activity_team_user_ids = fields.Many2many(
|
||||
comodel_name='res.users', string='test field',
|
||||
compute="_compute_activity_team_user_ids",
|
||||
search="_search_activity_team_user_ids",
|
||||
)
|
||||
|
||||
@api.depends("activity_ids")
|
||||
def _compute_activity_team_user_ids(self):
|
||||
for rec in self:
|
||||
rec.activity_team_user_ids = rec.activity_ids.mapped(
|
||||
"team_id.member_ids")
|
||||
|
||||
@api.model
|
||||
def _search_activity_team_user_ids(self, operator, operand):
|
||||
return [('activity_ids.team_id.member_ids', operator, operand)]
|
|
@ -1,6 +1,6 @@
|
|||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import models, fields
|
||||
from odoo import api, models, fields, modules
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
|
@ -11,3 +11,50 @@ class ResUsers(models.Model):
|
|||
relation='mail_activity_team_users_rel',
|
||||
string="Activity Teams",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def activity_user_count(self):
|
||||
if not self._context.get('team_activities', False):
|
||||
return super().activity_user_count()
|
||||
query = """SELECT m.id, count(*), act.res_model as model,
|
||||
CASE
|
||||
WHEN %(today)s::date - act.date_deadline::date = 0 Then 'today'
|
||||
WHEN %(today)s::date - act.date_deadline::date > 0 Then 'overdue'
|
||||
WHEN %(today)s::date - act.date_deadline::date < 0 Then 'planned'
|
||||
END AS states
|
||||
FROM mail_activity AS act
|
||||
JOIN ir_model AS m ON act.res_model_id = m.id
|
||||
WHERE team_id in (
|
||||
select mail_activity_team_id from mail_activity_team_users_rel
|
||||
where res_users_id =
|
||||
%(user_id)s
|
||||
)
|
||||
GROUP BY m.id, states, act.res_model;
|
||||
"""
|
||||
self.env.cr.execute(query, {
|
||||
'today': fields.Date.context_today(self),
|
||||
'user_id': self.env.uid,
|
||||
})
|
||||
activity_data = self.env.cr.dictfetchall()
|
||||
model_ids = [a['id'] for a in activity_data]
|
||||
model_names = {n[0]: n[1] for n in
|
||||
self.env['ir.model'].browse(model_ids).name_get()}
|
||||
|
||||
user_activities = {}
|
||||
for activity in activity_data:
|
||||
if not user_activities.get(activity['model']):
|
||||
user_activities[activity['model']] = {
|
||||
'name': model_names[activity['id']],
|
||||
'model': activity['model'],
|
||||
'icon': modules.module.get_module_icon(
|
||||
self.env[activity['model']]._original_module),
|
||||
'total_count': 0, 'today_count': 0, 'overdue_count': 0,
|
||||
'planned_count': 0,
|
||||
}
|
||||
user_activities[activity['model']][
|
||||
'%s_count' % activity['states']] += activity['count']
|
||||
if activity['states'] in ('today', 'overdue'):
|
||||
user_activities[activity['model']]['total_count'] += activity[
|
||||
'count']
|
||||
|
||||
return list(user_activities.values())
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
odoo.define('mail_activity_team.systray', function (require) {
|
||||
"use strict";
|
||||
|
||||
var systray = require('mail.systray');
|
||||
var session = require("web.session");
|
||||
|
||||
systray.ActivityMenu.include({
|
||||
events: _.extend({}, systray.ActivityMenu.prototype.events, {
|
||||
'click .o_filter_button': 'on_click_filter_button',
|
||||
}),
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$filter_buttons = this.$('.o_filter_button');
|
||||
this.filter = 'my';
|
||||
},
|
||||
on_click_filter_button: function (event) {
|
||||
var self = this;
|
||||
|
||||
event.stopPropagation();
|
||||
self.$filter_buttons.removeClass('active');
|
||||
var $target = $(event.currentTarget);
|
||||
$target.addClass('active');
|
||||
self.filter = $target.data('filter');
|
||||
if (self.filter == 'team'){
|
||||
session.user_context = _.extend({}, session.user_context, {
|
||||
'team_activities': true
|
||||
});
|
||||
}
|
||||
else if (self.filter == 'my'){
|
||||
session.user_context = _.extend({}, session.user_context, {
|
||||
'team_activities': false
|
||||
});
|
||||
}
|
||||
self._updateActivityPreview();
|
||||
|
||||
},
|
||||
_onActivityFilterClick: function (event){
|
||||
if (this.filter == 'my'){
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
if (this.filter == 'team'){
|
||||
var data = _.extend({}, $(event.currentTarget).data(), $(event.target).data());
|
||||
var context = {};
|
||||
if (data.filter === 'my') {
|
||||
context['search_default_activities_overdue'] = 1;
|
||||
context['search_default_activities_today'] = 1;
|
||||
} else {
|
||||
context['search_default_activities_' + data.filter] = 1;
|
||||
}
|
||||
this.do_action({
|
||||
type: 'ir.actions.act_window',
|
||||
name: data.model_name,
|
||||
res_model: data.res_model,
|
||||
views: [[false, 'kanban'], [false, 'form']],
|
||||
search_view_id: [false],
|
||||
domain: ['|', ['activity_user_id', '=', session.uid], ['activity_team_user_ids', 'in', session.uid]],
|
||||
context:context,
|
||||
});
|
||||
}
|
||||
},
|
||||
/*
|
||||
_getActivityData: function(){
|
||||
var self = this;
|
||||
this._super.apply(this, arguments).then(function () {
|
||||
|
||||
});
|
||||
},*/
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
|
||||
<t t-extend="mail.chat.ActivityMenu">
|
||||
<t t-jquery=".o_mail_navbar_dropdown_channels" t-operation="before">
|
||||
<li class="o_mail_navbar_dropdown_top">
|
||||
<div>
|
||||
<button type="button" class="btn btn-sm o_filter_button active" data-filter='my'> My Activities </button>
|
||||
<button type="button" class="btn btn-sm o_filter_button" data-filter='team'> Team Activities </button>
|
||||
</div>
|
||||
</li>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="assets_backend" name="mail assets"
|
||||
inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/mail_activity_team/static/src/js/systray.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
|
@ -5,7 +5,7 @@
|
|||
<field name="name">mail.activity.view.form.popup</field>
|
||||
<field name="model">mail.activity</field>
|
||||
<field name="inherit_id" ref="mail.mail_activity_view_form_popup"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="arch" type="xml">s
|
||||
<field name="user_id" position="after">
|
||||
<field name="team_id" options="{'no_create': True, 'no_open': True}"/>
|
||||
</field>
|
||||
|
|
Loading…
Reference in New Issue