[IMP] partner_autocomplete: diverse improvements
- CRON changed to 60min - Fixed display/rendering issues with autocomplete widgets. - Moved 'Insufficient credit' banner - Editable endpoint for partner_autocomplete service
This commit is contained in:
@@ -199,7 +199,7 @@ class IapAccount(models.Model):
|
||||
}
|
||||
|
||||
credit = jsonrpc(url=url, params=params)
|
||||
account.write({'insufficient_credit': credit == 0})
|
||||
account.sudo().write({'insufficient_credit': credit == 0})
|
||||
|
||||
return credit
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<field name="model_id" ref="model_res_partner_autocomplete_sync"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.start_sync()</field>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_number">60</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall"/>
|
||||
|
||||
@@ -9,9 +9,11 @@ class ResConfigSettings(models.TransientModel):
|
||||
partner_autocomplete_insufficient_credit = fields.Boolean('Insufficient credit', default=lambda self: self.env['iap.account'].get('partner_autocomplete').insufficient_credit)
|
||||
|
||||
@api.multi
|
||||
def redirect_to_buy_autocmplete_credit(self):
|
||||
def redirect_to_buy_autocomplete_credit(self):
|
||||
Account = self.env['iap.account']
|
||||
Account.get('partner_autocomplete').sudo().write({'insufficient_credit': False})
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': self.env['iap.account'].get_credits_url('partner_autocomplete'),
|
||||
'url': Account.get_credits_url('partner_autocomplete'),
|
||||
'target': '_new',
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ from odoo.addons.iap.models.iap import InsufficientCreditError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
PARTNER_REMOTE_URL = 'https://partner-autocomplete.odoo.com/iap/partner_autocomplete'
|
||||
DEFAULT_ENDPOINT = 'https://partner-autocomplete.odoo.com'
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_name = 'res.partner'
|
||||
@@ -75,9 +75,15 @@ class ResPartner(models.Model):
|
||||
|
||||
return country_id, state_id
|
||||
|
||||
@api.model
|
||||
def get_endpoint(self):
|
||||
url = self.env['ir.config_parameter'].sudo().get_param('iap.partner_autocomplete.endpoint', DEFAULT_ENDPOINT)
|
||||
url += '/iap/partner_autocomplete'
|
||||
return url
|
||||
|
||||
@api.model
|
||||
def _rpc_remote_api(self, action, params, timeout=15):
|
||||
url = '%s/%s' % (PARTNER_REMOTE_URL, action)
|
||||
url = '%s/%s' % (self.get_endpoint(), action)
|
||||
account = self.env['iap.account'].get('partner_autocomplete')
|
||||
params.update({
|
||||
'db_uuid': self.env['ir.config_parameter'].sudo().get_param('database.uuid'),
|
||||
@@ -90,10 +96,9 @@ class ResPartner(models.Model):
|
||||
except (ConnectionError, HTTPError, exceptions.AccessError) as exception:
|
||||
_logger.error('Autocomplete API error: %s' % str(exception))
|
||||
return False, str(exception)
|
||||
except InsufficientCreditError:
|
||||
account = self.env['iap.account'].get('partner_autocomplete')
|
||||
if account:
|
||||
account.write({'insufficient_credit': True})
|
||||
except InsufficientCreditError as exception:
|
||||
_logger.warning('Insufficient Credits for Autocomplete Service: %s' % str(exception))
|
||||
account.sudo().write({'insufficient_credit': True})
|
||||
return False, 'Insufficient Credit'
|
||||
|
||||
@api.model
|
||||
@@ -172,9 +177,8 @@ class ResPartner(models.Model):
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
record = super(ResPartner, self).write(values)
|
||||
res = super(ResPartner, self).write(values)
|
||||
if len(self) == 1:
|
||||
for partner in self:
|
||||
partner._update_autocomplete_data(values.get('vat', False))
|
||||
self._update_autocomplete_data(values.get('vat', False))
|
||||
|
||||
return record
|
||||
return res
|
||||
|
||||
@@ -43,7 +43,8 @@ return {
|
||||
return suggestion.website;
|
||||
});
|
||||
clearbitSuggestions.forEach(function (suggestion) {
|
||||
if (websites.indexOf(suggestion.website) < 0) {
|
||||
if (websites.indexOf(suggestion.domain) < 0) {
|
||||
websites.push(suggestion.domain);
|
||||
odooSuggestions.push(suggestion);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,16 +65,19 @@ var PartnerField = FieldMany2One.extend({
|
||||
*/
|
||||
_modifyAutompleteRendering: function (){
|
||||
var api = this.$input.data('ui-autocomplete');
|
||||
var renderWithoutLogo = api._renderItem;
|
||||
api._renderItem = function ( ul, item ) {
|
||||
var $li = renderWithoutLogo.call(this, ul, item);
|
||||
api._renderItem = function(ul, item){
|
||||
ul.addClass('o_partner_autocomplete_dropdown');
|
||||
var $a = $('<a/>')["html"](item.label);
|
||||
if (item.logo){
|
||||
var $a = $li.find('>a').addClass('o_partner_autocomplete_dropdown_item');
|
||||
var $img = $('<img/>').attr('src', item.logo);
|
||||
$a.append($img);
|
||||
}
|
||||
|
||||
return $li;
|
||||
return $("<li></li>")
|
||||
.data("item.autocomplete",item)
|
||||
.append($a)
|
||||
.appendTo(ul)
|
||||
.addClass(item.classname);
|
||||
};
|
||||
},
|
||||
|
||||
@@ -104,20 +107,17 @@ var PartnerField = FieldMany2One.extend({
|
||||
Autocomplete.autocomplete(search_val).then(function (suggestions) {
|
||||
var choices = [];
|
||||
if (suggestions && suggestions.length) {
|
||||
choices.push({
|
||||
label: _t('Create and Edit from Autocomplete :'),
|
||||
});
|
||||
_.each(suggestions, function (suggestion) {
|
||||
var label =_.str.sprintf('%s - %s', suggestion.label, suggestion.description);
|
||||
label = label.replace(new RegExp(search_val, "gi"), "<b>$&</b>");
|
||||
var label = '<i class="fa fa-magic text-muted"/> ';
|
||||
label += _.str.sprintf('%s, <span class="text-muted">%s</span>', suggestion.label, suggestion.description);
|
||||
|
||||
choices.push({
|
||||
label: label,
|
||||
action: function () {
|
||||
self._createPartner(suggestion);
|
||||
},
|
||||
classname: 'o_m2o_dropdown_option',
|
||||
logo: suggestion.logo,
|
||||
classname: 'o_partner_autocomplete_dropdown_item',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,11 +18,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
.ui-autocomplete .ui-menu-item > a.o_partner_autocomplete_dropdown_item {
|
||||
> img {
|
||||
float: right;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
.ui-autocomplete.o_partner_autocomplete_dropdown {
|
||||
> .ui-menu-item:nth-of-type(1n+16) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
}
|
||||
> .o_partner_autocomplete_dropdown_item {
|
||||
> a {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
position: relative;
|
||||
padding-right: 50px;
|
||||
padding-left: 40px;
|
||||
max-width: 400px;
|
||||
> img {
|
||||
position: absolute;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
right: 20px;
|
||||
top: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
> .ui-menu-item.ui-state-focus .text-muted {
|
||||
color: white !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ odoo.define('partner_autocomplete.tests', function (require) {
|
||||
QUnit.module('partner_autocomplete', {
|
||||
before: function () {
|
||||
var suggestions = [
|
||||
{name: "Odoo", website: "odoo.com", logo: "odoo.com/logo.png", vat: "BE0477472701"}
|
||||
{name: "Odoo", website: "odoo.com", domain: "odoo.com", logo: "odoo.com/logo.png", vat: "BE0477472701"}
|
||||
];
|
||||
|
||||
var enrich_data = {
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
<widget name="iap_credit_checker" service_name="partner_autocomplete"/>
|
||||
</div>
|
||||
|
||||
<xpath expr="//div[hasclass('app_settings_block')]" position="before">
|
||||
<field name="partner_autocomplete_insufficient_credit" invisible="1"/>
|
||||
<div class="alert alert-info alert-dismissible fade show pt-2 pb-2" role="alert" attrs="{'invisible': [('partner_autocomplete_insufficient_credit', '=', False)]}">
|
||||
<xpath expr="//div[hasclass('app_settings_block')][@data-key='general_settings']/div[1]" position="before">
|
||||
<div class="alert alert-info alert-dismissible fade show pt-2 pb-2" role="alert" attrs="{'invisible': [('partner_autocomplete_insufficient_credit', '=', False)]}" data-showfor="crm,general_settings">
|
||||
<field name="partner_autocomplete_insufficient_credit" invisible="1"/>
|
||||
<i class="fa fa-exclamation-triangle text-warning"></i> &nbsp; You don't have credits to auto-complete companies' data anymore.
|
||||
<button name="redirect_to_buy_autocmplete_credit" type="object" class="btn-link">
|
||||
<button name="redirect_to_buy_autocomplete_credit" type="object" class="btn-link">
|
||||
<i class="fa fa-arrow-right"/>
|
||||
Buy more credits
|
||||
</button>
|
||||
@@ -25,4 +25,3 @@
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
<field name="partner_gid" invisible="True"/>
|
||||
<field name="additional_info" invisible="True"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('oe_title')]/div[hasclass('o_row')]/field[@name='parent_id']" position="attributes">
|
||||
<attribute name="help">You can find a customer, a contact, etc. by its Name, TIN, Email or Internal Reference.</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -36,9 +33,6 @@
|
||||
<field name="partner_gid" invisible="True"/>
|
||||
<field name="additional_info" invisible="True"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('oe_title')]/div[hasclass('o_row')]/field[@name='parent_id']" position="attributes">
|
||||
<attribute name="help">You can find a customer, a contact, etc. by its Name, TIN, Email or Internal Reference.</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user