Created
June 19, 2020 12:38
-
-
Save simahawk/9138b5865e2b732531e785d355c2dcb7 to your computer and use it in GitHub Desktop.
attempt to find direct method on odoo component
This file contains 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
def _check_class_direct_func(instance, func_name): | |
"""Check if given instance class has defined a specific function directly.""" | |
# TODO: this should work on normal python classes but not on components. | |
# if func_name in vars(instance.__class__): | |
# return inspect.isfunction(vars(instance.__class__)[func_name]) | |
# FIXME this is not working either because: | |
# (Pdb++) instance.__class__ | |
# <class 'odoo.addons.component.core.sftp.adapter'> | |
# (Pdb++) instance.__class__.__module__ | |
# 'odoo.addons.component.core' | |
# (Pdb++) klass.__module__ | |
# 'odoo.addons.storage_backend_sftp.components.sftp_adapter' | |
for fname, klass in inspect.getmembers( | |
instance.__class__, predicate=inspect.isfunction | |
): | |
if fname == func_name and klass.__module__ == instance.__class__.__module__: | |
# Eg: 'odoo.addons.storage_backend.components.base_adapter' | |
# 'odoo.addons.storage_backend_sftp.components.sftp_adapter' | |
return True | |
# return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment