diff options
| author | TWA <twa@odoo.com> | 2018-09-27 12:39:02 +0200 |
|---|---|---|
| committer | Rémi Rahir <rar@odoo.com> | 2018-09-29 11:30:21 +0200 |
| commit | c51d4c2d058dcb03148e741f78ca8ba8650f02cf (patch) | |
| tree | 0e78e856ba742595e6e3cdaad8003b8a9e0e00c0 | |
| parent | e12ac2b91b48df436a311b881e0830a4b96b9471 (diff) | |
[FIX] partner_autocomplete: Catch error on get credit balance
| -rw-r--r-- | addons/iap/models/iap.py | 11 | ||||
| -rw-r--r-- | addons/iap/static/src/js/iap_credit_checker_widget.js | 13 | ||||
| -rw-r--r-- | addons/iap/static/src/xml/iap_templates.xml | 5 |
3 files changed, 22 insertions, 7 deletions
diff --git a/addons/iap/models/iap.py b/addons/iap/models/iap.py index 7be42d6f57d..0dd205f663e 100644 --- a/addons/iap/models/iap.py +++ b/addons/iap/models/iap.py @@ -186,7 +186,6 @@ class IapAccount(models.Model): @api.model def get_credits(self, service_name): - credit = 0 account = self.get(service_name) route = '/iap/1/balance' @@ -197,12 +196,14 @@ class IapAccount(models.Model): 'account_token': account.account_token, 'service_name': service_name, } - - credit = jsonrpc(url=url, params=params) - account.sudo().write({'insufficient_credit': credit == 0}) + try: + credit = jsonrpc(url=url, params=params) + account.sudo().write({'insufficient_credit': credit == 0}) + except Exception as e: + _logger.info('Get credit error : %s', str(e)) + credit = -1 return { 'credit': credit, 'url': account.get_credits_url(service_name), } - diff --git a/addons/iap/static/src/js/iap_credit_checker_widget.js b/addons/iap/static/src/js/iap_credit_checker_widget.js index 588d83b1b36..ff7d0740ba1 100644 --- a/addons/iap/static/src/js/iap_credit_checker_widget.js +++ b/addons/iap/static/src/js/iap_credit_checker_widget.js @@ -31,6 +31,7 @@ var IAPCreditChecker = Widget.extend({ this.$loading = this.$widget.find('.loading'); this.$sufficient = this.$widget.find('.sufficient'); this.$insufficient = this.$widget.find('.insufficient'); + this.$error = this.$widget.find('.error'); this.$buyLink = this.$widget.find('.oe_link'); this.$widget.appendTo(this.$el); @@ -52,7 +53,8 @@ var IAPCreditChecker = Widget.extend({ }, { shadow: true, }).then(function (result) { - if (result.credit) self._showSufficient(result.credit); + if (result.credit > 0) self._showSufficient(result.credit); + else if (result.credit < 0) self._showError(); else self._showInsufficient(); self.$buyLink.attr('href', result.url); }); @@ -62,16 +64,25 @@ var IAPCreditChecker = Widget.extend({ this.$loading.show(); this.$sufficient.hide(); this.$insufficient.hide(); + this.$error.hide(); }, _showSufficient: function (credits) { this.$loading.hide(); this.$sufficient.show().find('.remaining_credits').text(credits); this.$insufficient.hide(); + this.$error.hide(); }, _showInsufficient: function () { this.$loading.hide(); this.$sufficient.hide(); this.$insufficient.show(); + this.$error.hide(); + }, + _showError: function () { + this.$loading.hide(); + this.$sufficient.hide(); + this.$insufficient.hide(); + this.$error.show(); }, }); diff --git a/addons/iap/static/src/xml/iap_templates.xml b/addons/iap/static/src/xml/iap_templates.xml index 0afd6d891f0..e7cd0566331 100644 --- a/addons/iap/static/src/xml/iap_templates.xml +++ b/addons/iap/static/src/xml/iap_templates.xml @@ -28,11 +28,14 @@ <i class="fa fa-spinner fa-spin"/> Checking remaining credit ... </div> <div class="insufficient"> - <i class="fa fa-exclamation-triangle text-warning"/> Insufficient credit<br/> + <i class="fa fa-exclamation-triangle text-warning"/> Insufficient credit </div> <div class="sufficient"> <i class="fa fa-check-circle text-success"/> Remaining : <b class="remaining_credits"/> credits </div> + <div class="error"> + <i class="fa fa-question-circle text-muted"/> Temporarily unavailable + </div> </div> <div class="col-sm text-right"> <a class="oe_link" target="_blank"><i class="fa fa-arrow-right"/> Buy more credits</a> |
