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

How do I add "Search mode..." option to any many2one field? By selecting this option tree view opens up where I select one record.

I found similar example in Messaging model: 1. I select "Join a group" in "My Groups" category, 2. click "Create", 3. click the expand option for "Authorized Group" many2one list 4. There are listed "Create and Edit" and "Search More..." options. When I click "Search More" it opens up a search tree.

Please, how do I implement the same thing?

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

You have to create a many2one field like:

_columns = {
    'group_public_id': fields.many2one('res.groups', string='Authorized Group'),
}

Here res.groups is a relational table name.

And add this field to the form view in xml file and you can view the Search More.. option.

Ex:

<field name="group_public_id"/>

I have created a demo for you which may help you. Search More is displayed when there are at least 7 records in my.test1.

class my_test1(osv.osv): _name = 'my.test1' _columns = { 'name': fields.char('Test') }

class my_test(osv.osv): _name = 'my.test' _columns = { 'name': fields.char('Test'), 'test_id': fields.many2one('my.test1', string='Test Data'), }

Add following in xml file :

<record id="view_my_test_form" model="ir.ui.view"> <field name="name">my.test.form</field> <field name="model">my.test</field> <field name="arch" type="xml"> <form string="Product Form"> <field name="name"/> <field name="test_id"/> </form> </field> </record>

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you for your answer! :) I want to use my own many2one object than 'res.groups'.

e.g. class my_test(osv.osv): _name = 'my.test' _columns = {'name': fields.char('Test')} my_test()

Then how can I add "Search More" to this object? Thanks!

Have you added search view for that model?

Tác giả

No. Failed several times adding it before. What are the minimum requirements for search view?

You have to create XML record same as VIEW for SEARH VIEW and assign that ID in "search_view_id" attribute in ACTION.

Tác giả

You, sirs, are my heroes! I did not pay attention to this: "Search More is displayed when there are at least 7 records..."! Funnily enough, I spent 7 hours on this problem and all I had to do was add few more records! :)

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

I spent 7 hours on this problem and all I had to do was add few more records! <-- This is Answer. Thank you! you saved my 7 hours :))

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

Hello all,

Is it possible to open "search more" before 7 record. If yes, then from where?

Thanks in advance.

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

In Odoo 15 I have to override _search methdo from js backend.

This way worked for me:

Create a fields.js file with:

/* Override Search More ... option in Many2one fields */
odoo.define('my_module.Fields', function (require) {
"use strict";

var relational_fields = require('web.relational_fields');
var FieldMany2One = relational_fields.FieldMany2One;

FieldMany2One.include({
_search: async function (searchValue = "") {
const value = searchValue.trim();
const domain = this.record.getDomain(this.recordParams);
const context = Object.assign(
this.record.getContext(this.recordParams),
this.additionalContext
);
var values = await this._super.apply(this, arguments);

// Add "Search more..." option even if results count is lower than the limit of 7
if (this.limit >= values.length) {
values = this._manageSearchMore(values, value, domain, context);
}

return values;
},
})
});

Then add this line to __manifest__.py

'assets': {
'web.assets_backend': [
'my_module/static/src/js/fields.js',
],
},

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

Hello ,

I want to do something like, if user click on the many2one column at that time a selection with several records will be displayed under the field and than after one more option will be there "Search More...". If user click on search more button than a search more wizard will be open with all records.

But i want to do something like when user click on that field at that time direct the search more wizard will be open with all the records of that model(instead of a selection of few records and search more option)

I am using the odoo 16 version.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
6060
2
thg 3 15
5746
1
thg 6 22
17409
2
thg 3 15
32392
1
thg 5 18
8827