Skip to content

[18.0][FIX] mail_activity_team: enhance _get_default_team_id method to handle user and model IDs#167

Merged
OCA-git-bot merged 1 commit intoOCA:18.0from
c4a8-odoo:18.0-mail_activity_team-wizard
Mar 31, 2026
Merged

[18.0][FIX] mail_activity_team: enhance _get_default_team_id method to handle user and model IDs#167
OCA-git-bot merged 1 commit intoOCA:18.0from
c4a8-odoo:18.0-mail_activity_team-wizard

Conversation

@CRogos
Copy link
Copy Markdown
Contributor

@CRogos CRogos commented Mar 31, 2026

Introduced by: #149
image


Odoo Server Error

RPC_ERROR
Odoo Server Error

Occured on oca-mail-18-0-88eec26a9337.runboat.odoo-community.org on model mail.activity.schedule on 2026-03-31 07:52:20 GMT

Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 2167, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "/opt/odoo/odoo/service/model.py", line 157, in retrying
    result = func()
  File "/opt/odoo/odoo/http.py", line 2134, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/opt/odoo/odoo/http.py", line 2382, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 333, in _dispatch
    result = endpoint(**request.params)
  File "/opt/odoo/odoo/http.py", line 754, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/opt/odoo/addons/web/controllers/dataset.py", line 36, in call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 535, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
  File "/opt/odoo/addons/web/models/models.py", line 1005, in onchange
    record._apply_onchange_methods(field_name, result)
  File "/opt/odoo/odoo/models.py", line 7386, in _apply_onchange_methods
    res = method(self)
  File "/mnt/data/odoo-addons-dir/mail_activity_team/wizard/mail_activity_schedule.py", line 53, in _onchange_activity_team_user_id
    and self.activity_team_user_id in self.activity_team_id.member_ids
  File "/opt/odoo/odoo/fields.py", line 3113, in __get__
    return super().__get__(records, owner)
  File "/opt/odoo/odoo/fields.py", line 1244, in __get__
    self.recompute(record)
  File "/opt/odoo/odoo/fields.py", line 1471, in recompute
    apply_except_missing(self.compute_value, recs)
  File "/opt/odoo/odoo/fields.py", line 1444, in apply_except_missing
    func(records)
  File "/opt/odoo/odoo/fields.py", line 1493, in compute_value
    records._compute_field_value(self)
  File "/opt/odoo/odoo/models.py", line 5302, in _compute_field_value
    fields.determine(field.compute, self)
  File "/opt/odoo/odoo/fields.py", line 110, in determine
    return needle(*args)
  File "/mnt/data/odoo-addons-dir/mail_activity_team/wizard/mail_activity_schedule.py", line 30, in _compute_activity_team_id
    ]._get_default_team_id(
TypeError: MailActivity._get_default_team_id() takes 1 positional argument but 3 were given

The above server error caused the following client error:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    Error: An error occured in the owl lifecycle (see this Error's "cause" property)
        at handleError (http://oca-mail-18-0-88eec26a9337.runboat.odoo-community.org/web/assets/7de2c19/web.assets_web.min.js:972:101)
        at App.handleError (http://oca-mail-18-0-88eec26a9337.runboat.odoo-community.org/web/assets/7de2c19/web.assets_web.min.js:1631:29)
        at ComponentNode.initiateRender (http://oca-mail-18-0-88eec26a9337.runboat.odoo-community.org/web/assets/7de2c19/web.assets_web.min.js:1065:19)

Caused by: RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://oca-mail-18-0-88eec26a9337.runboat.odoo-community.org/web/assets/7de2c19/web.assets_web.min.js:3178:165)
        at XMLHttpRequest.<anonymous> (http://oca-mail-18-0-88eec26a9337.runboat.odoo-community.org/web/assets/7de2c19/web.assets_web.min.js:3184:13)

@CRogos CRogos changed the title [FIX] mail_activity_team: enhance _get_default_team_id method to handle user and model IDs [18.0][FIX] mail_activity_team: enhance _get_default_team_id method to handle user and model IDs Mar 31, 2026
@CRogos
Copy link
Copy Markdown
Contributor Author

CRogos commented Mar 31, 2026

@StefanRijnhart I think we broke part of the module with the mast change. Could you review this fix.

cc: @lorenzomorandini

Copy link
Copy Markdown

@DorianMAG DorianMAG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review.
Functional test OK.
Thx for the fix.
LGTM

Copy link
Copy Markdown
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give me a moment to check if I can fix this in the wizard itself

@StefanRijnhart
Copy link
Copy Markdown
Member

Here's a solution that reuses the method without reverting to its old signature: #168 It includes tests. What do you think?

Comment on lines 11 to 36
@api.model
def _get_default_team_id(self, user_id=None, model_id=None):
if not user_id:
user_id = self.user_id.id or self.env.user.id
if not model_id:
model_id = self.res_model_id.id if self.res_model_id else None
domain = []
domain.append(("member_ids", "=", self.user_id.id or self.env.user.id))
if self.res_model_id:
domain.append(("member_ids", "=", user_id))
if model_id:
domain += [
"|",
("res_model_ids", "=", False),
("res_model_ids", "=", self.res_model_id.id),
("res_model_ids", "=", model_id),
]
if not domain:
return self.env["mail.activity.team"]
teams = self.env["mail.activity.team"].search(domain)
if self.res_model_id:
if model_id:
# Prefer teams with a matching model
teams = (
teams.filtered(lambda mat: self.res_model_id in mat.res_model_ids)
teams.filtered(
lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids
)
or teams
)
return teams[:1]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefanRijnhart how about this, and we call _get_default_team_by_user_id from the wizard?

Suggested change
@api.model
def _get_default_team_id(self, user_id=None, model_id=None):
if not user_id:
user_id = self.user_id.id or self.env.user.id
if not model_id:
model_id = self.res_model_id.id if self.res_model_id else None
domain = []
domain.append(("member_ids", "=", self.user_id.id or self.env.user.id))
if self.res_model_id:
domain.append(("member_ids", "=", user_id))
if model_id:
domain += [
"|",
("res_model_ids", "=", False),
("res_model_ids", "=", self.res_model_id.id),
("res_model_ids", "=", model_id),
]
if not domain:
return self.env["mail.activity.team"]
teams = self.env["mail.activity.team"].search(domain)
if self.res_model_id:
if model_id:
# Prefer teams with a matching model
teams = (
teams.filtered(lambda mat: self.res_model_id in mat.res_model_ids)
teams.filtered(
lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids
)
or teams
)
return teams[:1]
def _get_default_team_id(self):
return _get_default_team_by_user_id(self.user_id.id or self.env.user.id, self.res_model_id.id)
@api.model
def _get_default_team_by_user_id(self, user_id=None, model_id=None):
domain.append(("member_ids", "=", user_id))
if model_id:
domain += [
"|",
("res_model_ids", "=", False),
("res_model_ids", "=", model_id),
]
if not domain:
return self.env["mail.activity.team"]
teams = self.env["mail.activity.team"].search(domain)
if model_id:
# Prefer teams with a matching model
teams = (
teams.filtered(
lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids
)
or teams
)
return teams[:1]

@CRogos CRogos force-pushed the 18.0-mail_activity_team-wizard branch from fd64c3f to 828362e Compare March 31, 2026 11:51
Copy link
Copy Markdown
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the test parity with #168, this seems fine to me. Thanks for fixing my mistake!

Fast tracking due to the impact of the bug .

/ocabot merge patch

@OCA-git-bot
Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 18.0-ocabot-merge-pr-167-by-StefanRijnhart-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit ada2a1f into OCA:18.0 Mar 31, 2026
9 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at c0a9519. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants