diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-02-10 15:05:14 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-02-10 15:05:14 +0700 |
| commit | 1ff643c37772d573b5bf4c1814c85cf442de1863 (patch) | |
| tree | a12e84c11456339525effc196187dd7f262d1723 | |
| parent | 8a29d6ef46d15fbce033b94464e139cabb8aeb68 (diff) | |
<iman> update logic add contact tempo(revisi)
| -rw-r--r-- | indoteknik_custom/models/user_pengajuan_tempo_request.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py index 3f960e58..0b77cc87 100644 --- a/indoteknik_custom/models/user_pengajuan_tempo_request.py +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -513,11 +513,28 @@ class UserPengajuanTempoRequest(models.Model): ], limit=1) if existing_contact: - # Perbarui hanya field yang tidak menyebabkan konflik - update_data = {k: v for k, v in contact_data.items() if k != 'name'} - existing_contact.write(update_data) + # Pastikan tidak ada duplikasi nama dalam perusahaan yang sama + duplicate_check = self.env['res.partner'].search([ + ('name', '=', contact_data['name']), + ('id', '!=', existing_contact.id) # Hindari update yang menyebabkan duplikasi global + ], limit=1) + + if not duplicate_check: + # Perbarui hanya field yang tidak menyebabkan konflik + update_data = {k: v for k, v in contact_data.items() if k != 'name'} + existing_contact.write(update_data) + else: + raise UserError(f"Skipping update for {contact_data['name']} due to existing duplicate.") else: - # Buat kontak baru jika belum ada + # Pastikan tidak ada partner lain dengan nama yang sama sebelum membuat baru + duplicate_check = self.env['res.partner'].search([ + ('name', '=', contact_data['name']) + ], limit=1) + + if duplicate_check: + # Jika nama sudah ada tetapi di perusahaan lain, tambahkan nama perusahaan + contact_data['name'] = f"{contact_data['name']} ({self.user_company_id.name})" + self.env['res.partner'].create({ "parent_id": self.user_company_id.id, # Hubungkan ke perusahaan **contact_data, # Tambahkan data kontak |
