Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] sms_alternative_provider, sms_messagebird #327

Draft
wants to merge 5 commits into
base: 16.0
Choose a base branch
from

Conversation

hbrunn
Copy link
Member

@hbrunn hbrunn commented Dec 27, 2024

This module allows configuring multiple providers for sending SMS.

By restricting providers to country or area codes, you can ie have Odoo pick different providers for different countries.

@hbrunn hbrunn changed the title [ADD] sms_alternative_provider, sms_messagebird [16.0][ADD] sms_alternative_provider, sms_messagebird Dec 27, 2024
@thomaspaulb
Copy link

@sebastienbeau This is an attempt to produce something a step up from what you have done with iap_alternative_provider, unfortunately the both cannot be reconciled. What do you think about it?


_name = "ir.sms.gateway"
_order = "sequence"
_desc = "SMS gateway provider"

Choose a reason for hiding this comment

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

This should be _description.


def _handle_results(self, results, unlink_failed=False, unlink_sent=True):
"""
Write state of sms.sms objects based on results

Choose a reason for hiding this comment

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

It might be nice to describe here which results are passed.

Also, are any of the original message key/value pairs passed? Would be handy to be able to rely on that.

            'id': sms.sms id,
            'number': phone number,
            'content': sms content,

Copy link
Member Author

Choose a reason for hiding this comment

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

I now pass the whole list of messages as passed to _send, seems most general to me

@hbrunn
Copy link
Member Author

hbrunn commented Jan 31, 2025

another discussion point: Given that basically all modules that mess with sms at all override sms.api#_send_sms_batch and/or sms.sms#_postprocess_iap_sent_sms, it's crucial that the overrides of sms_alternative_provider come after any other override.

I'm of a mind to patch into loading the module graph and inject a dependency on sms_alternative_provider for every module that depends on sms if sms_alternative_provider is installed. Do you agree, or should we leave this to glue modules to be done on a per case basis?

@thomaspaulb
Copy link

it's crucial that the overrides of sms_alternative_provider come after any other override.

I'm not quite sure of this TBH: let's say someone wanted to use sms_ovh_http in its current form next to this module, they could even without the patch, because the OVH messages will just be caught earlier but when super comes, ours will be sent.

That's not a very likely scenario, but in other cases, if I would override send_sms_batch for other reasons and I call super before I do some stuff, I would want the SMS already be sent when the super returns; your proposal would mess with that.

Could you give an example use case where someone would want this?

@hbrunn
Copy link
Member Author

hbrunn commented Jan 31, 2025

sms_ovh_http works in both cases, so that's not a good example. sms_masked_content would have a problem, but that's handled accidentally right because modules on the same level (=same dependencies, both depend just on sms) are sorted alphabetically.

So if you had another module also just depending on sms, but named anything_sorted_before_sms_alternative_provider, and it does something to messages that should affect all messages, currently this would only apply to messages sent via iap, because messages from other providers will be funneled away at this point already.

@thomaspaulb
Copy link

Ah... right. Yes. Well your dependency idea does sound like a nice solution, so IMO you can go for it!

@hbrunn
Copy link
Member Author

hbrunn commented Jan 31, 2025

ja hmm, i didn't think this through: at the point we can patch something, a module that we want to depend on ours might already be loaded, meaning its overrides are already incorporated into the models in the registry (odoo doesn't load the python code any more before actually loading the module). So we'd have to rebuild those models, remove the module from the module graph and have it reloaded afterwards.

that's a very heavy operation for a theoretical problem, so I suggest we stash this idea for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants