rechnung package


rechnung.cli module

rechnung.contract module

rechnung.contract.get_contracts(settings, year=None, month=None, cid_only=None, inactive=False)

Fetches all contracts from the settings.contracts_dir directory. Returns a dict with all active contracts, i.e. contracts with started in the past.


Renders all contracts as pdfs to settings.contracts_dir

rechnung.contract.send_contract(settings, cid)

Sends the contract specified with the cid via email to the customer.

If set, the policy and the product description of the main product will be attached.

rechnung.helpers module

rechnung.helpers.exit_on_miss(key, key_name, required_keys)

Checks existence of the given key in the given list. If the key is not found in the list, an error message is displayed, and the program is exited with exit code 1.

key: the key to be found key_name: a verbose name of the key, e.g. the variable name required_keys: the list where the key is to be found
rechnung.helpers.generate_email(settings, mail_to: str, mail_subject: str, mail_text: str, files=None)

Generate EmailMessage

settings mail_to: receiver mail address mail_subject: mail subject mail_text: mail text files (touple): list of file_path and file_name
rechnung.helpers.generate_pdf(html_data, css_data, path)

Takes rendered HTML template and filename and converts it to a PDF invoice using weasyprint.

rendered (str): Rendered invoice HTML invoice_path: Complete path where the invoice will be written to
rechnung.helpers.generate_yaml(object, filename)

Small wrapper around the yaml dump function.

object: Python object to be stored. filename: Filename of the yaml file.

Takes the path to the jinja2 template and returns a jinja2 Template instance with the contents of the file.

template_filename (str): full path to the template file (jinja2)
Template: jinja2 Template instance.
rechnung.helpers.read_with_default(prompt, default=None)

Prompts the user to enter some value. If a default value is given, the function will return that value, if the user presses enter, or enters only characters which are stripped by strip().


prompt: The prompt to be displayed to the user.

default: The default value to be returned if user enters nothing
default: None


str(): the default if set, empty string if not default and no input,
the input if something was entered.
rechnung.helpers.send_email(msg, server, username, password, insecure=True)

Sends the email.

msg (email.MIMEMultipart): The email to be sent.

rechnung.invoice module

exception rechnung.invoice.NoUnbilledItemsFound

Bases: Exception

rechnung.invoice.bill_cid_items(settings, contract, year, month)

Creates billed items for the given month and year.

rechnung.invoice.bill_items(settings, year, month, cid_only=None, dry=False)

Bill all products for all customers (or just one) i.e. mark them to be included in the next invoice to be created.

rechnung.invoice.create_billed_invoices(settings, suffix, cid_only=None, force=False)

Bulk creates invoice yaml files for the customer from the customers billed items.

rechnung.invoice.create_invoices(settings, year, month, cid_only=None, force=False)

Bulk creates invoice yaml files for a specific month-year-combination.

rechnung.invoice.fill_invoice_items(settings, items)

Calculates the items which will appear on the invoice, as well as the total_gross, total_net and total_vat value.

rechnung.invoice.generate_billed_invoice(settings, contract, suffix)

Creates an invoice from the already billed items, i.e. collects all unbilled items adds it to the invoice, and enters the invoice number into the billed items.

It returns the invoice dict.

rechnung.invoice.generate_invoice(settings, contract, year, month)

Creates an invoice, i.e. calls the fill_invoice_items function, to get all the numbers right, as well as filling all the remaining required meta information about the customer.

It returns the invoice dict.

rechnung.invoice.get_billed_items(settings, cid)

Returns the billed_items for the given cid.

If there are no billed items yet, an empty list is returned.


Generator which iterates over all contract directories and included invoice yamls, yields contract_invoice_dir and filename.


Renders all invoices and saves pdfs to settings.invoices_dir.

rechnung.invoice.save_billed_items_yaml(settings, billed_items, cid)

Saves the billed items to the billed items file of the customer

rechnung.invoice.save_invoice_yaml(settings, invoice_data, force=False)

Saves the invoice_data to a yaml file in settings.invoices_dir.

rechnung.invoice.send_invoices(settings, year, month, cid_only, force, suffix=None)

Sends emails with the invoices as attachment.

For backwards compatibility: year and month are ignored, if suffix is given!

rechnung.settings module

exception rechnung.settings.RequiredSettingMissingError

Bases: Exception

If a setting is missing, but required to be set in the settings.yaml, this exception is thrown.

class rechnung.settings.Settings(company_name, company_address, company_bank, contract_mail_subject, insecure, locale, password, sender, server, username, vat, invoice_mail_subject, assets_dir, contract_css_asset_file, contract_mail_template_file, contract_template_file, contracts_dir, csv_dir, delivery_date_format, invoice_css_asset_file, invoice_mail_template_file, invoice_template_file, invoices_dir, logo_asset_file, policy_attachment_asset_file, billed_items_dir, arrow_locale)

Bases: tuple


Alias for field number 26


Alias for field number 12


Alias for field number 25


Alias for field number 1


Alias for field number 2


Alias for field number 0


Alias for field number 13


Alias for field number 3


Alias for field number 14


Alias for field number 15


Alias for field number 16


Alias for field number 17


Alias for field number 18


Alias for field number 4


Alias for field number 19


Alias for field number 11


Alias for field number 20


Alias for field number 21


Alias for field number 22


Alias for field number 5


Alias for field number 23


Alias for field number 6


Alias for field number 24


Alias for field number 7


Alias for field number 8


Alias for field number 9


Alias for field number 10

exception rechnung.settings.UnknownSettingError

Bases: Exception

If a setting is found in the settings.yaml file which is unknown to rechnung, this exception is thrown.

rechnung.settings.copy_assets(target_dir, orig_dir=PosixPath('/home/docs/checkouts/'))

Copy the original assets, which are shipped with the tool, from the original directory (where the tool is installed) to the cwd (where the data is stored).

rechnung.settings.create_required_settings_file(cwd, settings_file='settings.yaml')

Creates a settings file with all required settings listed, to be filled by the user accordingly.

rechnung.settings.get_settings_from_cwd(cwd, create_non_existing_dirs=False, settings_file='settings.yaml')

Wrapper for get_settings_from_file to allow for easier exchange later.

rechnung.settings.get_settings_from_file(settings_path, error_on_unknown=True, prepend_base_path=True, create_non_existing_dirs=False)

Opens a settings.yaml and returns its contents as a namedtuple “Settings”. It checks if all required settings are found in the settings file, as well if there are any unknown settings given. Finally the base_path is prepended to all settings ending with “_file” or “_dir”.

rechnung.transactions module


Parses CSV files from the GLS bank

rechnung.transactions.read_csv_files(settings, year, month)

Parses CSV files of a specific year/month combo

Module contents