def get_account_url(self): """ Called only by res settings """ route = '/iap/services' endpoint = iap_tools.iap_get_endpoint(self.env) d = {'dbuuid': self.env['ir.config_parameter'].sudo().get_param('database.uuid')} return '%s?%s' % (endpoint + route, werkzeug.urls.url_encode(d))
def get_credits_url(self, service_name, base_url='', credit=0, trial=False): """ Called notably by ajax crash manager, buy more widget, partner_autocomplete, sanilmail. """ dbuuid = self.env['ir.config_parameter'].sudo().get_param('database.uuid') if not base_url: endpoint = iap_tools.iap_get_endpoint(self.env) route = '/iap/1/credit' base_url = endpoint + route account_token = self.get(service_name).account_token d = { 'dbuuid': dbuuid, 'service_name': service_name, 'account_token': account_token, 'credit': credit, } if trial: d.update({'trial': trial}) return '%s?%s' % (base_url, werkzeug.urls.url_encode(d))
def get_credits(self, service_name): account = self.get(service_name, force_create=False) credit = 0 if account: route = '/iap/1/balance' endpoint = iap_tools.iap_get_endpoint(self.env) url = endpoint + route params = { 'dbuuid': self.env['ir.config_parameter'].sudo().get_param('database.uuid'), 'account_token': account.account_token, 'service_name': service_name, } try: credit = iap_tools.iap_jsonrpc(url=url, params=params) except Exception as e: _logger.info('Get credit error : %s', str(e)) credit = -1 return credit