data import using csv error

Asked by Bushair

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
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#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
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#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
Vinay Rana (OpenERP) (vra-openerp) said :
#5

Hello Bushair,

I have imported following data successfully.You can check:

default_code,categ_id,name,standard_price,list_price

PC1a,PC,Basic PC-a,300.0,450.0

PC2b,PC,Basic+ PC (assembly on order)-b,500.0,750.0

PC3c,PC,Medium PC-c,600.0,900.0

PC4b,PC,Customizable PC-d,800.0,1200.0

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
Bushair (bushairka) said :
#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_code,categ_id,name,standard_price,list_price

PC1a,PC,Basic PC-a,300.0,450.0

PC2b,PC,Basic+ PC (assembly on order)-b,500.0,750.0

>>><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
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#8

Hi
I just copied the .csv that you send me

default_code,categ_id,name,standard_price,list_price

PC1a,PC,Basic PC-a,300.0,450.0

PC2b,PC,Basic+ PC (assembly on order)-b,500.0,750.0

PC3c,PC,Medium PC-c,600.0,900.0

PC4b,PC,Customizable PC-d,800.0,1200.0

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
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#10

Hi,
Am using the server version openerp-server-5.0.6
I havent done anychange in the code in my machine.

The other thing i noticed is that if you check the csv file

default_code,categ_id,name,standard_price,list_price

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
Vinay Rana (OpenERP) (vra-openerp) said :
#11

Hello bushair,

See the code product.py => line no:431 and 433.

    _name = "product.product"
    _description = "Product"
    _table = "product_product"
    _inherits = {'product.template': 'product_tmpl_id'}
    _columns = {
        'qty_available': fields.function(_product_qty_available, method=True, type='float', string='Real Stock'),
        'virtual_available': fields.function(_product_virtual_available, method=True, type='float', string='Virtual Stock'),
        'incoming_qty': fields.function(_product_incoming_qty, method=True, type='float', string='Incoming'),
        'outgoing_qty': fields.function(_product_outgoing_qty, method=True, type='float', string='Outgoing'),
        'price': fields.function(_product_price, method=True, type='float', string='Customer Price', digits=(16, int(config['price_accuracy']))),
        'lst_price' : fields.function(_product_lst_price, method=True, type='float', string='List Price', digits=(16, int(config['price_accuracy']))),
        'code': fields.function(_product_code, method=True, type='char', string='Code'),
        'partner_ref' : fields.function(_product_partner_ref, method=True, type='char', string='Customer ref'),
        'default_code' : fields.char('Code', size=64),
        'active': fields.boolean('Active'),
        'variants': fields.char('Variants', size=64),
        'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True),
        'ean13': fields.char('EAN13', size=13),
        'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the packing order and is mainly used if you use the EDI module."),
        'price_extra': fields.float('Variant Price Extra', digits=(16, int(config['price_accuracy']))),
        'price_margin': fields.float('Variant Price Margin', digits=(16, int(config['price_accuracy']))),
    }

Hope now you will agree with me.
Thanks.

Revision history for this message
Bushair (bushairka) said :
#12

Hi,
So the required fields for importing data to a product list is

default_code,categ_id,name,standard_price,list_price ,right?

Also you have imported the below list from Products->Products ,import wizard..right?

default_code,categ_id,name,standard_price,list_price

PC1a,PC,Basic PC-a,300.0,450.0

PC2b,PC,Basic+ PC (assembly on order)-b,500.0,750.0

PC3c,PC,Medium PC-c,600.0,900.0

PC4b,PC,Customizable PC-d,800.0,1200.0

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#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
Vinay Rana (OpenERP) (vra-openerp) said :
#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
Bushair (bushairka) said :
#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
Vinay Rana (OpenERP) (vra-openerp) said :
#17

Hello Bushair,

You can check in account.py => for account_account class , account code must be unique.
 _sql_constraints = [
        ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !')
    ]

Thanks.

Revision history for this message
Bushair (bushairka) said :
#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
Vinay Rana (OpenERP) (vra-openerp) said :
#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_code','name'])]

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.

To post a message you must log in.