Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
13439 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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

});

Ảnh đại diện
Huỷ bỏ

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

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

Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 23
8118
1
thg 5 19
6397
3
thg 10 18
19564
1
thg 11 18
6508
3
thg 1 20
7023