aoiro package

class aoiro.GeneralLedgerLine(*args, **kwargs)[source]

Bases: _LedgerLineBase, Protocol[Account, Currency]

values: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts. Amounts does not need to be non-negative.

class aoiro.GeneralLedgerLineImpl(*, date: Timestamp, values: Sequence[LedgerElement[Account, Currency]])[source]

Bases: GeneralLedgerLine[Account, Currency]

date: Timestamp

The date when the transaction occurred.

values: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts. Amounts does not need to be non-negative.

class aoiro.LedgerElement(*args, **kwargs)[source]

Bases: Protocol[Account, Currency]

account: Account

The account.

amount: Decimal

The amount.

currency: Currency

The currency.

class aoiro.LedgerElementImpl(*, account: Account, amount: Decimal, currency: Currency)[source]

Bases: LedgerElement[Account, Currency]

account: Account

The account.

amount: Decimal

The amount.

currency: Currency

The currency.

class aoiro.LedgerLine(*args, **kwargs)[source]

Bases: _LedgerLineBase, Protocol[Account, Currency]

amount: Decimal

The amount. Must be non-negative.

credit_account: Account

The account written on the credit side.

currency: Currency

The currency.

debit_account: Account

The account written on the debit side.

class aoiro.LedgerLineImpl(*, date: Timestamp, amount: Decimal, currency: Currency, debit_account: Account, credit_account: Account)[source]

Bases: LedgerLine[Account, Currency]

amount: Decimal

The amount. Must be non-negative.

credit_account: Account

The account written on the credit side.

currency: Currency

The currency.

date: Timestamp

The date when the transaction occurred.

debit_account: Account

The account written on the debit side.

class aoiro.MultiLedgerLine(*args, **kwargs)[source]

Bases: _LedgerLineBase, Protocol[Account, Currency]

credit: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts on the credit side. Each amount needs to be non-negative.

debit: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts on the debit side. Each amount needs to be non-negative.

class aoiro.MultiLedgerLineImpl(*, date: Timestamp, debit: Sequence[LedgerElement[Account, Currency]], credit: Sequence[LedgerElement[Account, Currency]])[source]

Bases: MultiLedgerLine[Account, Currency]

credit: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts on the credit side. Each amount needs to be non-negative.

date: Timestamp

The date when the transaction occurred.

debit: Sequence[LedgerElement[Account, Currency]]

The accounts and amounts on the debit side. Each amount needs to be non-negative.

aoiro.generalledger_line_to_multiledger_line(line: GeneralLedgerLine, is_debit: Callable[[Account], bool], /) MultiLedgerLine[source]

Convert a GeneralLedgerLine to a MultiLedgerLine.

Parameters:
  • line (GeneralLedgerLine[Account, Currency]) – The GeneralLedgerLine to convert.

  • is_debit (Callable[[Account], bool]) – Whether the account is a debit account.

Returns:

The converted MultiLedgerLine.

Return type:

MultiLedgerLine[Account, Currency]

aoiro.generalledger_to_multiledger(lines: Sequence[GeneralLedgerLine], is_debit: Callable[[Account], bool]) Sequence[MultiLedgerLine][source]

Convert a GeneralLedger to a MultiLedger.

Parameters:
  • lines (Sequence[GeneralLedgerLine[Account, Currency]]) – The GeneralLedger to convert.

  • is_debit (Callable[[Account], bool]) – Whether the account is a debit account.

Returns:

The converted MultiLedger.

Return type:

Sequence[MultiLedgerLine[Account, Currency]]

aoiro.get_sheets(lines: Sequence[GeneralLedgerLine[Account, Currency]], G: DiGraph, *, drop: bool = True) DiGraph[source]

Get the blue return accounts as a graph.

Returns:

Tree representation of the blue return account list. Has the following attributes:

sum: dict[Currency, Decimal]

The sum of the children for each currency, with alternating signs for each AccountType.

sum_natural: dict[Currency, Decimal]

The sum of the children for each currency. For accounts with AccountType well-defined, the sum is not altered. For accounts with AccountType None, the value is the same as sum.

Return type:

nx.DiGraph

aoiro.ledger_from_expenses(path: Path) Sequence[GeneralLedgerLineImpl[Any, Any]][source]

Generate ledger from expenses.

The CSV files are assumed to have columns [“勘定科目”]. The relative path of the CSV file would be used as “取引先”.

Parameters:

path (Path) – The path to the directory containing CSV files.

Returns:

The ledger lines.

Return type:

Sequence[GeneralLedgerLineImpl[Any, Any]]

aoiro.ledger_from_sales(path: Path, G: DiGraph | None = None) Sequence[GeneralLedgerLineImpl[Any, Any]][source]

Generate ledger from sales.

The CSV files are assumed to have columns [“発生日”, “金額”, “振込日”, “源泉徴収”, “手数料”]. If “源泉徴収” is True, the amount would be assumed by withholding_tax(). If “源泉徴収” if False or NaN, the amount would be assumed as 0. If “源泉徴収” is numeric, the amount would be assumed as 源泉徴収額. The relative path of the CSV file would be used as “取引先”.

Parameters:
  • path (Path) – The path to the directory containing CSV files.

  • G (nx.DiGraph | None) – The graph of accounts, by default None. If provided, each “取引先” would be added as a child node of “売上”.

Returns:

The ledger lines.

Return type:

Sequence[GneralLedgerLineImpl[Any, Any]]

Raises:
  • ValueError – If the transaction date is later than the transfer date.

  • ValueError – If withholding tax is included in transactions with different currencies.

aoiro.multidimensional_ledger_to_ledger(lines: Sequence[GeneralLedgerLine[Account, Currency]], is_debit: Callable[[Account], bool], prices: Mapping[Currency, pd.Series[Decimal]] = {}) Sequence[GeneralLedgerLineImpl[Account | Literal['為替差益', '為替差損'], Literal['']]][source]

Convert multidimensional ledger to ledger.

The multidimensional ledger’s any account must have positive amount. At the BOY, the previous B/S sheet must be added as a general ledger line, for example,

>>> from datetime import datetime
>>> lines = []
>>> lines.append(
...    GeneralLedgerLineImpl(
...        date=datetime(2024, 1, 1),
...        values=[
...            ("売掛金", 1000, ""),
...            ("元入金", 1000, "")
...         ]
...     )
... )
Returns:

The ledger lines.

Return type:

GeneralLedgerLineImpl[Account | Literal[“為替差益”, “為替差損”], Literal[“”]]

aoiro.multiledger_line_to_generalledger_line(line: MultiLedgerLine, /) GeneralLedgerLine[source]

Convert a MultiLedgerLine to a GeneralLedgerLine.

Parameters:

line (MultiLedgerLine[Account, Currency]) – The MultiLedgerLine to convert.

Returns:

The converted GeneralLedgerLine.

Return type:

GeneralLedgerLine[Account, Currency]

aoiro.multiledger_line_to_ledger_line(line: MultiLedgerLine, /) Sequence[LedgerLine[Account | Literal['諸口'], Currency]][source]

Convert a MultiLedgerLine to a list of LedgerLine.

Parameters:

line (MultiLedgerLine[Account, Currency]) – The MultiLedgerLine to convert.

Returns:

The converted LedgerLines.

Return type:

Sequence[LedgerLine[Account | AccountSundry, Currency]]

aoiro.multiledger_to_generalledger(lines: Sequence[MultiLedgerLine]) Sequence[GeneralLedgerLine][source]

Convert a MultiLedger to a GeneralLedger.

Parameters:

lines (Sequence[MultiLedgerLine[Account, Currency]]) – The MultiLedger to convert.

Returns:

The converted GeneralLedger.

Return type:

Sequence[GeneralLedgerLine[Account, Currency]]

aoiro.multiledger_to_ledger(lines: Sequence[MultiLedgerLine]) Sequence[LedgerLine[Account | Literal['諸口'], Currency]][source]

Convert a MultiLedger to a Ledger.

Parameters:

lines (Sequence[MultiLedgerLine[Account, Currency]]) – The MultiLedger to convert.

Returns:

The converted Ledger.

Return type:

Sequence[LedgerLine[Account | AccountSundry, Currency]]

aoiro.read_all_csvs(path: Path, /, **kwargs: Any) DataFrame[source]

Read all CSV files in the path.

Parameters:
  • path (Path) – The path to the directory containing CSV files.

  • **kwargs (Any) – The keyword arguments for pd.read_csv.

Returns:

The concatenated DataFrame with column “path” containing the relative path of the CSV file added.

Return type:

pd.DataFrame

aoiro.read_general_ledger(path: Path) Iterable[GeneralLedgerLineImpl[Any, Any]][source]

Read general ledger.

The first column is assumed to be the date. For all n in N. the 2n-1-th column is assumed to be the account name, and the 2n-th column is assumed to be the amount.

Parameters:

path (Path) – The path to the CSV file.

Returns:

The general ledger.

Return type:

Iterable[GeneralLedgerLineImpl[Any, Any]]

aoiro.read_simple_csvs(path: Path) DataFrame[source]

Read all CSV files in the path.

The CSV files are assumed to have columns [“発生日”, “金額”].

Parameters:

path (Path) – The path to the directory containing CSV files.

Returns:

The concatenated DataFrame with columns [“発生日”, “金額”, “通貨”, “path”].

Return type:

pd.DataFrame

aoiro.withholding_tax(amount: Decimal) Decimal[source]

Withholding tax calculation for most 源泉徴収が必要な報酬・料金等.

Parameters:

amount (Decimal) – The raw amount.

Returns:

The withholding tax amount.

Return type:

Decimal

References

https://www.nta.go.jp/taxes/shiraberu/taxanswer/gensen/2792.htm

Subpackages

Submodules

aoiro.cli module

aoiro.cli.metrics(path: Path, years: str | None = None, months: str | None = None, drop: bool = True) int[source]

Calculate metrics needed for tax declaration.

Parameters:
  • path (Path) – The path to the directory containing CSV files.

  • years (str | None, optional) – The year to calculate, by default None. If None, the previous year would be used.

  • months (str | None, optional) – The months to calculate, by default None.

  • drop (bool, optional) – Whether to drop unused accounts, by default True.