-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Retrieve twilio balance from account and display in company
- Loading branch information
1 parent
ee72680
commit aa4003d
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
# © 2018 Danimar Ribeiro <danimaibeiro@gmail.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
from odoo import fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
try: | ||
from twilio.rest import Client | ||
except ImportError: | ||
_logger.error('Cannot import twilio dependencies', exc_info=True) | ||
|
||
class ResCompany(models.Model): | ||
_inherit = 'res.company' | ||
|
||
twilio_account_sid = fields.Char(string="SID Twilio") | ||
twilio_account_sid = fields.Char(string="Twilio Account SID") | ||
twilio_auth_token = fields.Char(string="Twilio Auth Token") | ||
twilio_api_key = fields.Char(string="Twilio API Key") | ||
twilio_api_secret = fields.Char(string="Twilio API Secret") | ||
twilio_number = fields.Char(string="Twilio Número") | ||
|
||
balance_account = fields.Char( | ||
string="Account Balance", compute='_compute_balance_twilio') | ||
|
||
def _compute_balance_twilio(self): | ||
for item in self: | ||
if not item.twilio_account_sid or not item.twilio_auth_token: | ||
continue | ||
client = Client(item.twilio_account_sid, item.twilio_auth_token) | ||
|
||
balance = client.api.balance.fetch() | ||
item.balance_account = "%s: %s" % ( | ||
balance.currency, balance.balance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters