Ver código fonte

fix: set_primary and set_primary_email bug (#12299)

* fix: set_primary and set_primary_email bug

When user untick the `is_primary_phone` or `is_primary_mobile` from the contact numbers table, we should reset the phone, mobile number etc.
Same goes for the email address table.

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* Update frappe/contacts/doctype/contact/contact.py

fix variable naming as suggested

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>

* test: Set empty string instead of none for number

Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
Co-authored-by: Suraj Shetty <surajshetty3416@gmail.com>
version-14
Andy Zhu 4 anos atrás
committed by GitHub
pai
commit
138c7841c2
Nenhuma chave conhecida encontrada para esta assinatura no banco de dados ID da chave GPG: 4AEE18F83AFDEB23
2 arquivos alterados com 11 adições e 1 exclusões
  1. +10
    -0
      frappe/contacts/doctype/contact/contact.py
  2. +1
    -1
      frappe/contacts/report/addresses_and_contacts/test_addresses_and_contacts.py

+ 10
- 0
frappe/contacts/doctype/contact/contact.py Ver arquivo

@@ -97,11 +97,16 @@ class Contact(Document):
if len([email.email_id for email in self.email_ids if email.is_primary]) > 1:
frappe.throw(_("Only one {0} can be set as primary.").format(frappe.bold("Email ID")))

primary_email_exists = False
for d in self.email_ids:
if d.is_primary == 1:
primary_email_exists = True
self.email_id = d.email_id.strip()
break

if not primary_email_exists:
self.email_id = ""

def set_primary(self, fieldname):
# Used to set primary mobile and phone no.
if len(self.phone_nos) == 0:
@@ -115,11 +120,16 @@ class Contact(Document):
if len(is_primary) > 1:
frappe.throw(_("Only one {0} can be set as primary.").format(frappe.bold(frappe.unscrub(fieldname))))

primary_number_exists = False
for d in self.phone_nos:
if d.get(field_name) == 1:
primary_number_exists = True
setattr(self, fieldname, d.phone)
break

if not primary_number_exists:
setattr(self, fieldname, "")

def get_default_contact(doctype, name):
'''Returns default contact for the given doctype, name'''
out = frappe.db.sql('''select parent,


+ 1
- 1
frappe/contacts/report/addresses_and_contacts/test_addresses_and_contacts.py Ver arquivo

@@ -103,7 +103,7 @@ class TestAddressesAndContacts(unittest.TestCase):
create_linked_contact(links_list, d)
report_data = get_data({"reference_doctype": "Test Custom Doctype"})
for idx, link in enumerate(links_list):
test_item = [link, 'test address line 1', 'test address line 2', 'Milan', None, None, 'Italy', 0, '_Test First Name', '_Test Last Name', '_Test Address-Billing', '+91 0000000000', None, 'test_contact@example.com', 1]
test_item = [link, 'test address line 1', 'test address line 2', 'Milan', None, None, 'Italy', 0, '_Test First Name', '_Test Last Name', '_Test Address-Billing', '+91 0000000000', '', 'test_contact@example.com', 1]
self.assertListEqual(test_item, report_data[idx])

def tearDown(self):


Carregando…
Cancelar
Salvar