[IMP] mail_activity_type: Remove deprecated usage of onchange
Replaced for web_domain_field module
This commit is contained in:
parent
bd214206b6
commit
cdc606b566
@ -1,5 +1,7 @@
|
||||
# Copyright 2018-22 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
import json
|
||||
|
||||
from odoo import SUPERUSER_ID, _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
@ -20,42 +22,40 @@ class MailActivity(models.Model):
|
||||
return self.env["mail.activity.team"].search(domain, limit=1)
|
||||
|
||||
user_id = fields.Many2one(required=False)
|
||||
team_user_id = fields.Many2one(related="user_id", readonly=False)
|
||||
|
||||
team_id = fields.Many2one(
|
||||
comodel_name="mail.activity.team", default=lambda s: s._get_default_team_id()
|
||||
)
|
||||
user_id_domain = fields.Char(compute="_compute_user_id_domain")
|
||||
|
||||
@api.depends("team_id")
|
||||
def _compute_user_id_domain(self):
|
||||
for record in self:
|
||||
domain = []
|
||||
if record.team_id:
|
||||
domain.append(("id", "in", record.team_id.member_ids.ids))
|
||||
record.user_id_domain = json.dumps(domain)
|
||||
|
||||
@api.onchange("user_id")
|
||||
def _onchange_user_id(self):
|
||||
res = {"domain": {"team_id": []}}
|
||||
if not self.user_id:
|
||||
return res
|
||||
res["domain"]["team_id"] = [
|
||||
"|",
|
||||
("res_model_ids", "=", False),
|
||||
("res_model_ids", "in", self.res_model_id.ids),
|
||||
]
|
||||
if self.team_id and self.user_id in self.team_id.member_ids:
|
||||
return res
|
||||
if not self.user_id or (
|
||||
self.team_id and self.user_id in self.team_id.member_ids
|
||||
):
|
||||
return
|
||||
self.team_id = self.with_context(
|
||||
default_res_model=self.sudo().res_model_id.model
|
||||
)._get_default_team_id(user_id=self.user_id.id)
|
||||
return res
|
||||
|
||||
@api.onchange("team_id")
|
||||
def _onchange_team_id(self):
|
||||
res = {"domain": {"user_id": []}}
|
||||
if not self.team_id:
|
||||
return res
|
||||
res["domain"]["user_id"] = [("id", "in", self.team_id.member_ids.ids)]
|
||||
if self.user_id not in self.team_id.member_ids:
|
||||
if self.team_id and self.user_id not in self.team_id.member_ids:
|
||||
if self.team_id.user_id:
|
||||
self.user_id = self.team_id.user_id
|
||||
elif len(self.team_id.member_ids) == 1:
|
||||
self.user_id = self.team_id.member_ids
|
||||
else:
|
||||
self.user_id = self.env["res.users"]
|
||||
return res
|
||||
|
||||
@api.constrains("team_id", "user_id")
|
||||
def _check_team_and_user(self):
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Copyright 2018-22 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
import json
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import Form, TransactionCase
|
||||
|
||||
@ -200,6 +202,10 @@ class TestMailActivityTeam(TransactionCase):
|
||||
self.team2.member_ids = self.employee2
|
||||
with Form(self.act2) as form:
|
||||
form.team_id = self.team2
|
||||
self.assertIn(
|
||||
form.user_id,
|
||||
self.env["res.users"].search(json.loads(form.user_id_domain)),
|
||||
)
|
||||
self.assertEqual(form.user_id, self.employee2)
|
||||
|
||||
def test_activity_onchanges_team_different_member_no_leader(self):
|
||||
|
@ -6,8 +6,22 @@
|
||||
<field name="model">mail.activity</field>
|
||||
<field name="inherit_id" ref="mail.mail_activity_view_form_popup" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="user_id" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'invisible': [('team_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="user_id" position="after">
|
||||
<field name="team_id" options="{'no_create': True, 'no_open': True}" />
|
||||
<field
|
||||
name="team_user_id"
|
||||
attrs="{'invisible': [('team_id', '=', False)]}"
|
||||
domain="[('activity_team_ids', '=', team_id)]"
|
||||
/>
|
||||
<field
|
||||
name="team_id"
|
||||
options="{'no_create': True, 'no_open': True}"
|
||||
domain="['|', ('res_model_ids', '=', False), ('res_model_ids', '=', res_model_id)]"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
@ -31,8 +45,21 @@
|
||||
ref="mail_activity_board.mail_activity_view_form_board"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="user_id" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'invisible': [('team_id', '=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="user_id" position="after">
|
||||
<field name="team_id" />
|
||||
<field
|
||||
name="user_id"
|
||||
attrs="{'invisible': [('team_id', '!=', False)]}"
|
||||
domain="[('activity_team_ids', '=', team_id)]"
|
||||
/>
|
||||
<field
|
||||
name="team_id"
|
||||
domain="['|', ('res_model_ids', '=', False), ('res_model_ids', '=', res_model_id)]"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
Loading…
Reference in New Issue
Block a user