Hi,
You can import Odoo functions from self-made modules and from Odoo source directories. following are a few scenarios with examples.
Importing Odoo Functions in Custom Modules
1. Importing from Odoo source directories
from odoo import models, fields, api
from odoo.exceptions import ValidationError
2. Importing from your own custom modules
# Assuming you have a custom module named 'my_module' with a file 'helpers.py'
from . import helpers
from .models import my_model
3. Relative imports within your module
# In a file within your module, e.g., 'models/product.py'
from . import common
from ..helpers import utils
4. Importing specific functions or classes
from odoo.addons.base.models.res_partner import Partner
5. Using imported functions
class CustomModel(models.Model):
_name = 'custom.model'
@api.model
def custom_method(self):
#Using a function from Odoo core
self.env['res.partner'].create({'name': 'New Partner'})
#Using a function from your custom helper
result = helpers.custom_calculation()
#Using a model from another custom module
my_model.do_something()
6. Importing and using external libraries
#Make sure the library is installed in your Odoo environment
import requests
def external_api_call(self):
response = requests.get('https://api.example.com/data')
# Process the response...
In your case, Try this way to import,
from odoo.addons.my_module1.your_python_file_name import my_method
Note: When importing external libraries, ensure they're listed in your module's external dependencies.
Thanks