RATIONALE Purpose of this commit is to be explicit in subtype chosen when invoking the message composer / calling message_post. As default value may not always be clear, better be explicit in case the composer default value changes. SPECIFICATIONS Add explicit references to subtype when it is not obvious what will be the final subtype, notably when using helpers (post_with_view or template which uses the composer that is not crystal clear in its subtype management). In this commit we also add support of XMLID-based subtype when invoking the composer. A ``default_subtype_xmlid`` context key is transformed into a ``default_subtype_id``, to be used notably in JS where we cannot easily use a ``ref``-like statement. Post API now also supports 'subytpe_xmlid' argument allowing to give the xml id and ease calling the methods. Use ``_xmlid_to_res_id`` to get directly the ID of subtypes in order to avoid useless queries from ``ref`` that does an exists. Also remove useless values given to post API, notably author_id that is by default the current users' partner. Task-2710804 (Mail: Clean MailThread Posting API) Part-of: odoo/odoo#99482
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ProjectShareWizard(models.TransientModel):
|
|
_name = 'project.share.wizard'
|
|
_inherit = 'portal.share'
|
|
_description = 'Project Sharing'
|
|
|
|
@api.model
|
|
def default_get(self, fields):
|
|
result = super().default_get(fields)
|
|
if not result.get('access_mode'):
|
|
result.update(
|
|
access_mode='read',
|
|
display_access_mode=True,
|
|
)
|
|
return result
|
|
|
|
@api.model
|
|
def _selection_target_model(self):
|
|
project_model = self.env['ir.model']._get('project.project')
|
|
return [(project_model.model, project_model.name)]
|
|
|
|
access_mode = fields.Selection([('read', 'Readonly'), ('edit', 'Edit')])
|
|
display_access_mode = fields.Boolean()
|
|
|
|
@api.depends('res_model', 'res_id')
|
|
def _compute_resource_ref(self):
|
|
for wizard in self:
|
|
if wizard.res_model and wizard.res_model == 'project.project':
|
|
wizard.resource_ref = '%s,%s' % (wizard.res_model, wizard.res_id or 0)
|
|
else:
|
|
wizard.resource_ref = None
|
|
|
|
def action_send_mail(self):
|
|
self.ensure_one()
|
|
if self.access_mode == 'edit':
|
|
portal_partners = self.partner_ids.filtered('user_ids')
|
|
self.resource_ref._add_collaborators(self.partner_ids)
|
|
self._send_public_link(portal_partners)
|
|
self._send_signup_link(partners=self.partner_ids - portal_partners)
|
|
self.resource_ref.message_subscribe(partner_ids=self.partner_ids.ids)
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
return super().action_send_mail()
|