Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
4 Respostas
13362 Visualizações

When viewing a form in read mode (not editing the form), the user can click on a many2one field, to quickly jump to the form of this record.

The same thing I wish for the many2many_tags widget. I want that when viewing the form and clicking on one of the many2many tags, the corresponding record should be opened. At the moment nothing happens. I think this would be useful and I don't see any down side.

So is it possible to modify the many2many_tags widget to achieve that? What would I have to do?

Avatar
Cancelar
Melhor resposta

Try this and call the widget as 'my_many2many_tags' or change the name:

odoo.define('my_module.my_widget', function (require) { 
"use strict";
var core = require('web.core');
var common = require('web.form_common');
var FieldMany2ManyTags = core.form_widget_registry.get('many2many_tags');
var _t = core._t;
    var MyFieldMany2ManyTags = FieldMany2ManyTags.extend({ 
get_badge_id: function(el){
if ($(el).hasClass('badge')) return $(el).data('id');
return $(el).closest('.badge').data('id');
},
events: {
'click .o_delete': function(e) {
e.stopPropagation();
this.remove_id(this.get_badge_id(e.target));
},
'click .badge': function(e) {
e.stopPropagation();
var self = this;
var record_id = this.get_badge_id(e.target);
new common.FormViewDialog(self, {
res_model: self.many2one.field.relation,
res_id: record_id,
context: self.dataset.context,
title: _t('Open: ') + self.many2one.string,
readonly: self.many2one.get('effective_readonly')
}).on('write_completed', self, function() {
self.dataset.cache[record_id].from_read = {};
self.dataset.evict_record(record_id);
self.render_value();
}).open();
}
}
});
    core.form_widget_registry.add('my_many2many_tags', MyFieldMany2ManyTags); 

return {
        MyFieldMany2ManyTags: MyFieldMany2ManyTags 
};
});

Avatar
Cancelar

Hello pablo, I want to achieve the same thing but instead of open form view in dialog, I want to open the form in the current form view. can you please help.

Melhor resposta

Heres a version of Pablo's answer that works in Odoo 13. Cheers pablo for the template!

odoo.define('my_module.my_widgets', function (require) {
"use strict";

var core = require('web.core');
var dialogs = require('web.view_dialogs');
var registry = require('web.field_registry');
var rel_fields = require('web.relational_fields');
var _t = core._t;

var FieldMany2ManyTagLinks = rel_fields.FieldMany2ManyTags.extend({
get_badge_id: function (el) {
if ($(el).hasClass('badge')) return $(el).data('id');
return $(el).closest('.badge').data('id');
},
events: _.extend({}, rel_fields.FieldMany2ManyTags.prototype.events, {
'click .badge': function (e) {
e.stopPropagation();
var self = this;
var record_id = this.get_badge_id(e.target);
new dialogs.FormViewDialog(self, {
res_model: self.field.relation,
res_id: record_id,
context: self.record.getContext(),
title: _t('Open: ') + self.field.string,
readonly: !self.attrs.can_write,
}).on('write_completed', self, function () {
self.dataset.cache[record_id].from_read = {};
self.dataset.evict_record(record_id);
self.render_value();
}).open();
}
})
});
registry.add('many2many_taglinks', FieldMany2ManyTagLinks);

return {
FieldMany2ManyTagLinks: FieldMany2ManyTagLinks
};

});

Avatar
Cancelar

Grrr odoo forum formatting! Will fix for the next one :)

Bro, you saved my ass XD, it oso works in Odoo15

Melhor resposta

Sorry for bother you but how did you made it works? can you show me the structure of the module please?


Avatar
Cancelar
Melhor resposta

i have the same problem but this is the first time that i use JS . can you help me resolve this problem . i need the steps and thanks 

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
set. 23
7998
1
mai. 19
6324
3
out. 18
19434
1
nov. 18
6364
3
jan. 20
6954