[19.0][MIG] mail_restrict_follower_selection: Migration to 19.0#183
[19.0][MIG] mail_restrict_follower_selection: Migration to 19.0#183CRogos wants to merge 36 commits into
Conversation
Currently translated at 100.0% (3 of 3 strings) Translation: social-11.0/social-11.0-mail_restrict_follower_selection Translate-URL: https://translation.odoo-community.org/projects/social-11-0/social-11-0-mail_restrict_follower_selection/fr/
Currently translated at 100.0% (3 of 3 strings) Translation: social-11.0/social-11.0-mail_restrict_follower_selection Translate-URL: https://translation.odoo-community.org/projects/social-11-0/social-11-0-mail_restrict_follower_selection/de/
that you are not supposed to.
Currently translated at 75.0% (3 of 4 strings) Translation: social-13.0/social-13.0-mail_restrict_follower_selection Translate-URL: https://translation.odoo-community.org/projects/social-13-0/social-13-0-mail_restrict_follower_selection/it/
When creating a record from a record from another model, the model is not in the context (`default_res_model` key). For example: creating an invoice from a sale order.
Currently translated at 100.0% (7 of 7 strings) Translation: social-14.0/social-14.0-mail_restrict_follower_selection Translate-URL: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_restrict_follower_selection/it/
1. Use forecreate=false in mail_restrict_follower_selection/data/ir_config_parameter.xml so that a deleted configuration is not recreated by a module update 2. Change the default domain to something less agressive 3. Add an example restriction restricting following a specific model
Currently translated at 100.0% (4 of 4 strings) Translation: social-16.0/social-16.0-mail_restrict_follower_selection Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_restrict_follower_selection/it/
With this is change it is now possible to use the `ref` function in the domain set in a parameter, allowing to include xmlids in the domain.
aac986c to
7a76706
Compare
|
@trisdoan can you please review this PR? |
|
@BhaveshHeliconia could you please make a review? |
| [("id", "in", wizard.partner_ids.ids)] | ||
| + safe_eval( | ||
| domain_str, | ||
| {"ref": lambda str_id: _id_get(self.env, str_id)}, |
There was a problem hiding this comment.
What is the purpose of this?
There was a problem hiding this comment.
I had to ask the AI myself:
That lambda injects a ref() helper into safe_eval so domain expressions can resolve XML IDs safely at runtime.
In this code, safe_eval(str(domain), {"ref": lambda str_id: _id_get(self.env, str_id)}) means: when the evaluated domain contains something like ref("module.external_id"), call _id_get(self.env, str_id) and return the numeric database ID of that record. The helper itself is defined in utils.py and simply does env.ref(id_str).id, so it deliberately returns only the ID, not the recordset.
So I assume this enables you to use ref in the domain: e.g. [('industry_id','=',ref('base.res_partner_industry_A'))]
There was a problem hiding this comment.
I've verified on runboat and it gives some error. Could you please check on the runboat with this?
There was a problem hiding this comment.
I've fixed it and also improved the wizard domain filter.
There was a problem hiding this comment.
Is there any way to avoid overwriting onClickAddFollowers? If not, then please add a comment explaining why we need overwriting.
There was a problem hiding this comment.
You are totally right. How about this solution, by intercepting the doAction call? (I have to say that I am not an JS expert, but I like this solution from copilot)
| @@ -0,0 +1,7 @@ | |||
| <?xml version="1.0" ?> | |||
| <odoo> | |||
There was a problem hiding this comment.
| <odoo> | |
| <odoo noupdate="1"> |
There was a problem hiding this comment.
This one is still pending.
There was a problem hiding this comment.
This is only demo data and not a real configuration. Not sure if we should flag this as noupdate.... OK I had a look into other demo data, you are right.
There was a problem hiding this comment.
- Can you replace
setup()with following code snippet?
onClickAddFollowers() {
const originalDoAction = this.action.doAction.bind(this.action);
const saved = this.action;
this.action = Object.assign(Object.create(this.action), {
// The web client filters the loadViews context down to `lang` and
// keys ending with `_view_ref`. We smuggle the followed record's
// model through under a `_view_ref`-suffixed key so the wizard's
// `get_view` can apply the per-model follower domain.
doAction: (action, options) =>
originalDoAction(
{
...action,
context: {
...action.context,
restrict_follower_res_model_view_ref:
this.props.thread.model,
},
},
options
),
});
try {
return super.onClickAddFollowers();
} finally {
this.action = saved;
}
},- By this, we can narrow scope from
setup()toonClickAddFollowers()and also make use of arrow function.
There was a problem hiding this comment.
I've changed it even though I am not sure if this is a better solution. But maybe it is easier to understand because it is better linked to the reason of this change.
7a76706 to
2f3b290
Compare
0323a01 to
db78d05
Compare
db78d05 to
cc46022
Compare
BhaveshHeliconia
left a comment
There was a problem hiding this comment.
Code and functional review LGTM!
|
This PR has the |
|
@pedrobaeza could you merge? |
|
/ocabot migration mail_restrict_follower_selection |
|
This PR looks fantastic, let's merge it! |
|
@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 19.0-ocabot-merge-pr-183-by-pedrobaeza-bump-nobump. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
1 similar comment
|
@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 19.0-ocabot-merge-pr-183-by-pedrobaeza-bump-nobump. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
supersede: #150
mail_followers_edit.pyfrommodels/towizard/directoryenv.ref()withset_param()in testssafe_eval()API change:locals_dict=→ positionalcontextdict in Odoo 19.0