diff --git a/mail_activity_board/__manifest__.py b/mail_activity_board/__manifest__.py index a13100d..c369f21 100644 --- a/mail_activity_board/__manifest__.py +++ b/mail_activity_board/__manifest__.py @@ -1,24 +1,16 @@ # Copyright 2018 David Juaneda - # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Activities board', - 'summary': 'Add Activity Boards', - 'version': '12.0.1.0.0', - 'development_status': 'Beta', - 'category': 'Social Network', - 'website': 'https://github.com/OCA/social', - 'author': 'SDi, David Juaneda, Odoo Community Association (OCA)', - 'license': 'AGPL-3', - 'installable': True, - 'depends': [ - 'calendar', - 'board', - ], - 'data': [ - 'views/templates.xml', - 'views/mail_activity_view.xml', - ], - 'qweb': [ - 'static/src/xml/inherit_chatter.xml', - ] + "name": "Activities board", + "summary": "Add Activity Boards", + "version": "13.0.1.0.0", + "development_status": "Beta", + "category": "Social Network", + "website": "https://github.com/OCA/social", + "author": "SDi, David Juaneda, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["calendar", "board"], + "data": ["views/templates.xml", "views/mail_activity_view.xml"], + "qweb": ["static/src/xml/inherit_chatter.xml"], } diff --git a/mail_activity_board/models/mail_activity.py b/mail_activity_board/models/mail_activity.py index 817acde..7f8b76e 100644 --- a/mail_activity_board/models/mail_activity.py +++ b/mail_activity_board/models/mail_activity.py @@ -1,99 +1,119 @@ # Copyright 2018 David Juaneda - # 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, SUPERUSER_ID +from odoo import SUPERUSER_ID, api, fields, models class MailActivity(models.Model): _inherit = "mail.activity" res_model_id_name = fields.Char( - related='res_model_id.name', string="Origin", - readonly=True) - duration = fields.Float( - related='calendar_event_id.duration', readonly=True) + related="res_model_id.name", string="Origin", readonly=True + ) + duration = fields.Float(related="calendar_event_id.duration", readonly=True) calendar_event_id_start = fields.Datetime( - related='calendar_event_id.start', readonly=True) + related="calendar_event_id.start", readonly=True + ) calendar_event_id_partner_ids = fields.Many2many( - related='calendar_event_id.partner_ids', - readonly=True) + related="calendar_event_id.partner_ids", readonly=True + ) - @api.multi def open_origin(self): self.ensure_one() vid = self.env[self.res_model].browse(self.res_id).get_formview_id() response = { - 'type': 'ir.actions.act_window', - 'res_model': self.res_model, - 'view_mode': 'form', - 'res_id': self.res_id, - 'target': 'current', - 'flags': { - 'form': { - 'action_buttons': False - } - }, - 'views': [ - (vid, "form") - ] + "type": "ir.actions.act_window", + "res_model": self.res_model, + "view_mode": "form", + "res_id": self.res_id, + "target": "current", + "flags": {"form": {"action_buttons": False}}, + "views": [(vid, "form")], } return response @api.model def action_activities_board(self): - action = self.env.ref( - 'mail_activity_board.open_boards_activities').read()[0] + action = self.env.ref("mail_activity_board.open_boards_activities").read()[0] return action @api.model def _find_allowed_model_wise(self, doc_model, doc_dict): doc_ids = list(doc_dict) - allowed_doc_ids = self.env[doc_model].with_context( - active_test=False).search([('id', 'in', doc_ids)]).ids - return set([message_id for allowed_doc_id in allowed_doc_ids - for message_id in doc_dict[allowed_doc_id]]) + allowed_doc_ids = ( + self.env[doc_model] + .with_context(active_test=False) + .search([("id", "in", doc_ids)]) + .ids + ) + return { + message_id + for allowed_doc_id in allowed_doc_ids + for message_id in doc_dict[allowed_doc_id] + } @api.model def _find_allowed_doc_ids(self, model_ids): - ir_model_access_model = self.env['ir.model.access'] + ir_model_access_model = self.env["ir.model.access"] allowed_ids = set() for doc_model, doc_dict in model_ids.items(): - if not ir_model_access_model.check(doc_model, 'read', False): + if not ir_model_access_model.check(doc_model, "read", False): continue allowed_ids |= self._find_allowed_model_wise(doc_model, doc_dict) return allowed_ids @api.model - def _search(self, args, offset=0, limit=None, order=None, count=False, - access_rights_uid=None): + def _search( + self, + args, + offset=0, + limit=None, + order=None, + count=False, + access_rights_uid=None, + ): # Rules do not apply to administrator if self._uid == SUPERUSER_ID: return super(MailActivity, self)._search( - args, offset=offset, limit=limit, order=order, - count=count, access_rights_uid=access_rights_uid) + args, + offset=offset, + limit=limit, + order=order, + count=count, + access_rights_uid=access_rights_uid, + ) ids = super(MailActivity, self)._search( - args, offset=offset, limit=limit, order=order, - count=False, access_rights_uid=access_rights_uid) + args, + offset=offset, + limit=limit, + order=order, + count=False, + access_rights_uid=access_rights_uid, + ) if not ids and count: return 0 elif not ids: return ids # check read access rights before checking the actual rules - super(MailActivity, self.sudo(access_rights_uid or self._uid)).\ - check_access_rights('read') + super( + MailActivity, self.with_user(access_rights_uid or self._uid) + ).check_access_rights("read") model_ids = {} - self._cr.execute(""" + self._cr.execute( + """ SELECT DISTINCT a.id, im.id, im.model, a.res_id FROM "%s" a LEFT JOIN ir_model im ON im.id = a.res_model_id - WHERE a.id = ANY (%%(ids)s)""" % self._table, dict(ids=ids)) - for a_id, ir_model_id, model, model_id in self._cr.fetchall(): - model_ids.setdefault(model, {}).setdefault( - model_id, set()).add(a_id) + WHERE a.id = ANY (%%(ids)s)""" + % self._table, + dict(ids=ids), + ) + for a_id, _ir_model_id, model, model_id in self._cr.fetchall(): + model_ids.setdefault(model, {}).setdefault(model_id, set()).add(a_id) allowed_ids = self._find_allowed_doc_ids(model_ids) diff --git a/mail_activity_board/models/mail_activity_mixin.py b/mail_activity_board/models/mail_activity_mixin.py index 788c332..5ab4ede 100644 --- a/mail_activity_board/models/mail_activity_mixin.py +++ b/mail_activity_board/models/mail_activity_mixin.py @@ -4,7 +4,7 @@ from odoo import models class MailActivityMixin(models.AbstractModel): - _inherit = 'mail.activity.mixin' + _inherit = "mail.activity.mixin" def redirect_to_activities(self, **kwargs): """Redirects to the list of activities of the object shown. @@ -21,12 +21,12 @@ class MailActivityMixin(models.AbstractModel): :return: action. """ _id = kwargs.get("id") - action = self.env['mail.activity'].action_activities_board() + action = self.env["mail.activity"].action_activities_board() views = [] - for v in action['views']: - if v[1] == 'tree': - v = (v[0], 'list') + for v in action["views"]: + if v[1] == "tree": + v = (v[0], "list") views.append(v) - action['views'] = views - action['domain'] = [('res_id', '=', _id)] + action["views"] = views + action["domain"] = [("res_id", "=", _id)] return action diff --git a/mail_activity_board/readme/CONTRIBUTORS.rst b/mail_activity_board/readme/CONTRIBUTORS.rst index f2a8d5e..5c49273 100644 --- a/mail_activity_board/readme/CONTRIBUTORS.rst +++ b/mail_activity_board/readme/CONTRIBUTORS.rst @@ -5,3 +5,7 @@ * `Eficent `_: * Miquel Raïch (miquel.raich@eficent.com) + +* `Pesol `_: + + * Pedro Gonzalez (pedro.gonzalez@pesol.es) diff --git a/mail_activity_board/readme/DESCRIPTION.rst b/mail_activity_board/readme/DESCRIPTION.rst index 99d1c55..925a1c0 100644 --- a/mail_activity_board/readme/DESCRIPTION.rst +++ b/mail_activity_board/readme/DESCRIPTION.rst @@ -1,2 +1 @@ This module adds an activity board with form, tree, kanban, calendar, pivot, graph and search views. - diff --git a/mail_activity_board/static/src/xml/inherit_chatter.xml b/mail_activity_board/static/src/xml/inherit_chatter.xml index 5fee3e7..1cc45f0 100644 --- a/mail_activity_board/static/src/xml/inherit_chatter.xml +++ b/mail_activity_board/static/src/xml/inherit_chatter.xml @@ -1,10 +1,10 @@ - + - + - diff --git a/mail_activity_board/tests/test_mail_activity_board.py b/mail_activity_board/tests/test_mail_activity_board.py index aa23da9..1b02568 100644 --- a/mail_activity_board/tests/test_mail_activity_board.py +++ b/mail_activity_board/tests/test_mail_activity_board.py @@ -4,104 +4,138 @@ from odoo.tests.common import TransactionCase class TestMailActivityBoardMethods(TransactionCase): - def setUp(self): super(TestMailActivityBoardMethods, self).setUp() # Set up activities # Create a user as 'Crm Salesman' and added few groups - self.employee = self.env['res.users'].create({ - 'company_id': self.env.ref("base.main_company").id, - 'name': "Employee", - 'login': "csu", - 'email': "crmuser@yourcompany.com", - 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])] - }) + self.employee = self.env["res.users"].create( + { + "company_id": self.env.ref("base.main_company").id, + "name": "Employee", + "login": "csu", + "email": "crmuser@yourcompany.com", + "groups_id": [(6, 0, [self.env.ref("base.group_user").id])], + } + ) # Create a user who doesn't have access to anything except activities mail_activity_group = self.create_mail_activity_group() - self.employee2 = self.env['res.users'].create({ - 'company_id': self.env.ref("base.main_company").id, - 'name': "Employee2", - 'login': "alien", - 'email': "alien@yourcompany.com", - 'groups_id': [(6, 0, [mail_activity_group.id])], - }) + self.employee2 = self.env["res.users"].create( + { + "company_id": self.env.ref("base.main_company").id, + "name": "Employee2", + "login": "alien", + "email": "alien@yourcompany.com", + "groups_id": [(6, 0, [mail_activity_group.id])], + } + ) # lead_model_id = self.env['ir.model']._get('crm.lead').id - partner_model_id = self.env['ir.model']._get('res.partner').id + partner_model_id = self.env["ir.model"]._get("res.partner").id - ActivityType = self.env['mail.activity.type'] - self.activity1 = ActivityType.create({ - 'name': 'Initial Contact', - 'days': 5, - 'summary': 'ACT 1 : Presentation, barbecue, ... ', - 'res_model_id': partner_model_id, - }) - self.activity2 = ActivityType.create({ - 'name': 'Call for Demo', - 'days': 6, - 'summary': 'ACT 2 : I want to show you my ERP !', - 'res_model_id': partner_model_id, - }) - self.activity3 = ActivityType.create({ - 'name': 'Celebrate the sale', - 'days': 3, - 'summary': 'ACT 3 : ' - 'Beers for everyone because I am a good salesman !', - 'res_model_id': partner_model_id, - }) + ActivityType = self.env["mail.activity.type"] + self.activity1 = ActivityType.create( + { + "name": "Initial Contact", + "delay_count": 5, + "delay_unit": "days", + "summary": "ACT 1 : Presentation, barbecue, ... ", + "res_model_id": partner_model_id, + } + ) + self.activity2 = ActivityType.create( + { + "name": "Call for Demo", + "delay_count": 6, + "delay_unit": "days", + "summary": "ACT 2 : I want to show you my ERP !", + "res_model_id": partner_model_id, + } + ) + self.activity3 = ActivityType.create( + { + "name": "Celebrate the sale", + "delay_count": 3, + "delay_unit": "days", + "summary": "ACT 3 : " + "Beers for everyone because I am a good salesman !", + "res_model_id": partner_model_id, + } + ) # I create an opportunity, as employee self.partner_client = self.env.ref("base.res_partner_1") # assure there isn't any mail activity yet - self.env['mail.activity'].sudo().search([]).unlink() + self.env["mail.activity"].sudo().search([]).unlink() - self.act1 = self.env['mail.activity'].sudo().create({ - 'activity_type_id': self.activity3.id, - 'note': 'Partner activity 1.', - 'res_id': self.partner_client.id, - 'res_model_id': partner_model_id, - 'user_id': self.employee.id - }) - self.act2 = self.env['mail.activity'].sudo().create({ - 'activity_type_id': self.activity2.id, - 'note': 'Partner activity 2.', - 'res_id': self.partner_client.id, - 'res_model_id': partner_model_id, - 'user_id': self.employee.id - }) - self.act3 = self.env['mail.activity'].sudo().create({ - 'activity_type_id': self.activity3.id, - 'note': 'Partner activity 3.', - 'res_id': self.partner_client.id, - 'res_model_id': partner_model_id, - 'user_id': self.employee.id - }) + self.act1 = ( + self.env["mail.activity"] + .sudo() + .create( + { + "activity_type_id": self.activity3.id, + "note": "Partner activity 1.", + "res_id": self.partner_client.id, + "res_model_id": partner_model_id, + "user_id": self.employee.id, + } + ) + ) + self.act2 = ( + self.env["mail.activity"] + .sudo() + .create( + { + "activity_type_id": self.activity2.id, + "note": "Partner activity 2.", + "res_id": self.partner_client.id, + "res_model_id": partner_model_id, + "user_id": self.employee.id, + } + ) + ) + self.act3 = ( + self.env["mail.activity"] + .sudo() + .create( + { + "activity_type_id": self.activity3.id, + "note": "Partner activity 3.", + "res_id": self.partner_client.id, + "res_model_id": partner_model_id, + "user_id": self.employee.id, + } + ) + ) def create_mail_activity_group(self): - manager_mail_activity_test_group = self.env['res.groups'].create({ - 'name': 'group_manager_mail_activity_test', - }) - mail_activity_model_id = self.env['ir.model'].sudo().search( - [('model', '=', 'mail.activity')], limit=1) - access = self.env['ir.model.access'].create({ - 'name': 'full_access_mail_activity', - 'model_id': mail_activity_model_id.id, - 'perm_read': True, - 'perm_write': True, - 'perm_create': True, - 'perm_unlink': True, - }) + manager_mail_activity_test_group = self.env["res.groups"].create( + {"name": "group_manager_mail_activity_test"} + ) + mail_activity_model_id = ( + self.env["ir.model"] + .sudo() + .search([("model", "=", "mail.activity")], limit=1) + ) + access = self.env["ir.model.access"].create( + { + "name": "full_access_mail_activity", + "model_id": mail_activity_model_id.id, + "perm_read": True, + "perm_write": True, + "perm_create": True, + "perm_unlink": True, + } + ) access.group_id = manager_mail_activity_test_group return manager_mail_activity_test_group def get_view(self, activity): action = activity.open_origin() - result = self.env[action.get('res_model')]\ - .load_views(action.get('views')) - return result.get('fields_views').get(action.get('view_mode')) + result = self.env[action.get("res_model")].load_views(action.get("views")) + return result.get("fields_views").get(action.get("view_mode")) def test_open_origin_res_partner(self): """ This test case checks @@ -110,63 +144,58 @@ class TestMailActivityBoardMethods(TransactionCase): belongs. """ # Id of the form view for the class 'crm.lead', type 'lead' - form_view_partner_id = self.env.ref('base.view_partner_form').id + form_view_partner_id = self.env.ref("base.view_partner_form").id # Id of the form view return open_origin() view = self.get_view(self.act1) # Check the next view is correct - self.assertEqual(form_view_partner_id, view.get('view_id')) + self.assertEqual(form_view_partner_id, view.get("view_id")) # Id of the form view return open_origin() view = self.get_view(self.act2) # Check the next view is correct - self.assertEqual(form_view_partner_id, view.get('view_id')) + self.assertEqual(form_view_partner_id, view.get("view_id")) # Id of the form view return open_origin() view = self.get_view(self.act3) # Check the next view is correct - self.assertEqual(form_view_partner_id, view.get('view_id')) + self.assertEqual(form_view_partner_id, view.get("view_id")) def test_redirect_to_activities(self): """ This test case checks - if the method returns the correct action, - if the correct activities are shown. """ - action_id = self.env.ref( - 'mail_activity_board.open_boards_activities').id - action = self.partner_client\ - .redirect_to_activities(**{'id': self.partner_client.id}) - self.assertEqual(action.get('id'), action_id) + action_id = self.env.ref("mail_activity_board.open_boards_activities").id + action = self.partner_client.redirect_to_activities( + **{"id": self.partner_client.id} + ) + self.assertEqual(action.get("id"), action_id) - kwargs = { - 'groupby': [ - "activity_type_id" - ], - } - kwargs['domain'] = action.get('domain') + kwargs = {"groupby": ["activity_type_id"]} + kwargs["domain"] = action.get("domain") - result = self.env[action.get('res_model')]\ - .load_views(action.get('views')) - fields = result.get('fields_views').get('kanban').get('fields') - kwargs['fields'] = list(fields.keys()) + result = self.env[action.get("res_model")].load_views(action.get("views")) + fields = result.get("fields_views").get("kanban").get("fields") + kwargs["fields"] = list(fields.keys()) - result = self.env['mail.activity'].read_group(**kwargs) + result = self.env["mail.activity"].read_group(**kwargs) acts = [] for group in result: - records = self.env['mail.activity'].search_read( - domain=group.get('__domain'), fields=kwargs['fields'] + records = self.env["mail.activity"].search_read( + domain=group.get("__domain"), fields=kwargs["fields"] ) - acts += [record_id.get('id') for record_id in records] + acts += [record_id.get("id") for record_id in records] for act in acts: self.assertIn(act, self.partner_client.activity_ids.ids) def test_read_permissions(self): - search1 = self.env['mail.activity'].sudo(self.employee).search([]) + search1 = self.env["mail.activity"].with_user(self.employee).search([]) self.assertEqual(len(search1), 3) - search2 = self.env['mail.activity'].sudo(self.employee2).search([]) + search2 = self.env["mail.activity"].with_user(self.employee2).search([]) self.assertEqual(len(search2), 0) diff --git a/mail_activity_board/views/mail_activity_view.xml b/mail_activity_board/views/mail_activity_view.xml index 29c6910..14cbf8c 100644 --- a/mail_activity_board/views/mail_activity_view.xml +++ b/mail_activity_board/views/mail_activity_view.xml @@ -156,7 +156,7 @@ - + @@ -181,7 +181,6 @@ Activities mail.activity - form kanban,form [] {}