Skip to content

Commit e2968e2

Browse files
authored
Merge pull request #42 from westnetz/feature/docstrings
added docstrings
2 parents 9d66749 + 5f634ca commit e2968e2

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

rechnung/contract.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99

1010
def get_contracts(settings, year=None, month=None, cid_only=None, inactive=False):
11+
"""
12+
Fetches all contracts from the settings.contracts_dir directory.
13+
Returns a dict with all active contracts, i.e. contracts with started
14+
in the past.
15+
"""
1116
contracts = OrderedDict()
1217
for filename in settings.contracts_dir.glob("*.yaml"):
1318
if cid_only and cid_only != filename.stem:
@@ -28,6 +33,9 @@ def get_contracts(settings, year=None, month=None, cid_only=None, inactive=False
2833

2934

3035
def render_contracts(settings):
36+
"""
37+
Renders all contracts as pdfs to settings.contracts_dir
38+
"""
3139
template = get_template(settings.contract_template_file)
3240
logo_path = settings.assets_dir / "logo.png"
3341

@@ -60,6 +68,12 @@ def render_contracts(settings):
6068

6169

6270
def send_contract(settings, cid):
71+
"""
72+
Sends the contract specified with the cid via email to the customer.
73+
74+
If set, the policy and the product description of the main product
75+
will be attached.
76+
"""
6377
mail_template = get_template(settings.contract_mail_template_file)
6478
contract_pdf_path = Path(settings.contracts_dir) / f"{cid}.pdf"
6579
contract_yaml_filename = Path(settings.contracts_dir) / f"{cid}.yaml"

rechnung/invoice.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88

99
def fill_invoice_items(settings, items):
10+
"""
11+
Calculates the items which will appear on the invoice, as well as the total_gross,
12+
total_net and total_vat value.
13+
"""
1014
invoice_total_net = float()
1115
invoice_total_vat = float()
1216
invoice_total_gross = float()
@@ -36,6 +40,13 @@ def fill_invoice_items(settings, items):
3640

3741

3842
def generate_invoice(settings, contract, year, month):
43+
"""
44+
Creates an invoice, i.e. calls the fill_invoice_items function, to get
45+
all the numbers right, as well as filling all the remaining required meta
46+
information about the customer.
47+
48+
It returns the invoice dict.
49+
"""
3950
invoice_items, net, vat, gross = fill_invoice_items(settings, contract["items"])
4051

4152
invoice_data = {}
@@ -68,6 +79,9 @@ def iterate_invoices(settings):
6879

6980

7081
def render_invoices(settings):
82+
"""
83+
Renders all invoices and saves pdfs to settings.invoices_dir.
84+
"""
7185
template = get_template(settings.invoice_template_file)
7286

7387
for contract_invoice_dir, filename in iterate_invoices(settings):
@@ -98,6 +112,9 @@ def render_invoices(settings):
98112

99113

100114
def save_invoice_yaml(settings, invoice_data, force=False):
115+
"""
116+
Saves the invoice_data to a yaml file in settings.invoices_dir.
117+
"""
101118
invoice_contract_dir = settings.invoices_dir / invoice_data["cid"]
102119

103120
if not invoice_contract_dir.is_dir():
@@ -112,6 +129,9 @@ def save_invoice_yaml(settings, invoice_data, force=False):
112129

113130

114131
def create_invoices(settings, year, month, cid_only=None, force=False):
132+
"""
133+
Bulk creates invoice yaml files for a specific month-year-combination.
134+
"""
115135
if force:
116136
print("Force create enabled")
117137

@@ -126,6 +146,9 @@ def create_invoices(settings, year, month, cid_only=None, force=False):
126146

127147

128148
def send_invoices(settings, year, month, cid_only, force):
149+
"""
150+
Sends emails with the invoices as attachment.
151+
"""
129152
mail_template = get_template(settings.invoice_mail_template_file)
130153

131154
if force:

rechnung/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@
5252

5353

5454
class UnknownSettingError(Exception):
55+
"""
56+
If a setting is found in the settings.yaml file which is unknown to rechnung, this exception is thrown.
57+
"""
58+
5559
pass
5660

5761

5862
class RequiredSettingMissingError(Exception):
63+
"""
64+
If a setting is missing, but required to be set in the settings.yaml, this exception is thrown.
65+
"""
66+
5967
pass
6068

6169

rechnung/tests/test_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ def test_invoice_create_cid_only(cli_test_data_path):
153153
cli1, path = cli_test_data_path
154154
s = settings.get_settings_from_cwd(path)
155155
runner = CliRunner()
156-
result = runner.invoke(cli1, ["create-invoices", "2019", "10", "--cid-only=1000",
157-
"--force-recreate"])
156+
result = runner.invoke(
157+
cli1, ["create-invoices", "2019", "10", "--cid-only=1000", "--force-recreate"]
158+
)
158159
assert "1002" not in result.output
159160
assert "already exists" not in result.output
160161

0 commit comments

Comments
 (0)