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

Added OTRS Export development

parent 0599f9e5
No related branches found
No related tags found
No related merge requests found
import re
from collections import OrderedDict
from inventory_provider.db import ims
from inventory_provider.db.ims import IMS, InventoryStatus
from inventory_provider.db.ims import IMS, InventoryStatus, RelateType
INTERNAL_POP_NAMES = {
'Cambridge OC',
......@@ -111,6 +112,90 @@ def get_interface_info(ds):
yield from ds.get_all_entities('Port')
def otrs_get_customer_company_rows(ds):
yield ['customer_id', 'name', 'street', 'zip', 'city', 'country', 'url',
'comments']
for customer in ds.get_all_entities('Customer'):
yield [customer['Name'], customer['FullName'], '', '', '', '', '', '']
def otrs_get_users_as_customers(ds):
yielded = False
type_priority = {
RelateType.SITE: 1,
RelateType.GROUP: 2,
RelateType.CONTRACT: 3,
RelateType.VENDOR: 4,
RelateType.CONTACT: 5,
RelateType.CUSTOMER: 6,
}
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
def _is_valid_customer(cus):
# if not cus['email']:
# return False
return True
for customer in ds.get_all_entities(
'Customer',
ims.CUSTOMER_PROPERTIES['CustomerRelatedContacts']):
if customer['CustomerRelatedContacts']:
customer_user = None
for contact in customer['CustomerRelatedContacts']:
# could just do this as an array, but this makes it easier to
# keep track of the fields
t_customer_user = OrderedDict({
'type': ims.RelateType(contact['MainTypeId']),
'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
'firstname': contact['Contact']['Name'],
'lastname': contact['Contact']['LastName'],
'phone': contact['Contact']['Phone'],
'fax': contact['Contact']['Fax'],
'mobile': contact['Contact']['Mobile'],
'street': '',
'zip': '',
'city': '',
'country': '',
'comments': ''
})
if not _is_valid_customer(t_customer_user):
continue
customer_user = _choose_customer_user(
t_customer_user,
customer_user
)
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)
if __name__ == '__main__':
import sys
username = sys.argv[1]
......
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