data import using csv error
Hi,
I was trying to port some data from one non-OpenERP system to OpenERP using csv file.
The fields which i want to imports are Code and Name in the Products-Form Products
I have selected the Code and Name as fields to import
The .csv file contains the follwing data
Code,Name
69,"6680 ND NOKIA MOBILE"
70,"6020 IT-NOKIA MOBILE"
But when i do the import , am getting the below error
Unable to import this record:
active: 1
price_margin: 1.0
default_code: 69
price_extra: 0.0
Error Message:
Line 1 : Insertion Failed!
How to resolve this error?
Thanks
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Revision history for this message
|
#1 |
Hello Bushair,
Use like following format:
default_code,name
PC1,Basic PC
PC2,Basic+ PC (assembly on order)
PC3,Medium PC
PC4,Customizable PC
MB1,Mainboard ASUStek A7N8X
MB2,Mainboard ASUStek A7V8X-X
CPU1,Processor AMD Athlon XP 1800+
CPU2,Processor AMD Athlon XP 2200+
HDD1,HDD Seagate 7200.8 80GB
HDD2,HDD Seagate 7200.8 120GB
HDD3,HDD Seagate 7200.8 160GB
FAN,Regular case fan 80mm
FAN2,Silent fan
CPU_GEN,Regular processor config
RAM,DDR 256MB PC400
RAM512,DDR 512MB PC400
CPU2,High speed processor config
TOW1,ATX Mid-size Tower
HDD_GEN,HDD on demand
RAM_GEN,RAM on demand
CPU_GEN,Processor on demand
PC0,Complete PC With Peripherals
KEYA,Keyboard
MOU,Mouse
KIT0,Kit Keyboard + Mouse
DEV,Consultancy - Senior Developer
You had used wrong field name : code, name.
The exact field name is :default_code,name.
Hope this will help you.
Thanks.
Revision history for this message
|
#2 |
Hi,
Thanks for the information.
Can you please Navigate to Products- >Products
then select Import and check with fields available in the left side.
There is no default_code field available.
So how is it possible to have default_code in csv file.
if i use like you mentioned from the above Products- >Products form,
default_code,name
PC1,Basic PC
am getting the below error
Error processing your first line of the file.
Field default_code is unknown!
thanks
Revision history for this message
|
#3 |
Hello Bushair,
You just first try export the data from export wizard and import compatible field needs to be true in export wizard.
The generated wizard output csv will give you better idea regarding fields and format.
Thanks.
Revision history for this message
|
#4 |
Hi,
I have done Export in Products->Products form.
I selected Code and Name field in the export fields.
Selected the import compatible field option.
The generated csv file looks like
default_code name
PC1 Basic PC
But when i try to import the same using import ,
I have selected the Code and Name from the import filed .
Am getting the below error when i try to Browse the csv file
Error processing your first line of the file.
Field default_code is unknown!
Revision history for this message
|
#5 |
Hello Bushair,
I have imported following data successfully.You can check:
default_
PC1a,PC,Basic PC-a,300.0,450.0
PC2b,PC,Basic+ PC (assembly on order)-
PC3c,PC,Medium PC-c,600.0,900.0
PC4b,PC,
code field is functional field and default_code is actual field with type char you can check in product.product class.
product.py => line no:431 and 433.
You need to cover required field also.
Thanks.
Revision history for this message
|
#6 |
Hi,
Thanks for the information.
But can you please let me know how you have imported it using the Import wizard in Products->Products Form.
When we select import wizard from Products->Products Form ,it will list you all the fields available.
From this available fields ,i have to select the fields which i want to import ..right?
Say to import the below csv file ,what all are fields i have to select from the All fields coloumn ?
default_
PC1a,PC,Basic PC-a,300.0,450.0
PC2b,PC,Basic+ PC (assembly on order)-
>>><You need to cover required field also.
What you meant by this?
Or can i import the csv file ,using the browse option in the import wizard ,without selecting the fields requied?
Thanks
Revision history for this message
|
#7 |
Hello Bushair,
No need to select any field you just use auto detect option from import wizard.It will be taken the fields automatically from csv file.
Thanks.
Revision history for this message
|
#8 |
Hi
I just copied the .csv that you send me
default_
PC1a,PC,Basic PC-a,300.0,450.0
PC2b,PC,Basic+ PC (assembly on order)-
PC3c,PC,Medium PC-c,600.0,900.0
PC4b,PC,
Navigated to
Products->Products Form
Then selected import wizard and then selected the .csv file using Browse
But when i select AutoDetect button ,it is erroring out as
Error processing your first line of the file.
Field default_code is unknown!
Is anything wrong in my Naviagtion ,
Products->Products ?
Do i need to select some other menu ?
Really tired with this issue..it will great if you can help me to resolve this
Revision history for this message
|
#9 |
Hello Bushair,
How can this possible?
Make sure you are using latest updated stable code or not.I am sure it will work.
I have tested this in the latest updated code and its working smoothly.
May be this problem occure due to your side changes in code.
Thanks.
Revision history for this message
|
#10 |
Hi,
Am using the server version openerp-
I havent done anychange in the code in my machine.
The other thing i noticed is that if you check the csv file
default_
PC1a,PC,Basic PC-a,300.0,450.0
The first parameter is default_code and there is no field called default_code is not listed in the All Fields.
If i change this to some other fields which is listed in the All Fields ,i am not getting this error.
Revision history for this message
|
#11 |
Hello bushair,
See the code product.py => line no:431 and 433.
_name = "product.product"
_description = "Product"
_table = "product_product"
_inherits = {'product.
_columns = {
'price': fields.
'lst_price' : fields.
'code': fields.
'active': fields.
'variants': fields.
'ean13': fields.
'packaging' : fields.
}
Hope now you will agree with me.
Thanks.
Revision history for this message
|
#12 |
Hi,
So the required fields for importing data to a product list is
default_
Also you have imported the below list from Products->Products ,import wizard..right?
default_
PC1a,PC,Basic PC-a,300.0,450.0
PC2b,PC,Basic+ PC (assembly on order)-
PC3c,PC,Medium PC-c,600.0,900.0
PC4b,PC,
Revision history for this message
|
#13 |
Hello Bushair,
In product object : name and category needs to be filled up and other remaining required are assigned by default value.
Thanks.
Revision history for this message
|
#14 |
Hi,
Thanks for the information.
I have imported the following data successfully.
Name,Category,Code
Basic PC-a,PC,PC1a
But When i import the below data ,it is creating 3 products ,though they are same.
Name,Category,Code
Basic PC-a,PC,PC1a
Basic PC-a,PC,PC1a
Basic PC-a,PC,PC1a
How can i restrict this ?
What i want is that ,the system shouldnt allow to import the same data again.since it will create duplicate rows in the system.
How to acheive this?
Revision history for this message
|
#15 |
Hello Bushair,
You can put your side restriction by adding sql constrainst or in create methods put warning if same data will come.
Thanks.
Revision history for this message
|
#16 |
Hi,
Thank you very much for the information.
It will be great if you can give me and example for the above case.
As i mentioned in my last mail ,my requirement is to restrict the duplicate entries in list of Products
Name,Category,Code
Basic PC-a,PC,PC1a
Basic PC-a,PC,PC1a
Basic PC-a,PC,PC1a
You will be appreciated if you can give me example on how to restrict in the above example using sql contraints and methods.
Thanks
Revision history for this message
|
#17 |
Hello Bushair,
You can check in account.py => for account_account class , account code must be unique.
_sql_constraints = [
]
Thanks.
Revision history for this message
|
#18 |
Hi,
Thank you very much for the information.
So in my case ,while porting to openerp ,i want to make sure that the Product Code and Product Name combinations are unique.
That is there shouldn't be a product with the same product code and product name.
For example ,if am porting the below data,
Name,Code
Basic PC-a,PC1a
Basic PC-a,PC1a
It should say the Error/Warning that the the product is duplicate.
But if it should allow to port the below data
Name,Code
Basic PC-a,PC1a
Basic PC-a,PC1b
So can you please help me to create an sql constraint in the product,py with the above conidtion..
thanks
Revision history for this message
|
#19 |
Hello Bushair,
The sql constraint is already exist in tiny code, I already explained you with code in my previous comment.
But in your case code and name field are exist in two different class product.product and product.template respectively. You can not put sql constraint in one class directly instead you can put openErp constraint in product.product class in following way:
_constraints = [(_check_code_name, 'Error: code and name should be unique', ['default_
you need to define _check_code_name method for checking uniqueness of code and name.
There are so many similar example exist in tiny code.You can take any one as a reference.
Hope this will help you.
Thanks.
Can you help with this problem?
Provide an answer of your own, or ask Bushair for more information if necessary.