تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
13390 أدوات العرض

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
سبتمبر 23
8052
1
مايو 19
6357
3
أكتوبر 18
19459
1
نوفمبر 18
6411
3
يناير 20
6979