diff --git a/web_widget_child_selector/models/base.py b/web_widget_child_selector/models/base.py index dbe2a4944..a3de9d439 100644 --- a/web_widget_child_selector/models/base.py +++ b/web_widget_child_selector/models/base.py @@ -1,38 +1,31 @@ # Copyright 2019 Creu Blanca # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, _ +from odoo import models class Base(models.AbstractModel): _inherit = 'base' - def get_record_parent(self): - self.ensure_one() - if not hasattr(self, self._parent_name): - return False - parent = getattr(self, self._parent_name) - if not parent: - return False - return parent.name_get()[0] - def _get_record_parents(self, field): if not self: - return [(False, _('Root'))] + return [] return getattr( self, self._parent_name )._get_record_parents(field) + [(self.id, str(getattr(self, field)))] - def _get_record_direct_childs(self, field): + def _get_record_direct_childs(self, field, domain): if not hasattr(self, self._parent_name): return [] return [(r.id, str(getattr(r, field))) for r in self.search([( self._parent_name, '=', self.id or False - )])] + )] + domain)] - def get_record_direct_childs_parents(self, options): + def get_record_direct_childs_parents(self, options, domain=False): + if not domain: + domain = [] field = options.get('child_selection_field', 'display_name') return { - 'childs': self._get_record_direct_childs(field), + 'childs': self._get_record_direct_childs(field, domain), 'parents': self._get_record_parents(field) } diff --git a/web_widget_child_selector/static/description/edit_mode.png b/web_widget_child_selector/static/description/edit_mode.png index f6059749d..4b4c0b8fd 100644 Binary files a/web_widget_child_selector/static/description/edit_mode.png and b/web_widget_child_selector/static/description/edit_mode.png differ diff --git a/web_widget_child_selector/static/src/js/widget_child_selector.js b/web_widget_child_selector/static/src/js/widget_child_selector.js index e94a500b2..ced1c1957 100644 --- a/web_widget_child_selector/static/src/js/widget_child_selector.js +++ b/web_widget_child_selector/static/src/js/widget_child_selector.js @@ -13,7 +13,7 @@ odoo.define('web.web_widget_child_selector', function(require) { 'click .o_child_selection_button': '_onChildSelectionClick', }), start: function () { - // booleean indicating that the content of the input isn't synchronized + // boolean indicating that the content of the input isn't synchronized // with the current m2o value (for instance, the user is currently // typing something in the input, and hasn't selected a value yet). @@ -41,7 +41,11 @@ odoo.define('web.web_widget_child_selector', function(require) { this._rpc({ model: this.field.relation, method: 'get_record_direct_childs_parents', - args: [ resources, this.nodeOptions], + args: [ + resources, + this.nodeOptions, + this.record.getDomain({fieldName: this.name}), + ], context: this.record.getContext(this.recordParams), }) .then(function (data) { @@ -59,31 +63,17 @@ odoo.define('web.web_widget_child_selector', function(require) { })); }); }, - _onChildSelectionParent: function(event) { - var self = this; - this._rpc({ - model: this.field.relation, - method: 'get_record_parent', - args: [[this.value.res_id || false]], - context: this.record.getContext(this.recordParams), - }) - .then(function (parent) { - if (parent) - self._setValue({ - id: parent[0], display_name: parent[1] - }) - else - self._setValue({ - id: false, display_name: false - }); - }); - }, _onChildSelectionClick: function(event) { var target = $(event.target); - var index = target.data('index'); var type = target.data('type'); - var value = (type === 'child') ? this.childs[index]: this.parents[index]; - this._setValue({id: value[0], display_name: value[1]}); + if (type === 'clear') { + this._setValue({id: false}); + } + else { + var index = target.data('index'); + var value = (type === 'child') ? this.childs[index]: this.parents[index]; + this._setValue({id: value[0], display_name: value[1]}); + } }, _renderEdit: function() { this._set_childs(); diff --git a/web_widget_child_selector/static/src/less/widget_child_selector.less b/web_widget_child_selector/static/src/less/widget_child_selector.less index f33199066..e12d715b9 100644 --- a/web_widget_child_selector/static/src/less/widget_child_selector.less +++ b/web_widget_child_selector/static/src/less/widget_child_selector.less @@ -1,9 +1,14 @@ -.btn.o_child_selection_button { - white-space:normal; - width:100%; - margin:2px; -} -a.o_child_selection_button { +.o_child_selection_button { cursor: pointer, } +.o_child_selection_label { + cursor: pointer, +} + +.o_child_selection_clear { + opacity: 0.6; + &:hover { + opacity: 1; + } +} diff --git a/web_widget_child_selector/static/src/xml/widget_child_selector.xml b/web_widget_child_selector/static/src/xml/widget_child_selector.xml index edad93cc0..27b4c6ba9 100644 --- a/web_widget_child_selector/static/src/xml/widget_child_selector.xml +++ b/web_widget_child_selector/static/src/xml/widget_child_selector.xml @@ -15,10 +15,12 @@
- +
@@ -31,6 +33,9 @@ + +