[FIX] partner_autocomplete: Catch error on get credit balance
This commit is contained in:
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user