跳至内容
菜单
此问题已终结
3 回复
4103 查看

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!

形象
丢弃
最佳答案

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



形象
丢弃
编写者

Brilliant

最佳答案

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')
]


形象
丢弃
最佳答案

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

形象
丢弃
编写者

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.

相关帖文 回复 查看 活动
0
3月 24
1131
0
12月 23
1489
1
1月 24
1681
18
3月 24
20694
1
5月 21
4406