Created
April 18, 2019 09:10
-
-
Save tienhieuD/6c28d7da1716bf9ceda626d697a608b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from odoo import http | |
class SearchController(http.Controller): | |
@http.route('/fresh_crm/search_json/', type='json', auth='public') | |
def search_json(self, keyword, **kwargs): | |
""" | |
Search all data from list config model | |
:param keyword: the keyword to search | |
:param kwargs: optional (domain, order, limit, offset, model) | |
:return: dict of result, example: | |
{ | |
'keyword': keyword, | |
'error': False, | |
'message': 200, | |
'result': { | |
'total': 32, | |
'data': [ | |
{ | |
'string': 'Sale Orders', | |
'model': 'sale.order', | |
'total': 2, | |
'records': [{}, {}], | |
}, | |
{ | |
'string': 'Customer', | |
'model': 'res.partner', | |
'total': 2, | |
'records': [{}, {}], | |
}, | |
{ | |
'string': 'Product', | |
'model': 'product.template', | |
'total': 2, | |
'records': [{}, {}], | |
}, | |
], | |
} | |
} | |
""" | |
if keyword and 'model' in kwargs and 'offset' in kwargs and 'limit' in kwargs: | |
return { | |
'offset': 5, | |
'rest': 5, | |
'records': [ | |
[32, 'SO032', 'Conference Chair', 1290000], | |
[33, 'SO033', 'Conference Chair', 1290000], | |
[34, 'SO034', 'Conference Chair', 1290000], | |
[35, 'SO035', 'Conference Chair', 1290000], | |
[36, 'SO036', 'Conference Chair', 1290000], | |
], | |
} | |
return { | |
'keyword': keyword, | |
'error': False, | |
'message': 200, | |
'result': { | |
'total': 32, | |
'data': [ | |
{ | |
'string': 'Sale Orders', | |
'model': 'sale.order', | |
'total': 6, | |
'records': [ | |
[32, 'SO032', 'Conference Chair', 1290000], | |
[33, 'SO033', 'Conference Chair', 1290000], | |
[34, 'SO034', 'Conference Chair', 1290000], | |
[35, 'SO035', 'Conference Chair', 1290000], | |
[36, 'SO036', 'Conference Chair', 1290000], | |
], | |
}, | |
{ | |
'string': 'Invoices', | |
'model': 'account.invoice', | |
'total': 3, | |
'records': [ | |
[32, 'SO032', 'Conference Chair', 1290000], | |
[33, 'SO033', 'Conference Chair', 1290000], | |
[34, 'SO034', 'Conference Chair', 1290000], | |
[35, 'SO035', 'Conference Chair', 1290000], | |
], | |
}, | |
{ | |
'string': 'Product', | |
'model': 'product.template', | |
'total': 3, | |
'records': [ | |
[32, 'image:16', 'Conference Chair', 1290000], | |
[33, 'image:17', 'Conference Chair', 1290000], | |
[34, 'image:18', 'Conference Chair', 1290000], | |
[35, 'image:19', 'Conference Chair', 1290000], | |
], | |
}, | |
{ | |
'string': 'Customer', | |
'model': 'res.partner', | |
'total': 3, | |
'records': [ | |
[32, 'image:16', 'Conference Chair', 1290000], | |
[33, 'image:16', 'Conference Chair', 1290000], | |
[34, 'image:16', 'Conference Chair', 1290000], | |
[35, 'image:16', 'Conference Chair', 1290000], | |
], | |
}, | |
{ | |
'string': 'Lead/Opps', | |
'model': 'crm.lead', | |
'total': 0, | |
'records': [ | |
# [32, 'SO032', 'Conference Chair', 1290000], | |
# [33, 'SO033', 'Conference Chair', 1290000], | |
# [34, 'SO034', 'Conference Chair', 1290000], | |
# [35, 'SO035', 'Conference Chair', 1290000], | |
], | |
}, | |
{ | |
'string': 'Users', | |
'model': 'res.users', | |
'total': 3, | |
'records': [ | |
[32, 'SO032', 'Conference Chair', 1290000], | |
[33, 'SO033', 'Conference Chair', 1290000], | |
[34, 'SO034', 'Conference Chair', 1290000], | |
[35, 'SO035', 'Conference Chair', 1290000], | |
], | |
}, | |
], | |
}, | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment