Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม 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
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

OdooRPC "keys must be str, int, float, bool or None, not frozendict"

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
5320 มุมมอง
อวตาร
Nathanael Lee

Hello All


I try to access the field "invoice_ids" on the model sale.order with OdooRPC. It does not work, it shows the error below. I can access other Many2Many fields, for example tag_ids without problems. I can access the field invoice_ids from Odoo itself, also with code, but not with OdooRPC. What could be the problem? Thank you!


CODE:

for order in SaleOrder.browse(SaleOrder_ids):
print (order.invoice_ids)

ERROR:

ERROR: {'code': 200, 'message': 'Odoo Server Error', 'data': {'name': 'builtins.TypeError', 'debug': 'Traceback (most recent call last):\n  File "/home/odoo/src/odoo/odoo/http.py", line 1584, in _serve_db\n    return service_model.retrying(self._serve_ir_http, self.env)\n  File "/home/odoo/src/odoo/odoo/service/model.py", line 133, in retrying\n    result = func()\n  File "/home/odoo/src/odoo/odoo/http.py", line 1611, in _serve_ir_http\n    response = self.dispatcher.dispatch(rule.endpoint, args)\n  File "/home/odoo/src/odoo/odoo/http.py", line 1818, in dispatch\n    return self._response(result)\n  File "/home/odoo/src/odoo/odoo/http.py", line 1854, in _response\n    return self.request.make_json_response(response)\n  File "/home/odoo/src/odoo/odoo/http.py", line 1438, in make_json_response\n    data = json.dumps(data, ensure_ascii=False, default=date_utils.json_default)\n  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps\n    **kw).encode(obj)\n  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode\n    chunks = self.iterencode(o, _one_shot=True)\n  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode\n    return _iterencode(o, 0)\nTypeError: keys must be str, int, float, bool or None, not frozendict\n', 'message': 'keys must be str, int, float, bool or None, not frozendict', 'context': {}, 'arguments': ['keys must be str, int, float, bool or None, not frozendict']}}
Traceback (most recent call last):
  File "main.py", line 25, in 
    print (order.invoice_ids)
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/fields.py", line 415, in __get__
    env, ids, from_record=(instance, self))
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/models.py", line 246, in _browse
    records._init_values()
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/models.py", line 361, in _init_values
    self.ids, basic_fields, context=context, load='_classic_write')
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/models.py", line 74, in rpc_method
    cls._name, method, args, kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/odoo.py", line 486, in execute_kw
    'args': args_to_send})
  File "/home/pi/.local/lib/python3.5/site-packages/odoorpc/odoo.py", line 285, in json
    data['error'])
odoorpc.error.RPCError: keys must be str, int, float, bool or None, not frozendict


0
อวตาร
ละทิ้ง
Nathanael Lee
ผู้เขียน

Dear Jort


Thanks for your fast response. I already tried your approach, and now tried again, but with the same result. It gives me exactly the same error.


Best regards

Jort de Vreeze

Apologies, I was too hasty in answering your question. Looking at the source code for Odoo 15 I noticed that the invoice_ids is a computed value, and as such, it is not stored in the database. You should be able to access it with something like below, which is taken from the source code of the sale.order model:

@api.depends('order_line.invoice_lines')
def _get_invoiced(self):
# The invoice_ids are obtained thanks to the invoice lines of the SO
# lines, and we also search for possible refunds created directly from
# existing invoices. This is necessary since such a refund is not
# directly linked to the SO.
for order in self:
invoices = order.order_line.invoice_lines.move_id.filtered(lambda r: r.move_type in ('out_invoice', 'out_refund'))
order.invoice_ids = invoices
order.invoice_count = len(invoices)

So `order.order_line.invoice_lines.move_id.filtered(lambda r: r.move_type in ('out_invoice', 'out_refund'))` should return the invoice ids.

Jort de Vreeze

For OdooRPC this could look something like this:

ids = [1,2]

result_dict = {}

sale_orders = env.execute(
'sale.order',
'search_read',
[],
{
'domain': [('id', 'in', ids)],
'fields': ['id'],
}
)

for sale_order in sale_orders:
sale_order_lines = env.execute(
'sale.order.line',
'search_read',
[],
{
'domain': [('order_id', '=', sale_order['id'])],
'fields': ['invoice_lines'],
}
)
invoice_ids = []

for sale_order_line in sale_order_lines:
for invoice_line in sale_order_line['invoice_lines']:
move_lines = env.execute(
'account.move.line',
'search_read',
[],
{
'domain': [('id', '=', invoice_line)],
'fields': ['move_id'],
}
)
for move_line in move_lines:
if move_line['move_id']:

invoice_id = env.execute(
'account.move',
'search_read',
[],
{
'domain': [('id', '=', move_line['move_id'][0])],
'fields': ['move_type'],
}
)[-1]

if invoice_id['move_type'] in ['out_invoice', 'out_refund']:
invoice_ids.append(invoice_id['id'])

result_dict[sale_order['id']] = invoice_ids

print(result_dict)

You should probably change some parts to fit your requirements, and perhaps make it more efficient (i.e., less loops).

อวตาร
Dany Lopez
คำตอบที่ดีที่สุด

Hello

The problem is with the binary fields, when odoo convert a dictionary in string with the json.dumps library, and exist a key like frozen dictionary.


For solve this problem.

* Edit the code odoo. (I don't know if it can be override this code in other module).

In the file: 'odoo/odoo/http.py', add the method in the line 1635:

def key_dict2str(self, value):        
​res = {}
​for k, v in value.items():
​if isinstance(k, dict):
​ ​ ​k = json.dumps(k, ensure_ascii=False, default=date_utils.json_default)
res[k] = v
​ ​if isinstance(v, dict):
​ ​ ​res[k] = self.key_dict2str(v)
​ ​elif isinstance(v, list):
​ ​ ​res_list = []
​ ​ ​for l in v:
​ ​ ​ ​if isinstance(l, dict):
​ ​ ​ ​ ​res_list.append(self.key_dict2str(l))
else:
​ ​ ​ ​ ​res_list.append(l)
​ ​ ​res[k] = res_list
​ ​else:
​ ​ ​res[k] = v
​return res

And replace the line:

data = json.dumps(data, ensure_ascii=False, default=date_utils.json_default)

For

data = self.key_dict2str(data)
data = json.dumps(data, ensure_ascii=False, default=date_utils.json_default)

inside the method: def make_json_response(.... in the line 1635.





 


0
อวตาร
ละทิ้ง
อวตาร
Guido Leenders
คำตอบที่ดีที่สุด

Found two identical bugs in github: 

https://github\.com/odoo/odoo/issues/129493
https://github\.com/odoo/odoo/issues/109938

We\ are\ now\ solving\ it\ by\ skipping\ those\ fields,\ maintained\ in\ a\ manual\ list\.\ Pingback https://forums.invantive.com/t/odoo-v16-itgenodo047-odoo-server-error-keys-must-be-str-int-float-bool-or-none-not-frozendict-200/3671

0
อวตาร
ละทิ้ง
อวตาร
Niyas Raphy (Walnut Software Solutions)
คำตอบที่ดีที่สุด

Hi,

In the account.move model the problem is related to the tax_totals fields, which stores data as frozendict or defaultdict and as the xmlrpc is not able to handle this type of data, it is getting failed.

Until it get fixed in the odoo core, as tweek at the moment, you can specify the list of field names you need to read and get the data. Just exclude the tax_total field from it.


See this answer:  https://www.odoo.com/forum/help-1/can-the-read-operation-fetch-multiple-results-in-the-xml-rpc-api-229678#answer-229679


Thanks

0
อวตาร
ละทิ้ง
อวตาร
Jainesh Shah(Aktiv Software)
คำตอบที่ดีที่สุด

Hi Nathanael Lee,


I also encountered the same problem when I used OdooRPC to access 'account.move' records. It seems that the 'browse' method in the model 'account.move' has some bug. I tried some other ORM methods and they worked fine.

You can check the following example for reference. 

Please Find Example in Comment.

Hope it will be helpful to you.

Thanks & Regards,
Email:  odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

0
อวตาร
ละทิ้ง
Jainesh Shah(Aktiv Software)

Please find code example here :-

import config
import odoorpc
import os

odoo = odoorpc.ODOO(config.url, 'jsonrpc+ssl', 443)
odoo.login(config.db, config.username, config.password)

AccountMove = odoo.env['account.move']
SaleOrder = odoo.env['sale.order']

inv = AccountMove.search([('state', '=', 'draft')])
print(inv)

SaleOrder_ids = SaleOrder.search([('state', '=', 'sale')])

for order in SaleOrder.browse(SaleOrder_ids):
print (order.read(['invoice_ids']))

อวตาร
Nathanael Lee
ผู้เขียน คำตอบที่ดีที่สุด

Dear Jort


Thanks for your detailed answer!

BUT: It seems OdooRPC can not access the account.move model at all. The below code gives me the exactly same error, even though I am only browsing the model for a record. If I do the same with sale.order, it works.

BTW: I am using Odoo V16.

The user has Admin access, so this should not be a problem. Might it be a problem with OdooRPC?


import config
import odoorpc
import os

odoo = odoorpc.ODOO(config.url, 'jsonrpc+ssl', 443)
odoo.login(config.db, config.username, config.password)


AccountMove = odoo.env['account.move']

inv = AccountMove.browse(1465)
0
อวตาร
ละทิ้ง
Jort de Vreeze

It's likely that this object contains complex data types or relationships that cannot be automatically converted into a serializable format. Try to modify what's returned by the API call. If the error is raised when you're making an API call, try modifying your call to return simpler data. For instance, instead of returning an entire account.move object, you could return only the fields you need.

invoice_fields = env.execute('account.move', 'fields_get', [], {'attributes': ['string', 'type']})

for k, v in invoice_fields.items():
print(k, v)

อวตาร
Jort de Vreeze
คำตอบที่ดีที่สุด

The error message is indicating that it's received a frozendict​ object which it's unable to serialize. frozendict​ is a type of immutable dictionary in Python. Try printing the IDs (or any other attribute) of each invoice related to the sale order, rather than trying to print the entire RecordSet. For debugging purposes it might be helpful to add some error-checking code to handle unexpected data types:


for order in SaleOrder.browse(SaleOrder_ids):
try:
for invoice in order.invoice_ids:
print(invoice.id) # Or any other attribute of the invoice
except TypeError as e:
print(f'An error occurred: {e}')

0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة 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 เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ 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