콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I want to sync data table from a SQL server db table to a Odoo database table.

the synchronization should be automatic or there can be an on-click button to sync the data manually.

What are the ways to do this task?

I heard about xmlrpc port, psycopg, and creating a script.  but don't know how  to use them

Need some suggestions

아바타
취소

I think you should first start learning how to do it using whenever you wanna start with and ask specific questions. Otherwise you wouldn't get any help because your question it's too ambiguous and seems like you wanna others to give you a solution for something unclear

작성자

Axel Mendoza, Thanks for your reply.

This is what I have done so far. My objective is to transfer the data from a SQL server to odoo Postgres database automatically. below is my Python script, which will run on scheduled basis.

Now I'm trying to know, what is the industry standard, how are you solving this problem, is there any better way to do this.

import pandas as pd
import pymssql
import psycopg2
import psycopg2.extras

# Function to fetch data from SQL Server data table
def fetch_data_from_sql_server(server, database, username, password, table_name):
connection = pymssql.connect(server=server, database=database, user=username, password=password)
query = f'SELECT TOP 15 CustomerCode,CustomerName,Mobile,Business FROM {table_name};' # Use "TOP 10" to get the first 10 rows
data = pd.read_sql(query, connection)
connection.close()
return data

# Function to insert data into PostgreSQL database
def insert_data_to_postgres(server, database, username, password, table_name, data):
connection_string = f'dbname={database} user={username} password={password} host={server}'
with psycopg2.connect(connection_string) as conn:
data_columns = data.columns.tolist()

# Convert data to a list of tuples to use with psycopg2.extras.execute_values
data_values = [tuple(row) for row in data.to_numpy()]

with conn.cursor() as cur:
for row in data_values:
customer_code = row[0] # Assuming CustomerCode is the first column in the DataFrame
# Check if the CustomerCode exists in the PostgreSQL table
cur.execute(f"SELECT CustomerCode FROM {table_name} WHERE CustomerCode = %s", (customer_code,))
if not cur.fetchone(): # If the customer does not exist, insert the row
insert_query = f"INSERT INTO {table_name} ({', '.join(data_columns)}) VALUES %s"
psycopg2.extras.execute_values(cur, insert_query, [row])

# Commit the changes to the database
conn.commit()

# Configuration for SQL Server
sql_server_config = {
"server": "server_url",
"database": "dbname",
"username": "sa",
"password": "password",
"table_name": "Customer",
}

# Configuration for PostgreSQL
postgres_config = {
"server": "server_url",
"database": "dbname",
"username": "username",
"password": "password",
"table_name": "table_name",
}

# Fetch data from SQL Server
data = fetch_data_from_sql_server(**sql_server_config)

# Insert data into PostgreSQL
insert_data_to_postgres(**postgres_config, data=data)

print("Data transfer completed successfully.")

관련 게시물 답글 화면 활동
2
10월 25
5382
1
10월 25
4121
1
3월 24
2575
1
11월 22
6730
0
12월 21
35