Skip to Content
Menu
This question has been flagged
3 Replies
4151 Views

Context

I have to import a large list of contacts. Data for each contact includes name, a national ID number (unique), email, etc.

When I use the import function, there is no way to detect which contacts already exist, so they are duplicated.

Question

Is there a way to detect if a contact is going to be duplicated so I can skip that one and go to the next one?

I know there is a "fuse" function, and I already use it. But this is "after the fact", and I want to avoid the creation of duplicate contatcs.

Thanks!

Avatar
Discard
Best Answer

I believe there is a helper module at OCA that give you the option to select a field as unique comparison so you don't need external ID. You could use contact name or email or VAT ID as example. 


Update: this is the OCA module you want to test: https://odoo-community.org/shop/base-import-match-643#attr=42



Avatar
Discard
Author

Brilliant

Best Answer

Hi  Manuel,

You need programming knowledge to create unique constraints for the that fields of the res.partners model. E.g

class ResPartner:

_inherit='res.partner' 

_sql_constraints = [
('email_uniq', 'UNIQUE (email)', 'Email already exists')
]


Avatar
Discard
Best Answer

Hi

Normal Export and import method:
For importing a contact record we do the exporting process, so in that case the exporting record contains an external id, so when we reimport the same record it not adding the duplicates based on that record. So depending on the external id, there are no duplicates occurring in the import process we haven't external id the record will be duplicated.

Using Script:

def import_inv(self):
   
buffer = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
   
buffer.write(binascii.a2b_base64(self.file))
   
buffer.seek(0)
    book = xlrd.open_workbook(
buffer.name)
    sheet = book.sheet_by_index(
0)
           
for row_no in range(sheet.nrows):
       
if row_no <= 0:
            fields =
map(lambda row: row.value.encode('utf-8'),
                        sheet.row(row_no))
       
else:
           
line = list(
               
map(lambda row: isinstance(row.value,
                                          bytes)
and row.value.encode(
                   
'utf-8') or str(row.value),
                    sheet.row(row_no)))
            partner_id = self.env[
'res.partner'].sudo().browse([line[0]])

           
if line and not partner_id:
                self.env[
'res.partner'].sudo().create({
                   
'id': line[0],
                   
'active': line[1] if line[1] else False,
                   
'type': line[2] if line[2] else False,
                    //you can
add values based on the excel sheet

                })
            elif
line and partnr_id:
          //
if the partner id already available we can write the the record details
          partnr_id.
write({
                   
'id': line[0],
                   
'active': line[1] if line[1] else False,
                   
'type': line[2] if line[2] else False,
                    //you can
add values based on the excel sheet

                })

Hope it helps

Avatar
Discard
Author

Hi Cybrosys. Thanks for the answer, but it does not work for the case I describe.

Of course I can export the file first. I can even chech in excel, prior to importing, if the contacts are duplicates by checking the email or national id number. And then I can upload the contacts that are not going to create a duplicated contact. But this is not what I'm trying to do.

I want to upload the contact list and during the import process I want to check if a the contact is going to be duplicated.

The issue with the process you suggest is that I have to use the contact's ID, and the new contacts (contacts that I want to import) have no ID prior to import. I can't create it manually since some contacts have the name "client" and others have a generic national ID number used when it is not provided.

Related Posts Replies Views Activity
0
Mar 24
1151
0
Dec 23
1523
1
Jan 24
1696
18
Mar 24
20747
1
May 21
4423