跳至内容
菜单
此问题已终结
4 回复
13423 查看

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?

形象
丢弃
最佳答案

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 
};
});

形象
丢弃

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.

最佳答案

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
};

});

形象
丢弃

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

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

最佳答案

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


形象
丢弃
最佳答案

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 

形象
丢弃
相关帖文 回复 查看 活动
2
9月 23
8090
1
5月 19
6390
3
10月 18
19530
1
11月 18
6482
3
1月 20
7001