Compare commits

...

2 commits

2 changed files with 25 additions and 2 deletions

View file

@ -8,7 +8,7 @@ Wir berechnen dir daher die folgenden Mitgliedsbeiträge:
Wir werden dir daher die folgenden Mitgliedsbeiträge berechnen:
{%- endif %}
{% for line in invoice.lines %}
{{ line.description.ljust(39) }} {{ (line.quantity|format_quantity).rjust(5) }} × {{ (line.unit_price|format_currency(currency=line.currency.code)).rjust(9) }} = {{ (line.amount|format_currency(currency=line.currency.code)).rjust(12) }}
{% if line.description %}{{ line.description.ljust(39) }}{% elif line.product %}{{ line.product.name.ljust(39) }}{% else %}{{ " ".ljust(39) }}{% endif %} {{ (line.quantity|format_quantity).rjust(5) }} × {{ (line.unit_price|format_currency(currency=line.currency.code)).rjust(9) }} = {{ (line.amount|format_currency(currency=line.currency.code)).rjust(12) }}
{%- endfor %}
{{ "".ljust(72, '-') }}
{{ "Summe".ljust(59) }} {{ (invoice.total_amount|format_currency).rjust(12) }}

View file

@ -11,6 +11,7 @@ import operator
import pathlib
import subprocess
import tempfile
import tomllib
import babel.numbers
import dateutil.relativedelta
@ -68,7 +69,10 @@ def fee_invoice(env: Env):
invoicing_client = triad.client.InvoicingClient.from_session(env.session)
template = env.jinja2_env.get_template("beitrag.eml")
for member in csvreader:
invoice = invoicing_client.get_invoice_by_id(member['invoice_id'])
try:
invoice = invoicing_client.Invoice.find([(env.args.lookup_key, "=", str(member['invoice_id'])), ("type", "=", "out")])[0]
except IndexError:
continue
year = invoice.invoice_date or env.args.year
months = [datetime.date(year.year, month, 1) for month in range(1, 13)]
email_address = member.get('email') or invoice.party.email
@ -178,6 +182,8 @@ def main():
parser.add_argument("-O", "--output-dir", help="email output directory", default=".", type=pathlib.Path)
parser.add_argument("-T", "--template-dir", help="email template directory", default="mail_templates")
parser.add_argument("-c", "--config", type=argparse.FileType("rb"))
# Email arguments
parser.add_argument('--email-sender', help='email signature sender')
parser.add_argument("--email-from", help="email from header")
@ -190,6 +196,7 @@ def main():
fee_invoice_parser.add_argument("-F", "--csv-fields", type=lambda f: f.split(","), help="csv fields")
fee_invoice_parser.add_argument("-y", "--year", type=lambda y: datetime.date(int(y), 1, 1))
fee_invoice_parser.add_argument("--months", help="Beitragsmonate", type=lambda m: m.split(","), default="1,2,3,4,5,6,7,8,9,10,11,12")
fee_invoice_parser.add_argument("-k", "--lookup-key", choices={'number', 'id'}, default='id', help='lookup key for invoice')
fee_invoice_parser.add_argument("csvfile", type=argparse.FileType("r"), default="-", nargs="?")
fee_invoice_parser.set_defaults(func=fee_invoice)
@ -213,6 +220,22 @@ def main():
env.jinja2_env.filters["format_quantity"] = format_quantity
env.args = args
if args.config:
env.config = tomllib.load(args.config)
args.config.close()
if "tryton" in env.config:
if "uri" in env.config["tryton"]:
env.args.uri = env.config["tryton"]["uri"]
if "username" in env.config["tryton"]:
env.args.username = env.config["tryton"]["username"]
if "password" in env.config["tryton"]:
env.args.password = env.config["tryton"]["password"]
if "email" in env.config:
if "sender" in env.config["email"]:
env.args.email_sender = env.config["email"]["sender"]
if "from" in env.config["email"]:
env.args.email_from = env.config["email"]["from"]
if not args.uri:
args.uri = input("URI for Tryton: ")