Skip to content
Snippets Groups Projects
Commit 110cbd80 authored by Robert Latta's avatar Robert Latta
Browse files

updated otrs_get_customer_users_rows to yield Organisations and Customers

parent f552b4fe
No related branches found
No related tags found
No related merge requests found
......@@ -119,8 +119,10 @@ def otrs_get_customer_company_rows(ds):
yield [customer['Name'], customer['FullName'], '', '', '', '', '', '']
def otrs_get_users_as_customers(ds):
yielded = False
def otrs_get_customer_users_rows(ds):
yield ['email', 'username', 'customer_id', 'customer_id_2', 'title',
'firstname', 'lastname', 'phone', 'fax', 'mobile', 'street', 'zip',
'city', 'country', 'comments']
type_priority = {
RelateType.SITE: 1,
RelateType.GROUP: 2,
......@@ -130,20 +132,58 @@ def otrs_get_users_as_customers(ds):
RelateType.CUSTOMER: 6,
}
# TODO - check the rules for prioritisation once model has been confirmed
def _choose_customer_user(cu_1, cu_2):
if not cu_2 or type_priority.get(cu_1['type'], 0) > type_priority.get(
cu_2['type'], 0):
return cu_1
return cu_2
# TODO - check the rules for validation once model has been confirmed
def _is_valid_customer(cus):
# commented out as no contact details are in IMS
# if not cus['email']:
# return False
return True
# TODO - check this rule for getting the customer_id2 once model has been confirmed # noqa
def _get_customer_id2(cus):
if cus['CustomerType'] and cus['CustomerType']['Name'] == 'NREN NOC':
return True
return ''
for customer in ds.get_all_entities(
'Customer',
ims.CUSTOMER_PROPERTIES['CustomerRelatedContacts']):
[
ims.CUSTOMER_PROPERTIES['CustomerRelatedContacts'],
ims.CUSTOMER_PROPERTIES['CustomerType']
]):
# Org as User
org_customer = OrderedDict({
'type': customer['CustomerType']['Name'] if customer[
'CustomerType'] else '',
'email': customer['AccountEmail'],
'username': customer['AccountEmail'],
'customer_id': customer['Name'],
'customer_id_2': _get_customer_id2(customer),
'title': '',
'firstname': customer['Name'],
'lastname': '-',
'phone': '',
'fax': '',
'mobile': '',
'street': '',
'zip': '',
'city': '',
'country': '',
'comments': ''
})
if _is_valid_customer(org_customer):
del org_customer['type']
yield org_customer.values()
# end of Org as User
# Contacts as Users
if customer['CustomerRelatedContacts']:
customer_user = None
......@@ -155,13 +195,13 @@ def otrs_get_users_as_customers(ds):
'email': contact['Contact']['Mail'],
'username': contact['Contact']['Mail'], # TODO if tal_id is going to be present use that # noqa
'customer_id': customer['Name'],
'customer_id_2': '', # TODO populate - need the rules for this # noqa
'title': contact['Contact']['PreFix'], # TODO - double check this is the right field # noqa
'customer_id_2': _get_customer_id2(customer),
'title': '',
'firstname': contact['Contact']['Name'],
'lastname': contact['Contact']['LastName'],
'phone': contact['Contact']['Phone'],
'fax': contact['Contact']['Fax'],
'mobile': contact['Contact']['Mobile'],
'phone': '',
'fax': '',
'mobile': '',
'street': '',
'zip': '',
'city': '',
......@@ -177,23 +217,7 @@ def otrs_get_users_as_customers(ds):
if customer_user:
del customer_user['type']
yield customer_user.values()
yielded = True
# Is there a better way to do this?
if not yielded:
return []
def otrs_get_orgs_as_customers(ds):
return []
def otrs_get_customer_users_rows(ds):
yield ['email', 'username', 'customer_id', 'customer_id_2', 'title',
'firstname', 'lastname', 'phone', 'fax', 'mobile', 'street', 'zip',
'city', 'country', 'comments']
yield from otrs_get_users_as_customers(ds)
yield from otrs_get_orgs_as_customers(ds)
# end of Contact as User
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment