aeat.application.review._edit module

Typed --set KEY=VALUE parser for record-edit commands.

The CLI exposes --set KEY=VALUE on ledger / invoice review-edit commands. The canonical grammar:

  • ledger: --set category=software, --set business.share=1.0, --set reference=invoice-1, --set comments=…, --set document.path=…

  • invoice: --set base=120.00, --set iva.rate=21, --set iva.amount=25.20, --set iva.category=…, --set retention.rate=15, --set retention.amount=18.00, --set payment.id=row_…, --set reference=…, --set comments=…, --set document.path=…

The CLI argv layer parses the raw strings; this module turns them into typed EditClause records and binds them to per-scope LedgerEditSpec / InvoiceEditSpec records. Each spec validates its closed key catalogue, coerces each value to its typed shape (Decimal, Path, free text, foreign-key id), and exposes typed accessors the orchestration layer reads instead of re-parsing strings at every edit-application call site.

The orchestration that applies an EditSpec to a stored aeat.domain.transactions.Transaction / aeat.domain.invoices.Invoice / aeat.domain.filing.ModeloDraft lives in the application/workflow state overlay.

class EditClause(**data)[source]

Bases: BaseModel

One typed KEY=VALUE clause from a --set flag.

The raw_value is the trimmed string before per-key coercion; typed coercion happens on the owning scope’s spec.

Variables:
  • key – Lowercase, dotted-or-flat identifier.

  • raw_value – Trimmed value string.

Parameters:
key: str
raw_value: str
parse_edit_clause(raw)[source]

Parse one raw KEY=VALUE string into an EditClause.

Parameters:

raw (str) – The raw KEY=VALUE token supplied by the operator.

Return type:

EditClause

Returns:

A validated EditClause with the parsed key and value.

Raises:

EditParseError – When the token is missing =, has an empty key, or has an empty value.

parse_edit_clauses(raw)[source]

Parse a sequence of --set strings into EditClause records, preserving input order.

Return type:

tuple[EditClause, ...]

Parameters:

raw (Iterable[str])

class LedgerEditKey(*values)[source]

Bases: StrEnum

Closed catalogue of aeat app ledger update --set keys.

Variables:
  • CATEGORY – Spending / income category foreign-key id.

  • BUSINESS_SHARE – Decimal share in [0, 1] of the row that is business-related (mixed-use accounting).

  • REFERENCE – Free-text user reference (invoice number, ticket id, contract id).

  • COMMENTS – Free-text operator note.

  • DOCUMENT_PATH – Filesystem path to a supporting document.

CATEGORY
TREATMENT
BUSINESS_SHARE
REFERENCE
COMMENTS
DOCUMENT_PATH
class InvoiceEditKey(*values)[source]

Bases: StrEnum

Closed catalogue of invoice-evidence edit keys.

Variables:
  • BASE – Decimal taxable base amount.

  • IVA_RATE – Decimal IVA percentage (21 / 10 / 4 / 0 are the supported rates; the parser accepts any non-negative decimal so the grammar is not tied to a fixed rate table).

  • IVA_AMOUNT – Decimal IVA amount.

  • IVA_CATEGORY – Free-text IVA category.

  • RETENTION_RATE – Decimal IRPF retention percentage.

  • RETENTION_AMOUNT – Decimal IRPF retention amount.

  • PAYMENT_ID – Foreign-key transaction id linked as the payment.

  • REFERENCE – Free-text invoice reference.

  • COMMENTS – Free-text operator note.

  • DOCUMENT_PATH – Filesystem path to the invoice file.

BASE
IVA_RATE
IVA_AMOUNT
IVA_CATEGORY
RETENTION_RATE
RETENTION_AMOUNT
PAYMENT_ID
REFERENCE
COMMENTS
DOCUMENT_PATH
class LedgerEditSpec(**data)[source]

Bases: BaseModel

Typed aeat app ledger update --set spec.

Variables:
  • clauses – Raw clauses in input order.

  • category – Resolved spending / income category id.

  • business_share – Resolved business share (0..1).

  • reference – Resolved free-text reference.

  • comments – Resolved free-text comments.

  • document_path – Resolved supporting-document path.

Parameters:
clauses: tuple[EditClause, ...]
category: str | None
business_share: Decimal | None
reference: str | None
comments: str | None
document_path: Path | None
classmethod from_strings(raw)[source]

Parse --set arguments into a typed ledger spec.

Returns a LedgerEditSpec with fields populated from the parsed key=value clause strings.

Return type:

LedgerEditSpec

Parameters:

raw (Iterable[str])

class InvoiceEditSpec(**data)[source]

Bases: BaseModel

Typed invoice-evidence edit spec.

Variables:
  • clauses – Raw clauses in input order.

  • base – Decimal taxable base.

  • iva_rate – Decimal IVA percentage.

  • iva_amount – Decimal IVA amount.

  • iva_category – Free-text IVA category.

  • retention_rate – Decimal IRPF retention percentage.

  • retention_amount – Decimal IRPF retention amount.

  • payment_id – Foreign-key transaction id.

  • reference – Free-text invoice reference.

  • comments – Free-text operator note.

  • document_path – Path to the invoice file.

Parameters:
clauses: tuple[EditClause, ...]
base: Decimal | None
iva_rate: Decimal | None
iva_amount: Decimal | None
iva_category: str | None
retention_rate: Decimal | None
retention_amount: Decimal | None
payment_id: str | None
reference: str | None
comments: str | None
document_path: Path | None
classmethod from_strings(raw)[source]

Parse --set arguments into a typed InvoiceEditSpec.

Return type:

InvoiceEditSpec

Parameters:

raw (Iterable[str])