Skip to content

Commit

Permalink
fixup! [ADD] sms_alternative_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jan 31, 2025
1 parent eca81a7 commit 859eff2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions sms_alternative_provider/models/ir_sms_gateway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

import operator

from odoo import _, api, exceptions, fields, models

Expand All @@ -10,7 +9,7 @@ class IrSmsGateway(models.Model):

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

name = fields.Char(required=True)
active = fields.Boolean(default=True)
Expand Down Expand Up @@ -43,7 +42,7 @@ def _compute_description(self):

# SMS sending functions

def send(self, messages):
def _send_via_self(self, messages):
"""
Send a list of SMS via the current provider
Expand Down Expand Up @@ -85,13 +84,13 @@ def _send(self, messages, handle_results=True, raise_exception=True):
raise exceptions.UserError(
_("No suitable provider found for messages %s") % messages_to_send
)
provider_result = provider.send(messages_to_send) or []
provider_result = provider._send_via_self(messages_to_send) or []
sms = SmsSms.browse(
filter(None, map(operator.itemgetter("id"), provider_result))
filter(None, map(lambda x: x.get("id"), provider_result))
)
sms.write({"sms_gateway_id": provider.id})
if handle_results:
provider._handle_results(provider_result)
provider._handle_results(messages_to_send, provider_result)
result.extend(provider_result)
return result

Expand Down Expand Up @@ -140,9 +139,12 @@ def _can_send(self, message):
for prefix in self.prefix.split()
)

def _handle_results(self, results, unlink_failed=False, unlink_sent=True):
def _handle_results(self, messages, results, unlink_failed=False, unlink_sent=True):
"""
Write state of sms.sms objects based on results
Write state of sms.sms objects based on results.
messages is the list of messages passed to _send
results is the list of results (provider-specific) as returned by _send
"""
self.ensure_one()
SmsSms = self.env["sms.sms"]
Expand Down

0 comments on commit 859eff2

Please sign in to comment.