跳至内容
菜单
此问题已终结
2 回复
1907 查看

I'm working on an Odoo app where I need to use a custom SMS provider for sending notifications, rather than the default SMS provider that Odoo typically uses. Most of the modules in Odoo seem to rely on the built-in SMS sender, and I’m unsure how to replace it with my custom provider.

Should I create an inherited model or method to override the default SMS sender behavior? Or is there a recommended approach to integrate custom SMS functionality in a way that works across forms and other modules? Any guidance or examples would be appreciated!

形象
丢弃
编写者

TypeError: Model 'sms.api' does not exist in registry.                  
this giving me this error

最佳答案

Hi Bahrom

The easiest way is to adapt SmsApi


class SmsApi(models.AbstractModel):
​_inherit = 'sms.api'
   _description = 'my API'

    @api.model
    def _send_sms(self, numbers, message):

        """ Send sms """

        my_api = call the calls of your new provider

        params = {
            'numbers': numbers,
            'message': message,
        }

        my_api.call(make the call)

        return True
# do the same  for _send_sms_batch



   I advise you to create the api calls as a seperate class that you can call


With this approach you ensure that all methods in odoo that calls the sms methods are calling your extension


From versio v17 odoo moved sms.api to a class to be used as 

from odoo.addons.sms.tools.sms_api import SmsApi

this means either you adapt the odoo class or the method using the class SmsApi



Hope this helps

形象
丢弃
相关帖文 回复 查看 活动
0
1月 25
757
2
11月 22
2331
1
7月 25
358
2
6月 25
537
0
11月 24
1165