[15.0][IMP] template_content_swapper: allow manual editing of the name - #1305
[15.0][IMP] template_content_swapper: allow manual editing of the name#1305smorita7749 wants to merge 1 commit into
Conversation
| return self.env["res.lang"].get_installed() | ||
|
|
||
| name = fields.Char(compute="_compute_name", store=True, readonly=True) | ||
| name = fields.Char() |
There was a problem hiding this comment.
Isn't it possible just by changing readonly to False?
There was a problem hiding this comment.
Do you want to add name before inserting content values? Is that the reason?
There was a problem hiding this comment.
The intent is to preserve a manually entered name even after content_from / content_to are changed.
I reflected the review for Yoshi-san, so please take a look when you have time.
24e9598 to
623b46b
Compare
623b46b to
c98be3d
Compare
AungKoKoLin1997
left a comment
There was a problem hiding this comment.
Instead of adding logic in both create and onchange, I am wondering why can't we keep original approach just by adding readonly=False attribute. The original compute method depends on content_from and content_to. So, user can still change the name after these values are filled. IMO, changing the name when content_from or content_to is make sense and the name should be updated.
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| if not vals.get("name") and vals.get("content_from"): | ||
| vals["name"] = vals["content_from"] |
There was a problem hiding this comment.
Shouldn't we keep original practice f"{record.content_from or ''} -> {record.content_to or ''}"? Is there any reason to use only content_from?
There was a problem hiding this comment.
In the original computed version the name was always rebuilt from content_from / content_to, so including content_to made sense.
Now the record is created as soon as content_from (a required field) is filled, and content_to is optional and often not set yet at that point. So I guess there's no need to build the name from content_to here.
There was a problem hiding this comment.
What I am not comfortable is current improvement breaks the original behavior and always forces us to put the manual name. If we don't do it, the name will always show "content_from" only. I understand the name field in the config is not in important role at the moment but I don't want to break existing behavior and forcing a manual name.
| def _onchange_content(self): | ||
| """Auto-fill the name from the contents while empty; keep manual names.""" | ||
| if not self.name and self.content_from: | ||
| self.name = self.content_from |
There was a problem hiding this comment.
Same as above.
Isn't better to use write method?
There was a problem hiding this comment.
name is required=True, so a saved record always has a name, and a write override would have nothing to fill. The onchange fills a default in the form while the record's name is still empty before saving.
The editable-computed way would overwrite the name, but that's what we want to avoid. |
This change allows users to edit the mapping name manually.
@qrtl QT6819