mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-18 21:01:59 +02:00
Initial commit: Project packages
This commit is contained in:
commit
89613c97b0
753 changed files with 496325 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import mail_plugin
|
||||
from . import project_client
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import logging
|
||||
|
||||
from odoo.http import request
|
||||
|
||||
from odoo.addons.mail_plugin.controllers import mail_plugin
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MailPluginController(mail_plugin.MailPluginController):
|
||||
|
||||
def _get_contact_data(self, partner):
|
||||
"""
|
||||
Overrides the base module's get_contact_data method by Adding the "tasks" key within the initial contact
|
||||
information dict loaded when opening an email on Outlook.
|
||||
This is structured this way to enable the "project" feature on the Outlook side only if the Odoo version
|
||||
supports it.
|
||||
|
||||
Return the tasks key only if the current user can create tasks. So, if they can not
|
||||
create tasks, the section won't be visible on the addin side (like if the project
|
||||
module was not installed on the database).
|
||||
"""
|
||||
contact_values = super(MailPluginController, self)._get_contact_data(partner)
|
||||
|
||||
if not request.env['project.task'].check_access_rights('create', raise_exception=False):
|
||||
return contact_values
|
||||
|
||||
if not partner:
|
||||
contact_values['tasks'] = []
|
||||
else:
|
||||
partner_tasks = request.env['project.task'].search(
|
||||
[('partner_id', '=', partner.id)], offset=0, limit=5)
|
||||
|
||||
accessible_projects = partner_tasks.project_id._filter_access_rules('read').mapped("id")
|
||||
|
||||
tasks_values = [
|
||||
{
|
||||
'task_id': task.id,
|
||||
'name': task.name,
|
||||
'project_name': task.project_id.name,
|
||||
} for task in partner_tasks if task.project_id.id in accessible_projects]
|
||||
|
||||
contact_values['tasks'] = tasks_values
|
||||
contact_values['can_create_project'] = request.env['project.project'].check_access_rights(
|
||||
'create', raise_exception=False)
|
||||
|
||||
return contact_values
|
||||
|
||||
def _mail_content_logging_models_whitelist(self):
|
||||
models_whitelist = super(MailPluginController, self)._mail_content_logging_models_whitelist()
|
||||
if not request.env['project.task'].check_access_rights('create', raise_exception=False):
|
||||
return models_whitelist
|
||||
return models_whitelist + ['project.task']
|
||||
|
||||
def _translation_modules_whitelist(self):
|
||||
modules_whitelist = super(MailPluginController, self)._translation_modules_whitelist()
|
||||
if not request.env['project.task'].check_access_rights('create', raise_exception=False):
|
||||
return modules_whitelist
|
||||
return modules_whitelist + ['project_mail_plugin']
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
from odoo import Command, http, _
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class ProjectClient(http.Controller):
|
||||
@http.route('/mail_plugin/project/search', type='json', auth='outlook', cors="*")
|
||||
def projects_search(self, search_term, limit=5):
|
||||
"""
|
||||
Used in the plugin side when searching for projects.
|
||||
Fetches projects that have names containing the search_term.
|
||||
"""
|
||||
projects = request.env['project.project'].search([('name', 'ilike', search_term)], limit=limit)
|
||||
|
||||
return [
|
||||
{
|
||||
'project_id': project.id,
|
||||
'name': project.name,
|
||||
'partner_name': project.partner_id.name,
|
||||
'company_id': project.company_id.id
|
||||
}
|
||||
for project in projects.sudo()
|
||||
]
|
||||
|
||||
@http.route('/mail_plugin/task/create', type='json', auth='outlook', cors="*")
|
||||
def task_create(self, email_subject, email_body, project_id, partner_id):
|
||||
partner = request.env['res.partner'].browse(partner_id).exists()
|
||||
if not partner:
|
||||
return {'error': 'partner_not_found'}
|
||||
|
||||
if not request.env['project.project'].browse(project_id).exists():
|
||||
return {'error': 'project_not_found'}
|
||||
|
||||
if not email_subject:
|
||||
email_subject = _('Task for %s', partner.name)
|
||||
|
||||
record = request.env['project.task'].with_company(partner.company_id).create({
|
||||
'name': email_subject,
|
||||
'partner_id': partner_id,
|
||||
'description': email_body,
|
||||
'project_id': project_id,
|
||||
'user_ids': [Command.link(request.env.uid)],
|
||||
})
|
||||
|
||||
return {'task_id': record.id, 'name': record.name}
|
||||
|
||||
@http.route('/mail_plugin/project/create', type='json', auth='outlook', cors="*")
|
||||
def project_create(self, name):
|
||||
record = request.env['project.project'].create({'name': name})
|
||||
return {"project_id": record.id, "name": record.name}
|
||||
Loading…
Add table
Add a link
Reference in a new issue