Skip to content

Commit

Permalink
Add slip option for tax-slip command to select one slip type
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 committed Apr 16, 2023
1 parent 9adfe09 commit 37ee6f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/SwiftBeanCountCLILibrary/SubCommands/TaxSlips.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ struct TaxSlips: FormattableLedgerCommand {
var ledgerOptions: LedgerCommandOptions
@Argument(help: "Tax year to generate slips for.")
var year = Calendar.current.component(.year, from: Date()) - 1
@ArgumentParser.Option(help: "Tax slip to generate - if not specified, all will be generated")
var slip: String?
@OptionGroup()
var formatOptions: FormattableCommandOptions
@OptionGroup()
var colorOptions: ColorizedCommandOptions

func getResult(from ledger: Ledger, parsingDuration: Double) throws -> [FormattableResult] {
try TaxCalculator.generateTaxSlips(from: ledger, for: year).map { slip -> FormattableResult in
try TaxCalculator.generateTaxSlips(from: ledger, for: year).filter { slip != nil ? $0.name.lowercased() == slip!.lowercased() : true }.map { slip in
var values: [[String]] = slip.rows.map {
slip.symbols.isEmpty ? $0.values.map { $0.displayValue } : [$0.symbol!, $0.name!] + $0.values.map { $0.displayValue }
}
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftBeanCountCLILibraryTests/SubCommands/TaxSlipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ class TaxSlipTests: XCTestCase {
""")
}

func testSlipArgument() {
let url = temporaryFileURL()
createFile(at: url, content: """
2020-06-13 custom "tax-slip-settings" "slip-names" "t5"
2020-06-13 custom "tax-slip-settings" "slip-currency" "t4" "CAD"
2020-06-13 custom "tax-slip-settings" "slip-currency" "t5" "CAD"
2020-06-13 open Income:Work
t4: "Box 1"
2020-06-13 open Income:Bank
t5: "Box 1"
2020-06-13 open Assets:Bank
2020-06-13 * "" ""
Income:Work -10.00 CAD
Assets:Bank 10.00 CAD
2020-06-13 * "" ""
Income:Bank -15.00 CAD
Assets:Bank 15.00 CAD
""")
assertSuccessfulExecutionResult(arguments: ["tax-slips", url.path, "2020", "--format", "text", "--slip", "t5"], output: """
Tax Slip T5 - Tax year 2020
Box 1
15.00 CAD
""")
}

func testSlipSymbol() {
let url = temporaryFileURL()
createFile(at: url, content: """
Expand Down

0 comments on commit 37ee6f3

Please sign in to comment.