Hello,
I'm trying to connect to a mysql database within a self-written odoo app.
Here is my code:
from odoo import api, fields, models
import mysql.connector
MYSQL_USER = 'root'
MYSQL_PASSWORD = 'root'
MYSQL_HOST = 'localhost'
MYSQL_DATABASE = 'data'
class importlogic(models.Model):
_name = 'test.data'
_inherit = 'test.data'
cnx = None
def action_import_data(self):
self.process()
def process(self):
self.connect_mysql()
def connect_mysql(self):
self.cnx = mysql.connector.connect(user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
database=MYSQL_DATABASE)
And I receive the following error message:
AttributeError: 'test.data' object attribute 'cnx' is read-only
For the moment I have no idea why this appears, can someone help me?
Thank you.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
1
Reply
1726
Views
Okay, I found the problem
should be importlogic.cnx > the classname because it is the class attribute https://www.toptal.com/python/python-class-attributes-an-overly-thorough-guide
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