This reverts commit fc7778f8c512202dc3361d6b87be8c28b299c3c8 because of a change in the spec. The access mode are removed and replaced by this access mode for portal user: - read: the user goes to the classic portal view - edit: the user is added as collaborator of the shared project and can access to project sharing views. To do this, the portal share is inherited by the project share wizard. This new wizard can be open to share in readonly and open to share in edit mode via 2 buttons in the form view of the shared project. A new stat button is added to form view of project to see the collaborators of this project. That is, the ones can access to the project sharing views. The project manager will can remove or also add new collaborators via the views in this stat button. task-2379518 closes #73341
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
from odoo.tools import email_normalize
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
""" Inherits partner and adds Tasks information in the partner form """
|
|
_inherit = 'res.partner'
|
|
|
|
task_ids = fields.One2many('project.task', 'partner_id', string='Tasks')
|
|
task_count = fields.Integer(compute='_compute_task_count', string='# Tasks')
|
|
|
|
def _compute_task_count(self):
|
|
# retrieve all children partners and prefetch 'parent_id' on them
|
|
all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
|
|
all_partners.read(['parent_id'])
|
|
|
|
task_data = self.env['project.task'].read_group(
|
|
domain=[('partner_id', 'in', all_partners.ids)],
|
|
fields=['partner_id'], groupby=['partner_id']
|
|
)
|
|
|
|
self.task_count = 0
|
|
for group in task_data:
|
|
partner = self.browse(group['partner_id'][0])
|
|
while partner:
|
|
if partner in self:
|
|
partner.task_count += group['partner_id_count']
|
|
partner = partner.parent_id
|
|
|
|
def _create_portal_users(self):
|
|
partners_without_user = self.filtered(lambda partner: not partner.user_ids)
|
|
if not partners_without_user:
|
|
return self.env['res.users']
|
|
created_users = self.env['res.users']
|
|
for partner in partners_without_user:
|
|
created_users += self.env['res.users'].with_context(no_reset_password=True)._create_user_from_template({
|
|
'email': email_normalize(partner.email),
|
|
'login': email_normalize(partner.email),
|
|
'partner_id': partner.id,
|
|
'company_id': self.env.company.id,
|
|
'company_ids': [(6, 0, self.env.company.ids)],
|
|
'active': True,
|
|
})
|
|
return created_users
|