cli: --pivot payee/note uses description parts before/after |
This assumes a "PAYEE | NOTE" convention in the description field, similar to Beancount's journal syntax. If the description has no pipe character, payee and note are the same as the full description.
This commit is contained in:
		
							parent
							
								
									80827321c4
								
							
						
					
					
						commit
						2e61c037c3
					
				| @ -44,6 +44,10 @@ module Hledger.Data.Posting ( | ||||
|   concatAccountNames, | ||||
|   accountNameApplyAliases, | ||||
|   accountNameApplyAliasesMemo, | ||||
|   -- * transaction description operations | ||||
|   transactionPayee, | ||||
|   transactionNote, | ||||
|   payeeAndNoteFromDescription, | ||||
|   -- * arithmetic | ||||
|   sumPostings, | ||||
|   -- * rendering | ||||
| @ -173,9 +177,25 @@ postingStatus Posting{pstatus=s, ptransaction=mt} | ||||
| transactionImplicitTags :: Transaction -> [Tag] | ||||
| transactionImplicitTags t = filter (not . T.null . snd) [("code", tcode t) | ||||
|                                                         ,("description", tdescription t) | ||||
|                                                         ,("payee", tdescription t) | ||||
|                                                         ,("payee", transactionPayee t) | ||||
|                                                         ,("note", transactionNote t) | ||||
|                                                         ] | ||||
| 
 | ||||
| transactionPayee :: Transaction -> Text | ||||
| transactionPayee = fst . payeeAndNoteFromDescription . tdescription | ||||
| 
 | ||||
| transactionNote :: Transaction -> Text | ||||
| transactionNote = fst . payeeAndNoteFromDescription . tdescription | ||||
| 
 | ||||
| -- | Parse a transaction's description into payee and note (aka narration) fields, | ||||
| -- assuming a convention of separating these with | (like Beancount). | ||||
| -- Ie, everything up to the first | is the payee, everything after it is the note. | ||||
| -- When there's no |, payee == note == description. | ||||
| payeeAndNoteFromDescription :: Text -> (Text,Text) | ||||
| payeeAndNoteFromDescription t = (textstrip p, textstrip $ T.tail n) | ||||
|   where | ||||
|     (p,n) = T.breakOn "|" t | ||||
| 
 | ||||
| -- | Tags for this posting including implicit and any inherited from its parent transaction. | ||||
| postingAllImplicitTags :: Posting -> [Tag] | ||||
| postingAllImplicitTags p = ptags p ++ maybe [] transactionTags (ptransaction p) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user