[18.0][MIG] iap_alternative_provider: Migration to 18.0 - #3241
Conversation
Moving this behaviour in a new module in server-env repo
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: server-tools-15.0/server-tools-15.0-iap_alternative_provider Translate-URL: https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-iap_alternative_provider/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: server-tools-16.0/server-tools-16.0-iap_alternative_provider Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-iap_alternative_provider/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: server-tools-16.0/server-tools-16.0-iap_alternative_provider Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-iap_alternative_provider/
Currently translated at 100.0% (7 of 7 strings) Translation: server-tools-16.0/server-tools-16.0-iap_alternative_provider Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-iap_alternative_provider/it/
Currently translated at 100.0% (7 of 7 strings) Translation: server-tools-16.0/server-tools-16.0-iap_alternative_provider Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-iap_alternative_provider/es/
| @api.onchange("provider") | ||
| def onchange_provider(self): | ||
| self._set_service_from_provider() |
There was a problem hiding this comment.
Wondering if the onchange_provider method would be redundant since i see this a few lines below a method that seems like it would set the service as well.
def write(self, vals):
super().write(vals)
self._set_service_from_provider()
return True
I guess the difference would be that for onchange is that the new service value would be visible on the form before it is saved, where with the write method the new service value would only be set after the record is saved.
It does feel like the _get_service_from_provider() method will be called twice when a provider is changed though, once in the onchange and then another time when saving the record via write().
Is there anyway to avoid that? Was going to suggest removing the overridden write method but seems like we need that in case we update via orm (rpc or script) or any other way besides through the form.
There was a problem hiding this comment.
To avoid redundant calls, can we check the vals dictionary in the write method to see if service value was changed?
If service is to be updated, perhaps we can skip the self._set_service_from_provider() call. The assumption being of course that the onchange would have already set the service field to the correct value from the ui.
There was a problem hiding this comment.
From version 18.0, the Service field is required when creating a new IAP account. Changing the service as soon as the provider is selected will provide a better user experience than randomly selecting a service to create a new IAP account and then having the service updated according to the provider.
As you mentioned, we need this in case we update via ORM (RPC or script). We should not skip the self._set_service_from_provider() call to ensure the service corresponds to the provider.
There was a problem hiding this comment.
Right, i understand that the self._set_service_from_provider() shouldn't be removed from the write(), though I was hoping for a way to reduce unneeded calls.
Something like this:
def write(self, vals):
res = super().write(vals)
if "service_id" not in vals:
self._set_service_from_provider()
return res
I guess the downside is if a user would update the service id incorrectly and adding checks for that might negate any benefits over just calling self._set_service_from_provider() anyways but just wanted to put that out there.
There was a problem hiding this comment.
Hi @wlin-kencove I have updated, please help to review
There was a problem hiding this comment.
After thinking about it it is probably not necessary to to check for update here.
We are probably okay with how it was before. Sorry for the back and forth, thinking that trying to change the write here will not likely matter in the long run since it will likely call self._set_service_from_provider() anyways.
This update will prevent unneeded calls when service or provider was not change (and thus the call would not be needed) but will not prevent duplicate calls when it is updated via form. It still has value in the first scenario but not sure if that might introduce issues later on. It might be better to just leave as it was and live with the duplicate calls on service/provider update since that will happen anyways.
Sorry again for this diversion.
There was a problem hiding this comment.
No problem at all, I have removed the check
|
Can we better insert commit of auto pre-commit before the migration commit? |
| if service and record.service_id != service: | ||
| record.service_id = service | ||
|
|
||
| @api.onchange("provider") | ||
| def onchange_provider(self): | ||
| self._set_service_from_provider() |
There was a problem hiding this comment.
I need to understand if the necessity to interchange service_name with service_id?
and if possible to use them both?
There was a problem hiding this comment.
There is no pre-commit auto-fix during migration using oca-port.
In version 17.0, the iap.account model only had the service_name field. In version 18.0, the iap.service model was introduced. The change from service_name to service_id improves data integrity by following a Many2one relationship instead of using a string. Using both would be redundant.
340257c to
417ea68
Compare
417ea68 to
c182d83
Compare
|
@kobros-tech can you please review the requested changes? approval is hanging since there is a pending review. |
|
This PR has the |
|
Not sure if this belongs into a particular iap_account implementation but regarding In my specific case, the account of an alternative provider (ClickSend) uses (always) the "sms" service. So at the moment I have to do this: and Would be nice if there was a hook for treating an alternative account as registered. In fact, given the odoo.com-centric treatment of that it could probably just be the default to treat alternative accounts as registered. |
|
/ocabot migration iap_alternative_provider |
|
This PR looks fantastic, let's merge it! |
|
It looks like something changed on |
|
Congratulations, your PR was merged at c0040d5. Thanks a lot for contributing to OCA. ❤️ |
Change: