Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3103 Lượt xem

Hello All,


I have Odoo sh and a created a custom module.


In this module, I want to read in a CSV file from my local machine into a Dataframe:

df = pd.read_csv('path\test.csv', delimiter=';', encoding='utf-8')


When having Odoo running locally it works, but can someone tell me how to achieve this using Odoo sh?


Thanks!


Kind regards,


Nick

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you. 

I have created the module, but the data is dynamic and it updates every hour.

I need to be able to load in the data automatically.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
  1. Create a Python module (e.g., my_module) in your Odoo add-ons folder.
  2. Inside the module, create a Python file (e.g., models.py) and define a model to store the data from the CSV file. For example:
  3. from odoo import models, fields 
  4. classMyModel(models.Model): 
    1. _name = 'my_module.my_model'
    2. name = fields.Char(string='Name') 
    3. email = fields.Char(string='Email') # Add more fields as needed
  5. Create a CSV file (e.g., data.csv) with the corresponding headers and data you want to import. Place it in the module's folder.

  6. In the same Python file (models.py), add a method to read the CSV file and create records in the model. For example:

import csv from odoo import models, api 

classMyModel(models.Model): # ...

@api.modeldefimport_data_from_csv(self): 

with open('my_module/data.csv', 'r') as file: 

​csv_data = csv.DictReader(file) 

​for row in csv_data: 

​self.create({ 'name': row['Name'], 'email': row['Email'], # Set values for other fields })



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 22
2233
0
thg 3 22
2653
2
thg 8 25
2534
1
thg 7 25
950
1
thg 8 25
1151