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

I have a CSV with some data related to products and a Custom Module. How can I make my custom module to store the data into the product table (database) when the module gets installed. 

Assume that the CSV (with product data) is also included in module. If some fields from CSV are not present in the product table, it should get created automatically in the table.

Can someone please help me to understand how the CSV reading data works and how can I achieve this?




อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Take a look at the l10n_uk module.  This module imports a CSV file to populate UK Counties.

https://github.com/odoo/odoo/tree/10.0/addons/l10n_uk


You can see in the __manifest__ file of the module the direction to import the file:

'data': [ 
   'data/res.country.state.csv',
],

Also at https://github.com/odoo/odoo/blob/10.0/addons/l10n_uk/__manifest__.py#L26


The CSV file looks like this:

"id","country_id:id","code","name"

"state_uk_1","base.uk","A1","Aberdeenshire"
"state_uk_2","base.uk","A5","Angus"
"state_uk_3","base.uk","A7","Argyll"
"state_uk_4","base.uk","A9","Avon"
"state_uk_5","base.uk","B1","Ayrshire"
"state_uk_6","base.uk","B3","Banffshire"
"state_uk_7","base.uk","B5","Bedfordshire"
"state_uk_8","base.uk","B7","Berkshire"
"state_uk_9","base.uk","B9","Berwickshire"
"state_uk_10","base.uk","C1","Buckinghamshire"
"state_uk_11","base.uk","C3","Caithness"

Also at https://github.com/odoo/odoo/blob/10.0/addons/l10n_uk/data/res.country.state.csv


Which imports these records into Odoo:



Also, see:

https://www.odoo.com/documentation/10.0/reference/data.html#csv-data-files


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi Ray,

Thanks for your kind help. This worked for me well. I just exported the csv of my custom model. Then I put that csv in module with some other data, specified the location in __manifest__.file. Finally installed the module on a new database and all worked fine.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 24
20294
How to install odoo 10 in ubuntu 20.04? แก้ไขแล้ว
1
ก.ย. 23
3112
3
พ.ค. 23
5688
7
เม.ย. 23
49074
Barcode scanner from mobile แก้ไขแล้ว
1
ธ.ค. 22
7908