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

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?

形象
丢弃
最佳答案

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!

形象
丢弃
编写者 最佳答案

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.

形象
丢弃
最佳答案

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.

形象
丢弃
编写者

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

相关帖文 回复 查看 活动
2
7月 19
16041
4
7月 25
443
1
5月 25
754
0
11月 24
1413
0
3月 24
1393