Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Override "ir.sequence" field in csv import in Odoo?

I'm trying to import new customer data into Odoo using CSV import. There is one field customer_id_no which is auto generated when the record is created(using the "ir.sequence").

Now each customer record in the CSV has a unique customer_id_no but when I try to import it, the existing customer_id_no is overridden by the standard sequence.

How can I insert the data from CSV as it is in the Odoo?

Also I was unable to find an answer to import many2one fields. Any help on that would be greatful.

like image 997
Vaibhav Bhavsar Avatar asked Nov 08 '16 08:11

Vaibhav Bhavsar


1 Answers

@CZoellner is right. You have to change your method. It would be something like this :

@api.model
def create(self, vals):
    vals['customer_id_no'] = mechanics_to_generate_sequence()
    return super(ClassName, self).create(vals)

It needs to address the case where customer_id_no is provided. Like this

@api.model
def create(self, vals):
    if not vals.get('customer_id_no'):
        vals['customer_id_no'] = mechanics_to_generate_sequence()
    return super(ClassName, self).create(vals)

Note that afterward you would need to make the sequence next iteration to the value next to the highest in customer_id_no.

like image 152
Majikat Avatar answered Nov 16 '22 14:11

Majikat