Code clean up. Bug fixes for person, user, contact, and address methods. There is a bug related get_account_id_w_for_type_id()
This commit is contained in:
@@ -380,14 +380,21 @@ def create_contact_obj(
|
||||
# contact_dict = contact_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'address', 'created_on', 'updated_on'})
|
||||
|
||||
# ### SECTION ### Process data
|
||||
# Look for an account_id in the contact_obj
|
||||
if account_id: pass
|
||||
elif account_id := contact_obj.account_id: pass
|
||||
|
||||
contact_obj.account_id = account_id
|
||||
contact_dict['account_id'] = account_id
|
||||
|
||||
contact_obj.for_type = for_type
|
||||
contact_obj.for_id = for_id
|
||||
contact_dict['account_id'] = account_id
|
||||
contact_dict['for_type'] = for_type
|
||||
contact_dict['for_id'] = for_id
|
||||
|
||||
# if not address_id and contact_obj.address_id_random:
|
||||
# Look for an address_id in the contact_obj if one was not passed separately
|
||||
if address_id: pass
|
||||
# elif address_id := contact_obj.address.id: pass
|
||||
|
||||
if contact_dict_in_result := sql_insert(data=contact_dict, table_name='contact', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
@@ -454,6 +461,8 @@ def create_contact_obj(
|
||||
def update_contact_obj(
|
||||
contact_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
contact_dict_obj: Contact_Base,
|
||||
for_type: str = None,
|
||||
for_id: int|str = None,
|
||||
address_id: int = None,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
@@ -490,7 +499,20 @@ def update_contact_obj(
|
||||
contact_obj.id = contact_id # Is this needed?
|
||||
contact_dict['id'] = contact_id
|
||||
|
||||
account_id = get_account_id_w_contact_id(contact_id)
|
||||
# Look for an account_id in the contact_obj
|
||||
if account_id := contact_obj.account_id: pass
|
||||
elif account_id := get_account_id_w_for_type_id(for_type='contact', for_id=contact_id): pass
|
||||
|
||||
# If for_type and for_id are passed then the contact needs to be updated
|
||||
if for_type and for_id:
|
||||
contact_obj.for_type = for_type
|
||||
contact_obj.for_id = for_id
|
||||
contact_dict['for_type'] = for_type
|
||||
contact_dict['for_id'] = for_id
|
||||
|
||||
# Look for an address_id in the contact_obj if one was not passed separately
|
||||
if address_id: pass
|
||||
elif address_id := contact_obj.address.id: pass
|
||||
|
||||
if contact_dict_up_result := sql_update(data=contact_dict, table_name='contact', rm_id_random=True): pass
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user