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

Hi, i try make phone lookup addon which fetches name for the number from odoo database and show it on mobile phone

The problem what I have now is how to select database with custom url (if multiple database on same domain)?


I have ULR like below but db parameter doesn't work...


https://odoo.domain.com/lc_phonenumber_lookup/Search?phoneNumber=1234567890&db=mydb2


What I need to add to controller to make it work?

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

Hello timo,

I believe there is no need to add such URL and thing for it if you want to make the name search via phone number you can do it so via the namesearch method too.

Check the name search method which will help you do the same as it is currently working in the backend and fronted so I will basically wirork in the mobile phone too, 

if it don't so then I believe the db thing doesn't need to be added as the odoo doesn't cater the db like this so remove the db from the URL it should work or it still shows the 404 then the error is of handling  the controller provide me the code so I can help with it further 

Thanks!

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

Thanks for quick reply.

I tried with your code but still get 404 error?

I also forget mention Odoo version but it is 17 enterprise.

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

To make ?db=mydb2 work in your Odoo controller:

  1. Set this in odoo.conf:

    ini

    CopyEdit

    dbfilter = .*

  2. Update your controller:

    python

    CopyEdit

    from odoo import http from odoo.http import request class PhoneLookup(http.Controller): @http.route('/lc_phonenumber_lookup/Search', type='http', auth='public', csrf=False) def search(self, phoneNumber=None, db=None, **kw): if db: request.session.db = db partner = request.env['res.partner'].sudo().search([('phone', '=', phoneNumber)], limit=1) return partner.name if partner else "Not found"

That’s it! Now ?db=mydb2 will work.

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

Thanks for quick reply.

I tried with your code but still get 404 error?

I also forget mention Odoo version but it is 17 enterprise

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 19
16046
4
thg 7 25
446
1
thg 5 25
756
0
thg 11 24
1416
0
thg 3 24
1395