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:
Scott Idem
2022-01-06 18:34:53 -05:00
parent 597c765673
commit 29c6770581
4 changed files with 94 additions and 15 deletions

View File

@@ -284,10 +284,15 @@ def create_address_obj(
# address_dict = address_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'created_on', 'updated_on'})
# ### SECTION ### Process data
# Look for an account_id in the address_obj
if account_id: pass
elif account_id := address_obj.account_id: pass
address_obj.account_id = account_id
address_dict['account_id'] = account_id
address_obj.for_type = for_type
address_obj.for_id = for_id
address_dict['account_id'] = account_id
address_dict['for_type'] = for_type
address_dict['for_id'] = for_id
@@ -309,6 +314,8 @@ def create_address_obj(
def update_address_obj(
address_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
address_dict_obj: Address_Base,
for_type: str = None,
for_id: int|str = None,
create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> bool:
@@ -339,6 +346,17 @@ def update_address_obj(
address_obj.id = address_id # Is this needed?
address_dict['id'] = address_id
# Look for an account_id in the address_obj
if account_id := address_obj.account_id: pass
elif account_id := get_account_id_w_for_type_id(for_type='address', for_id=address_id): pass
# If for_type and for_id are passed then the address needs to be updated
if for_type and for_id:
address_obj.for_type = for_type
address_obj.for_id = for_id
address_dict['for_type'] = for_type
address_dict['for_id'] = for_id
log.debug(address_dict_obj)
# log.debug(address_dict_obj.dict(by_alias=True, exclude_unset=True))
log.debug(address_dict_obj.dict(by_alias=False, exclude_unset=True))