This question has been flagged
1 Reply
10223 Views

While uploading CSV file into the Odoo getting this error:

"Unknown error during import: <class 'openerp.exceptions.ValidationError'>: ('ValidateError', u"Error while validating constraint\n\n'iprodstep.log' object has no attribute 'sales_record_number_id'") at row 2

Resolve other errors first"

Help me please, record "sales_record_number" needs to be checked.

If record number exist .... skip it.

Validation script:

@api.one

@api.constrains('sales_record_number')

def _check_sales_record_number(self):

search = self.search(sales_record_number)

#..... if there is "sales_record_number" in any of this states .... raise error.
# Or maybe someone will tell me how should look like a validation formula ? .....
# I'm a newbee so ... 

sales_record_number = [sales_record_number.id for sales_record_number in search]

for order in self:

if order.sales_record_number in sales_record_number:

raise ValidationError(_('This order is already in Database'))

Guessing that there is an error in this code.

Any suggestion ?

Or just how to check if there is already "sales_record_number" in odoo.


Avatar
Discard
Best Answer

Rob,
You can not simply check sales_record_number value using constraint, because while creating a every new record, this constraint will run.
So, if, while importing data from file(csv), it gets voilated, then an exception will be thrown at the very first voilation only and as a result of which your import will get stopped.

Thats why inspite of using constraint, you can create your own new object  and create a new functionality in that for importing the files using your required validation.

Hope it seems valid for you ..

Avatar
Discard
Author

Hi Pawan, yeah thank you