rechu.command.new package¶
Submodules¶
rechu.command.new.input module¶
Input source for new subcommand.
- class rechu.command.new.input.InputSource[source]¶
Bases:
object
Abstract base class for a typed input source.
- get_completion(text: str, state: int) str | None [source]¶
Retrieve a completion option for the current suggestions and text state. The text is a partial input that matches some part of the suggestions and state indicates the position of the suggestion in the sorted list of matching suggestions to choose.
If there is no match found or if the input source does not support completion suggestions, then None is returned.
- get_date(default: datetime | None = None) datetime [source]¶
Retrieve a date input. The default may be used as a fallback if nothing is input or if a partial timestamp is provided.
- get_input(name: str, input_type: type[InputT], options: str | None = None, default: InputT | None = None) InputT [source]¶
Retrieve an input cast to a certain type (string, integer or float). Optionally, the input source provides suggestions from a predefined completion source defined by the options name and may fall back to a default if nothing is input.
- class rechu.command.new.input.Prompt[source]¶
Bases:
InputSource
Standard input prompt.
- display_matches(substitution: str, matches: Sequence[str], longest_match_length: int) None [source]¶
Write a display of matches to the standard output compatible with readline buffers.
- get_completion(text: str, state: int) str | None [source]¶
Retrieve a completion option for the current suggestions and text state. The text is a partial input that matches some part of the suggestions and state indicates the position of the suggestion in the sorted list of matching suggestions to choose.
If there is no match found or if the input source does not support completion suggestions, then None is returned.
- get_date(default: datetime | None = None) datetime [source]¶
Retrieve a date input. The default may be used as a fallback if nothing is input or if a partial timestamp is provided.
rechu.command.new.step module¶
Steps for creating a receipt in new subcommand.
- class rechu.command.new.step.Discounts(receipt: Receipt, input_source: InputSource, matcher: ProductMatcher)[source]¶
Bases:
Step
Step to add discounts.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Edit(receipt: Receipt, input_source: InputSource, editor: str | None = None)[source]¶
Bases:
Step
Step to edit the receipt in its YAML representation via a temporary file.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Help(receipt: Receipt, input_source: InputSource)[source]¶
Bases:
Step
Step to display help for steps that are usable from the menu.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.ProductMeta(receipt: Receipt, input_source: InputSource, matcher: ProductMatcher, products: set[Product])[source]¶
Bases:
Step
Step to add product metadata that matches one or more products.
- MATCHERS: dict[str, _Matcher] = {'discount': {'key': 'label', 'model': <class 'rechu.models.product.DiscountMatch'>, 'options': 'discounts'}, 'label': {'key': 'name', 'model': <class 'rechu.models.product.LabelMatch'>, 'options': 'products'}, 'price': {'extra_key': 'indicator', 'input_type': <class 'rechu.types.quantized.Price'>, 'key': 'value', 'model': <class 'rechu.models.product.PriceMatch'>, 'options': 'prices'}}¶
- add_product(item: ProductItem | None = None, initial_key: str | None = None, matched_items: set[ProductItem] | None = None) tuple[bool, str | None] [source]¶
Request fields for a product’s metadata and add it to the database as well as a products YAML file. item is an optional product item from the receipt to specifically match the metadata for. initial_key is a metadata key to use for the first prompt. Returns whether to no longer attempt to create product metadata and the current prompt answer.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Products(receipt: Receipt, input_source: InputSource, matcher: ProductMatcher, products: set[Product])[source]¶
Bases:
Step
Step to add products.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Quit(receipt: Receipt, input_source: InputSource)[source]¶
Bases:
Step
Step to exit the receipt creation menu.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Read(receipt: Receipt, input_source: InputSource, matcher: ProductMatcher)[source]¶
Bases:
Step
Step to check if there are any new or updated product metadata entries in the file inventory that should be synchronized with the database inventory before creating and matching receipt products.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.ResultMeta[source]¶
Bases:
TypedDict
Result of a step being run, indicator additional metadata to update.
‘receipt_path’: Boolean indicating pdate the path of the receipt based on receipt metadata.
- exception rechu.command.new.step.ReturnToMenu(msg: str = '')[source]¶
Bases:
RuntimeError
Indication that the step is interrupted to return to a menu.
- class rechu.command.new.step.Step(receipt: Receipt, input_source: InputSource)[source]¶
Bases:
object
Abstract base class for a step during receipt creation.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.View(receipt: Receipt, input_source: InputSource, products: set[Product] | None = None)[source]¶
Bases:
Step
Step to display the receipt in its YAML representation.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
- class rechu.command.new.step.Write(receipt: Receipt, input_source: InputSource, matcher: ProductMatcher, products: set[Product] | None = None)[source]¶
Bases:
Step
Final step to write the receipt to a YAML file and store in the database.
- run() ResultMeta [source]¶
Perform the step. Returns whether there is additional metadata which needs to be updated outside of the step.
Module contents¶
Subcommand to create a new receipt YAML file and import it.
- class rechu.command.new.New[source]¶
Bases:
Base
Create a YAML file for a receipt and import it to the database.
- subparser_arguments: SubparserArguments = [(('-c', '--confirm'), {'action': 'store_true', 'default': False, 'help': 'Confirm before updating database files or exiting'})]¶
- subparser_keywords: SubparserKeywords = {'description': 'Interactively fill in a YAML file for a receipt and import it to the database.', 'help': 'Create receipt file and import'}¶