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

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.")

Related Posts ตอบกลับ มุมมอง กิจกรรม
Scheduler - Request for Quote creation แก้ไขแล้ว
1
มี.ค. 24
1910
1
พ.ย. 22
4871
1
พ.ค. 22
4643
0
ธ.ค. 21
35
1
ต.ค. 21
2921