콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
4830 화면

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
1500
0
12월 23
1806
1
1월 24
1980
18
3월 24
21336
1
5월 21
4729