Working on contact and address create update v4

This commit is contained in:
Scott Idem
2021-08-25 18:48:55 -04:00
parent a508307df3
commit 107366d4f8
4 changed files with 147 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ def load_contact_obj(
exclude_unset: bool = True,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_address:bool=False
inc_address: bool = False
) -> Contact_Base|dict|bool:
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -41,7 +41,12 @@ def load_contact_obj(
if inc_address:
log.info('Need to include address data...')
address_id = contact_rec.get('address_id', None)
# NOTE: The address_id field needs to be removed from the contact table.
# NOTE: This is not ideal and the view needs to be updated when possible and anything currently pointing to the original contact.address_id needs to be fixed.
if address_id := contact_rec.get('address_id', None): pass # WARNING
elif address_id := contact_rec.get('linked_address_id', None): pass # WARNING
else: pass # WARNING
# address_id = contact_rec.get('address_id', None)
log.debug(address_id)
from app.methods.address_methods import load_address_obj
if address_result := load_address_obj(
@@ -147,12 +152,8 @@ def get_account_id_w_contact_id(
# ### BEGIN ### API Contact Methods ### create_update_contact_obj_v4() ###
# NOTE: This will create a contact and then also create a linked address if contact_obj.address data is passed.
# NOTE: In the future it should be required that account_id, for_type, and for_id should be passed separately. account_id might not be required *if* it can be looked up based on for_type and for_id.
# NOTE: This will create or update a contact.
# Rewrite and updated 2021-08-25
def create_update_contact_obj_v4(
contact_dict_obj: Contact_Base|dict,
@@ -270,6 +271,7 @@ def create_update_contact_obj_v4(
contact_outline['address_id'] = None
address_obj = contact_obj.address
if address_id := contact_obj.address_id: pass
elif address_id := address_obj.id: pass
else: address_id = None
address_obj.id
address_obj.for_type = 'contact'