fix: Correctly infer Cash accounts using accountNameInferType.
This commit is contained in:
		
							parent
							
								
									4aa06d7920
								
							
						
					
					
						commit
						e17cd1540d
					
				| @ -99,16 +99,16 @@ revenueAccountRegex   = toRegexCI' "^(income|revenue)s?(:|$)" | ||||
| expenseAccountRegex   = toRegexCI' "^expenses?(:|$)" | ||||
| 
 | ||||
| -- | Try to guess an account's type from its name, | ||||
| -- matching common english top-level account names.  | ||||
| -- matching common English top-level account names. | ||||
| accountNameInferType :: AccountName -> Maybe AccountType | ||||
| accountNameInferType a | ||||
|   | regexMatchText cashAccountRegex      a = Just Cash | ||||
|   | regexMatchText assetAccountRegex     a = Just Asset | ||||
|   | a == "asset" || a == "assets"          = Just Asset | ||||
|   | regexMatchText assetAccountRegex     a = Just $ if regexMatchText cashAccountRegex a then Asset else Cash | ||||
|   | regexMatchText liabilityAccountRegex a = Just Liability | ||||
|   | regexMatchText equityAccountRegex    a = Just Equity | ||||
|   | regexMatchText revenueAccountRegex   a = Just Revenue | ||||
|   | regexMatchText expenseAccountRegex   a = Just Expense | ||||
|   | otherwise                          = Nothing | ||||
|   | otherwise                              = Nothing | ||||
| 
 | ||||
| accountNameLevel :: AccountName -> Int | ||||
| accountNameLevel "" = 0 | ||||
| @ -283,5 +283,15 @@ tests_AccountName = testGroup "AccountName" [ | ||||
|     "assets:bank" `isSubAccountNameOf` "assets" @?= True | ||||
|     "assets:bank:checking" `isSubAccountNameOf` "assets" @?= False | ||||
|     "assets:bank" `isSubAccountNameOf` "my assets" @?= False | ||||
|   ,testCase "accountNameInferType" $ do | ||||
|     accountNameInferType "assets"            @?= Just Asset | ||||
|     accountNameInferType "assets:cash"       @?= Just Cash | ||||
|     accountNameInferType "assets:A/R"        @?= Just Asset | ||||
|     accountNameInferType "liabilities"       @?= Just Liability | ||||
|     accountNameInferType "equity"            @?= Just Equity | ||||
|     accountNameInferType "expenses"          @?= Just Expense | ||||
|     accountNameInferType "revenues"          @?= Just Revenue | ||||
|     accountNameInferType "revenue"           @?= Just Revenue | ||||
|     accountNameInferType "income"            @?= Just Revenue | ||||
|  ] | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user