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

[IMP] sms, sms_*: sms composer and templates #32625

Closed
wants to merge 3 commits into from

Conversation

pro-odoo
Copy link
Contributor

@pro-odoo pro-odoo commented Apr 11, 2019

The aim of this commit is to:

  1. Add templates for SMS:
  • Users can now create template for SMS Text messages similar to mail templates.
  • Templates can be linked with models, especially to create contextual action to quickly send SMS.
  1. Improve the SMS composer:
  • Integrate the template system.
  • Allow to use it for mass SMS.
  1. Handle SMS failures:
  • SMS is log in the chatter with a fa-comment icon next to the date.
  • The icon can be grey if all the SMS have correctly been sent.
  • The icon can be red if at least one SMS have not correctly been sent.
  • As mail, SMS failures are created if a SMS fails. The failure appears in the inbox.
  • When clicking on the red icon, a new modal is displayed, which is used to re-send SMS, discard SMS failures or buy more SMS credits.

Task ID: 1922163

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@C3POdoo C3POdoo added the RD research & development, internal work label Apr 11, 2019
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Apr 11, 2019
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Apr 12, 2019
@pro-odoo pro-odoo force-pushed the master-sms-template-pro branch 4 times, most recently from ccf82e4 to bea169e Compare April 16, 2019 08:10
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Apr 16, 2019
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Apr 23, 2019
@pro-odoo pro-odoo requested a review from pimodoo April 23, 2019 13:09
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Apr 23, 2019
@pro-odoo
Copy link
Contributor Author

@pimodoo I changed calendar_sms and hr_presence to work with SMS templates

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Apr 24, 2019
addons/calendar_sms/models/calendar.py Outdated Show resolved Hide resolved
addons/calendar_sms/models/calendar.py Outdated Show resolved Hide resolved
addons/calendar_sms/models/calendar.py Outdated Show resolved Hide resolved
addons/calendar_sms/models/calendar.py Outdated Show resolved Hide resolved
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Apr 25, 2019
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Apr 26, 2019
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Apr 26, 2019
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels May 2, 2019
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels May 9, 2019
record.write({
'state': 'error',
'error_code': 'insufficient_credit'
})
Copy link
Contributor

Choose a reason for hiding this comment

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

to reduce a bit the code, you could make something like this :

for record in self:
    error = 'missing_number' if not record.number else False
    if not error:
        number = record._get_sanitized_number()
        if not number:
            error = 'wrong_number_format'
        else:
            try:
                self.env['sms.api']._send_sms([number], record.content)
            except InsufficientCreditError:
                error = 'insufficient_credit'
    record.write({
        'state': 'error' if error else 'sent',
        'error_code': error
    })

Copy link
Contributor

Choose a reason for hiding this comment

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

And I would prefer to name 'record' into 'sms', so we directly know what we are talking about :)
Same for all the other methods

The aim of this commit is to:

1) Add templates for SMS:
- Users can now create template for SMS Text messages similar to mail templates.
- Templates can be linked with models, especially to create contextual action to quickly send SMS.

2) Improve the SMS composer:
- Integrate the template system.
- Allow to use it for mass SMS.

3) Handle SMS failures:
- SMS is log in the chatter with a fa-comment icon next to the date.
- The icon can be grey if all the SMS have correctly been sent.
- The icon can be red if at least one SMS have not correctly been sent.
- As mail, SMS failures are created if a SMS fails. The failure appears in the inbox.
- When clicking on the red icon, a new modal is displayed, which is used to re-send SMS, discard SMS failures or buy more SMS credits.

Task ID: 1922163
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label May 14, 2019
@pro-odoo
Copy link
Contributor Author

@dbeguin I made the change you suggested and rebased the branch :) Thanks for having a look !

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label May 14, 2019
Copy link
Contributor

@dbeguin dbeguin left a comment

Choose a reason for hiding this comment

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

Some remarks and questions

record.write({
'state': 'error',
'error_code': 'insufficient_credit'
})
Copy link
Contributor

Choose a reason for hiding this comment

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

And I would prefer to name 'record' into 'sms', so we directly know what we are talking about :)
Same for all the other methods

return recipients

@api.multi
def _get_sanitized_number(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be an opportunity to use that in voip enterprise stuff to avoid duplicated code (in a separated prepare commit with sms sanitization stuffs)

Copy link
Contributor

Choose a reason for hiding this comment

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

also, as for 'email_normalized' we could think of a 'number_sanitized' field, so we can directly use it in _send method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok for use it in enterprise, it was intended :)
But the field sanitized, I don't know... We should do one for mobile, one for phone, one for work mobile on employees, one for ... ;-)

to the mail.message
:param body: Note to log in the chatter.
:param sms_ids: IDs of the sms.sms records
:return: ID of the mail.message created
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not the id that is returned but the message itself (even if main message_post docstring is incorrect). So I suggest to rename 'message_id' into 'message' (and maybe adapt the original docstring [in separated commit?])
also, is it not possible to integrate this into message_post directly ? so that the caller calls only message_post and the message post link itself the sms_ids to the message ? (giving sms_ids in kwargs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, what do you prefer ? override message_post ?

'account_token': account.account_token,
'messages': messages
}
endpoint = self.env['ir.config_parameter'].sudo().get_param('sms.endpoint', DEFAULT_ENDPOINT) + '/iap/sms/1/send'
Copy link
Contributor

Choose a reason for hiding this comment

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

This '/iap/sms/1/send' is a route in odoo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in IAP

@@ -12,9 +12,37 @@ class SmsApi(models.AbstractModel):
_name = 'sms.api'
_description = 'SMS API'

@api.model
def _send_multi_sms(self, messages):
""" Send SMS using IAP in batch mode
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be the role of this method to prepare the parameters. I would give sms.sms instead of messages list of dict as sms.sms model contains everything you need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was for the possibility to only send sms, without creating sms.sms

if self.env.context.get('default_composition_mode') != 'mass_sms' \
and not self.env.context.get('default_recipient_ids'):
recipients = self.env['sms.sms']._get_sms_recipients(active_model, records.id)
missing_numbers = []
Copy link
Contributor

Choose a reason for hiding this comment

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

missing_numbers = [recipient['partner_id'].display_name for recipient in recipients if not recipient['number']]

@pro-odoo pro-odoo closed this Oct 7, 2019
@robodoo robodoo added closed 💔 and removed CI 🤖 Robodoo has seen passing statuses labels Oct 7, 2019
@pro-odoo pro-odoo deleted the master-sms-template-pro branch October 14, 2019 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants