Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3624 มุมมอง

I'm trying to override the function dispatch_rpc located in odoo>odoo>service>__init__.py
by using the monkeypatch method.
this is the new definition of the function

# -*- coding: utf-8 -*-

from . import common

import odoo
import threading

from odoo import service

def dispatch_rpc(service_name, method, params):
""" Handle a RPC call.

This is pure Python code, the actual marshalling (from/to XML/JSON)
is done in a upper layer.
"""
threading.current_thread().uid = None
threading.current_thread().dbname.dis = None

if
service_name == 'common':
dispatch = odoo.addons.common.dispatch
elif service_name == 'db':
dispatch = odoo.service.db.dispatch
elif service_name == 'object':
dispatch = odoo.service.model.dispatch

return dispatch(method, params)

service.dispatch_rpc = dispatch_rpc
the probleme is that the new definition of dispatch_rpc is not taken into consideration.
and I get just the behavor of the old definition.



Thanks in advance,
youel


อวตาร
ละทิ้ง

Hi,

firstly, did you check that the server reads your file ? you can add print('====') before your function def dispatch_rpc() and then watch odoo logs to see if displayed.
I think this is probably the issue: your file is not read.

ผู้เขียน

yes the server read my file .

I already checked that by using print("===============") before the function.

ผู้เขียน

yes the server read my file .

I already checked that by using print("===============") before the function.


คำตอบที่ดีที่สุด

Hi,

Try referring the blog on how to apply MonkeyPatching in odoo 16:https://www.cybrosys.com/blog/what-is-monkey-patching-and-how-it-can-be-applied-in-odoo-16

Hope it helps

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

change new fonction name

for exemple 

service.dispatch_rpc = dispatch_rpc_new


อวตาร
ละทิ้ง

not necessarily. he can keep the same name.

Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ก.ย. 25
22327
3
ส.ค. 25
3265
1
พ.ค. 25
3119
1
เม.ย. 25
4092
1
เม.ย. 25
4959