Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo JSON Filter and Offset Parameter

Subscribe

Get notified when there's activity on this post

This question has been flagged
jsonpython3jsonrpc
5 Replies
11046 Views
Avatar
shirsendudas.2011@gmail.com
i am developing a json rpc based attendance system. so fer i got this below code working as planned except one thing, when searching for last attendance entry id i'm getting full list of ids associated with the related user, this is how search function works, but i want only the last entry id, i thing this can be achieve by using FILTER and OFFSET (maybe), which i'm unable include in my code. can anybody look at this python code and guide me. getting the full list is not an option for me, as i will use arduino later, so memory is limited. and i wanna know how to include this parameters.
import json
import random
import urllib.request
import datetime
import sys

CODE = sys.argv[1] HOST = 'localhost' PORT = 8069 DB = 'ezp' USER = 'root' PASS = 'toor' url = "http://%s:%s/jsonrpc" % (HOST, PORT) date_time = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
def call(url, service, method, *args): id = random.randint(0, 1000000000) data = {"jsonrpc": "2.0", "params": {"args": args, "method": method,"service":service,}, "id": id, "method": "call",} req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={"Content-Type":"application/json",}) reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8')) if reply.get("error"): raise Exception(reply["error"]) return reply temp = call(url, "common", "login", DB, USER, PASS) uid = temp["result"] print('Login ID: ' + str(uid))
temp = call(url, "object", "execute", DB, uid, PASS, 'hr.employee', 'search', [['barcode', '=', CODE]]) eid = str(temp["result"])[1:-1] if(eid == ''):   print('Employee not exists')   exit()
temp = call(url, "object", "execute", DB, uid, PASS, 'hr.employee', 'read', int(eid), ['name']) for x in temp["result"]: e_name = x['name'] print('Employee Name: ' +str(e_name))
# below rpc list all the attendance ids associated with this user temp = call(url, "object", "execute", DB, uid, PASS, 'hr.attendance', 'search', [['employee_id','=', int(eid)]]) # how can i insart FILTER PARAMETER so thet only the last entry id returns instead of full list?????? attn = temp["result"]
print('All attendances: ' + str(attn))
def fn_check_in(): attn_record = {'employee_id': eid, 'check_in': date_time} result = call(url, "object", "execute", DB, uid, PASS, 'hr.attendance', 'create', attn_record) print('Checked In : ' + str(e_name), ' At: ' + date_time)
def fn_check_out(id): attn_record = {'check_out': date_time} result = call(url, "object", "execute", DB, uid, PASS, 'hr.attendance', 'write', int(id), attn_record) print('Checked Out : ' + str(e_name), ' At: ' + date_time)
def attendance(): if(len(attn) == 0): fn_check_in() else: last_id = attn[0] for i in range(0, len(attn)): if(attn[i] > last_id): last_id = attn[i] print('Last Entry ID: ' + str(last_id)) is_out = call(url, "object", "execute", DB, uid, PASS, 'hr.attendance', 'read', int(last_id), ['check_out']) if('False' in str(is_out)): fn_check_out(last_id) else: fn_check_in() attendance()
0
Avatar
Discard
shirsendudas.2011@gmail.com
Author

Mihran Thalhath i tried your solution and got this server error message

Exception: {'code': 200, 'message': 'Odoo Server Error', 'data': {'name': 'builtins.ValueError', 'debug': 'Traceback (most recent call last):\n File "/odoo/odoo-server/odoo/http.py", line 619, in _handle_exception\n return super(JsonRequest, self)._handle_exception(exception)\n File "/odoo/odoo-server/odoo/http.py", line 309, in _handle_exception\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n File "/odoo/odoo-server/odoo/tools/pycompat.py", line 14, in reraise\n raise value\n File "/odoo/odoo-server/odoo/http.py", line 664, in dispatch\n result = self._call_function(**self.params)\n File "/odoo/odoo-server/odoo/http.py", line 345, in _call_function\n return checked_call(self.db, *args, **kwargs)\n File "/odoo/odoo-server/odoo/service/model.py", line 93, in wrapper\n return f(dbname, *args, **kwargs)\n File "/odoo/odoo-server/odoo/http.py", line 338, in checked_call\n result = self.endpoint(*a, **kw)\n File "/odoo/odoo-server/odoo/http.py", line 909, in __call__\n return self.method(*args, **kw)\n File "/odoo/odoo-server/odoo/http.py", line 510, in response_wrap\n response = f(*args, **kw)\n File "/odoo/odoo-server/odoo/addons/base/controllers/rpc.py", line 71, in jsonrpc\n return dispatch_rpc(service, method, args)\n File "/odoo/odoo-server/odoo/http.py", line 138, in dispatch_rpc\n result = dispatch(method, params)\n File "/odoo/odoo-server/odoo/service/model.py", line 40, in dispatch\n res = fn(db, uid, *params)\n File "/odoo/odoo-server/odoo/service/model.py", line 93, in wrapper\n return f(dbname, *args, **kwargs)\n File "/odoo/odoo-server/odoo/service/model.py", line 175, in execute\n res = execute_cr(cr, uid, obj, method, *args, **kw)\n File "/odoo/odoo-server/odoo/service/model.py", line 164, in execute_cr\n return odoo.api.call_kw(recs, method, args, kw)\n File "/odoo/odoo-server/odoo/api.py", line 391, in call_kw\n result = _call_kw_model(method, model, args, kwargs)\n File "/odoo/odoo-server/odoo/api.py", line 364, in _call_kw_model\n result = method(recs, *args, **kwargs)\n File "/odoo/odoo-server/odoo/models.py", line 4825, in search_read\n result = records.read(fields)\n File "/odoo/odoo-server/odoo/models.py", line 2879, in read\n raise ValueError("Invalid field %r on model %r" % (name, self._name))\nValueError: Invalid field \'order\' on model \'hr.attendance\'\n', 'message': "Invalid field 'order' on model 'hr.attendance'", 'arguments': ["Invalid field 'order' on model 'hr.attendance'"], 'exception_type': 'internal_error'}}

is there any documentation or guide of proper odoo json structure for "read", "search", "edit", "write" all this operation. along with sort limit offset. i tried finding but got only one example of creating 'note'.

Mihran Thalhath

@shirsendudas.2011@gmail.com

You can check the official web services documentation of Odoo for more details. https://www.odoo.com/documentation/12.0/webservices/odoo.html

Avatar
Mihran Thalhath
Best Answer

Hi,


You can try to use the search_read() method to sort the records by check-in or check-out date in descending order and then apply limit as '1' which will only retrieve the last record. I guess the below code fragment should work. Try and revert back    :)


temp = call(url, "object", "execute", DB, uid, PASS, 'hr.attendance', 'search_read', [['employee_id','=', int(eid)]], {'order': 'check_out desc', 'limit': 1})
1
Avatar
Discard
Avatar
Hilar Andikkadavath
Best Answer

Try to pass an argument for sorting according to id descending and limit to one record. This gives you the last record from db.

{'order': 'id desc', 'limit': 1}
0
Avatar
Discard
Avatar
shirsendudas.2011@gmail.com
Author Best Answer

Solved the issue using "execute_kw" instead "execute" 

call(url, "object", "execute_kw", DB, uid, PASS, 'hr.attendance', 'search', [[['employee_id','=', int(eid)]]],{'limit':1,'order': 'id desc'})
0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to return a simple json instead object JsonRpc? (Odoo11)
json jsonrpc odoo11
Avatar
Avatar
1
सित॰ 20
7252
JSON-RPC - define request parameters like limit or fields Solved
json rpc jsonrpc
Avatar
Avatar
Avatar
6
जुल॰ 20
13067
Return reponse as standard json
json jsonrpc odoo12
Avatar
1
मार्च 20
4192
Selecting a specific db for a json request
json request jsonrpc
Avatar
0
मार्च 17
5347
JSON-RPC dont use context (return datetime gmt and lang per default)
json mobile jsonrpc
Avatar
Avatar
1
जून 16
8456
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now