"""
    See LICENSE file for copyright and license details.
"""

"""
    A file with Lisa specific functions that can be used everywhere
"""

from modules.constant import NEGATIVES, TRADING_ACCOUNTS

def is_a_trading_account(account):
    """
        Check if the given account is a broker (used for trading).
    """
    return (account in TRADING_ACCOUNTS)
    
def is_negative_amount(account_from):
    """
        Check if the amount we enter should be positive or negative.
    """
    result = False
    # If asset in account_from
    for name in NEGATIVES:
        if name.lower() in account_from.lower():
            result = True
            break;
    return result

def deals_with_commodities(account_from, account_to = ''):
    """
        Check if 'commodities' is in the account name.
    """
    return ('commodities' in [account_from, account_to])

def is_a_table(key):
    """
        Used to ignore all dictionary entries that don't start with t_
    """
    return key.lower().startswith('t_')

def we_are_buying(account_from, account_to):
    """
        Are we buying? (not buying == selling)
    """
    #TODO: find a better way to do this
    buy = False
    sell = False
    if (not buy) and (not sell):
        for value in ['whsi00']:
            if (value.lower() in account_from):
                buy = True
                sell = False
            elif (value.lower() in account_to):
                buy = False
                sell = True
    return buy

def combine_sets(a_set):
    """
        Combine sets into a list.
        input: [{'test1', 'test2'}, {'test2'}]
        output: ['test1', 'test2']
    """
    combined = set()
    for item in a_set:
        combined = combined | item
    return list(combined)
    
def get_last_part(astring, aseparator):
    """
        Gets the last part of a <asaparator> seprated string.
    """
    partlist = astring.split(aseparator)
    return partlist[len(partlist) - 1]

@@ -509,16 +509,55 @@
   # 
-I
+Note: the below translates to:%0A    # i
 f 
+'
 asset
+'
  in 
@@ -612,19 +612,19 @@
 if name.
-low
+upp
 er() in 
@@ -636,19 +636,19 @@
 nt_from.
-low
+upp
 er():%0A  
@@ -797,27 +797,63 @@
  if 
-'commodities' is in
+we are using commoditie-related text in %0A        one of
  the
@@ -865,16 +865,17 @@
 unt name
+s
 .%0A    %22%22
@@ -887,18 +887,20 @@
  return 
+(
 ('
+:
 commodit
@@ -934,16 +934,69 @@
 unt_to%5D)
+ %5C%0A        or (':cfd' in %5Baccount_from, account_to%5D))
 %0A%0Adef is
@@ -1086,17 +1086,17 @@
 rt with 
-t
+T
 _%0A    %22%22
@@ -1112,19 +1112,19 @@
 urn key.
-low
+upp
 er().sta
@@ -1132,17 +1132,17 @@
 tswith('
-t
+T
 _')%0A%0Adef
@@ -1254,147 +1254,72 @@
     
-#TODO: find a better way to do this%0A    buy = False%0A    sell = False%0A    if (not buy) and (not sell):%0A        for value in %5B'whsi00'%5D:%0A    
+buy = False%0A    sell = False%0A    for value in TRADING_ACCOUNTS:%0A
     
@@ -1366,28 +1366,24 @@
             
-  
-  
 buy = True%0A 
@@ -1373,36 +1373,32 @@
      buy = True%0A
-    
             sell
@@ -1414,20 +1414,16 @@
         
-   
- 
 elif (va
@@ -1458,28 +1458,24 @@
             
-    
 buy = False%0A
@@ -1470,28 +1470,24 @@
 buy = False%0A
-    
             
@@ -1860,16 +1860,17 @@
 art of a
+n
  %3Casapar

Fix for deals_with_commodities + cleanup.