rechnung package

Submodules

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.

rechnung.contract.render_contracts(settings)

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.

Args:
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

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

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

Args:
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.

Args:
object: Python object to be stored. filename: Filename of the yaml file.
rechnung.helpers.get_template(template_filename)

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

Args:
template_filename (str): full path to the template file (jinja2)
Returns:
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().

Args:

prompt: The prompt to be displayed to the user.

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

Returns:

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.

Args:
msg (email.MIMEMultipart): The email to be sent.
rechnung.helpers.str2bool(var)

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.

rechnung.invoice.get_period_from_item_keys(item_keys)
rechnung.invoice.iterate_invoices(settings)

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

rechnung.invoice.render_invoices(settings)

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

arrow_locale

Alias for field number 26

assets_dir

Alias for field number 12

billed_items_dir

Alias for field number 25

company_address

Alias for field number 1

company_bank

Alias for field number 2

company_name

Alias for field number 0

contract_css_asset_file

Alias for field number 13

contract_mail_subject

Alias for field number 3

contract_mail_template_file

Alias for field number 14

contract_template_file

Alias for field number 15

contracts_dir

Alias for field number 16

csv_dir

Alias for field number 17

delivery_date_format

Alias for field number 18

insecure

Alias for field number 4

invoice_css_asset_file

Alias for field number 19

invoice_mail_subject

Alias for field number 11

invoice_mail_template_file

Alias for field number 20

invoice_template_file

Alias for field number 21

invoices_dir

Alias for field number 22

locale

Alias for field number 5

logo_asset_file

Alias for field number 23

password

Alias for field number 6

policy_attachment_asset_file

Alias for field number 24

sender

Alias for field number 7

server

Alias for field number 8

username

Alias for field number 9

vat

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/readthedocs.org/user_builds/rechnung/envs/latest/lib/python3.7/site-packages/rechnung-0.1-py3.7.egg/rechnung/orig'))

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

rechnung.transactions.parser_gls(csv_path)

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