[FIX] iap, partner_autocomplete: Autocomplete without IAP account token
Steps to reproduce the bug: - Go to Settings > Technical > IAP account > - Remove the access token - Go to Contact - Try to create a company called 'Proximus' and click on the autocomplete Bug: A traceback was raised because the IAP account token was not set. opw:2087607 closes odoo/odoo#39099 X-original-commit: bc6357f0b95d354afa602eecce24a3c265819101 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
@@ -209,6 +209,18 @@ class IapAccount(models.Model):
|
||||
|
||||
return '%s?%s' % (endpoint + route, werkzeug.urls.url_encode(d))
|
||||
|
||||
@api.model
|
||||
def get_config_account_url(self):
|
||||
account = self.env['iap.account'].get('partner_autocomplete')
|
||||
action = self.env.ref('iap.iap_account_action')
|
||||
menu = self.env.ref('iap.iap_account_menu')
|
||||
no_one = self.user_has_groups('base.group_no_one')
|
||||
if account:
|
||||
url = "/web#id=%s&action=%s&model=iap.account&view_type=form&menu_id=%s" % (account.id, action.id, menu.id)
|
||||
else:
|
||||
url = "/web#action=%s&model=iap.account&view_type=form&menu_id=%s" % (action.id, menu.id)
|
||||
return no_one and url
|
||||
|
||||
@api.model
|
||||
def get_credits(self, service_name):
|
||||
account = self.get(service_name, force_create=False)
|
||||
|
||||
@@ -90,6 +90,13 @@ msgid ""
|
||||
" <b>Employees:</b>"
|
||||
msgstr ""
|
||||
|
||||
#. module: partner_autocomplete
|
||||
#. openerp-web
|
||||
#: code:addons/partner_autocomplete/static/src/js/partner_autocomplete_core.js:0
|
||||
#, python-format
|
||||
msgid "IAP Account Token missing"
|
||||
msgstr ""
|
||||
|
||||
#. module: partner_autocomplete
|
||||
#: model:ir.model.fields,field_description:partner_autocomplete.field_res_partner__additional_info
|
||||
#: model:ir.model.fields,field_description:partner_autocomplete.field_res_users__additional_info
|
||||
@@ -213,6 +220,13 @@ msgstr ""
|
||||
msgid "Searching Autocomplete..."
|
||||
msgstr ""
|
||||
|
||||
#. module: partner_autocomplete
|
||||
#. openerp-web
|
||||
#: code:addons/partner_autocomplete/static/src/xml/partner_autocomplete.xml:0
|
||||
#, python-format
|
||||
msgid "Set Your Account Token"
|
||||
msgstr ""
|
||||
|
||||
#. module: partner_autocomplete
|
||||
#: model_terms:ir.ui.view,arch_db:partner_autocomplete.additional_info_template
|
||||
msgid "Twitter :"
|
||||
|
||||
@@ -87,6 +87,8 @@ class ResPartner(models.Model):
|
||||
return False, 'Insufficient Credit'
|
||||
url = '%s/%s' % (self.get_endpoint(), action)
|
||||
account = self.env['iap.account'].get('partner_autocomplete')
|
||||
if not account.account_token:
|
||||
return False, 'No Account Token'
|
||||
params.update({
|
||||
'db_uuid': self.env['ir.config_parameter'].sudo().get_param('database.uuid'),
|
||||
'account_token': account.account_token,
|
||||
|
||||
@@ -141,6 +141,11 @@ var PartnerAutocompleteMixin = {
|
||||
company_data = company;
|
||||
}
|
||||
|
||||
if (company_data.error && company_data.error_message === 'No Account Token') {
|
||||
self._notifyAccountToken();
|
||||
company_data = company;
|
||||
}
|
||||
|
||||
if (_.isEmpty(company_data)) {
|
||||
company_data = company;
|
||||
}
|
||||
@@ -326,6 +331,26 @@ var PartnerAutocompleteMixin = {
|
||||
self.do_notify(title, content, false, 'o_partner_autocomplete_no_credits_notify');
|
||||
});
|
||||
},
|
||||
|
||||
_notifyAccountToken: function () {
|
||||
var self = this;
|
||||
return this._rpc({
|
||||
model: 'iap.account',
|
||||
method: 'get_config_account_url',
|
||||
args: []
|
||||
}).then(function (url) {
|
||||
var title = _t('IAP Account Token missing');
|
||||
if (url){
|
||||
var content = Qweb.render('partner_autocomplete.account_token', {
|
||||
account_url: url
|
||||
});
|
||||
self.do_notify(title, content, false, 'o_partner_autocomplete_no_credits_notify');
|
||||
}
|
||||
else {
|
||||
self.do_notify(title);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
return PartnerAutocompleteMixin;
|
||||
|
||||
@@ -20,4 +20,8 @@
|
||||
<div t-name="partner_autocomplete.insufficient_credit_notification" class="">
|
||||
<a class="btn btn-link" t-att-href="credits_url"><i class="fa fa-arrow-right"/> Buy more credits</a>
|
||||
</div>
|
||||
|
||||
<div t-name="partner_autocomplete.account_token" class="">
|
||||
<a class="btn btn-link" t-att-href="account_url" ><i class="fa fa-arrow-right"/> Set Your Account Token</a>
|
||||
</div>
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user