sending invoices
This commit is contained in:
@@ -328,6 +328,8 @@ def update_subscription(rower, data, method='up'):
|
||||
'%Y-%m-%d'),
|
||||
method)
|
||||
|
||||
_ = idoklad.create_invoice(rower, amount, result.subscription.id, dosend=True)
|
||||
|
||||
return True, amount
|
||||
else: # pragma: no cover
|
||||
errors = result.errors.for_object("subscription")
|
||||
|
||||
@@ -14,6 +14,13 @@ contacts_url = 'https://api.idoklad.cz/v3/Contacts'
|
||||
invoice_url = 'https://api.idoklad.cz/v3/IssuedInvoices'
|
||||
email_url = 'https://api.idoklad.cz/v3/Mails/IssuedInvoice/Send'
|
||||
|
||||
from rowers.tasks import handle_send_email_noinvoice
|
||||
|
||||
from rowers.utils import myqueue
|
||||
|
||||
import django_rq
|
||||
queuehigh = django_rq.get_queue('high')
|
||||
|
||||
from rowers.models import iDokladToken
|
||||
|
||||
#idoklad_countries = json.loads(open('rowers/idoklad_countries.json').read())["Data"]["Items"]
|
||||
@@ -86,6 +93,7 @@ def get_contacts(rower):
|
||||
return None # pragma
|
||||
|
||||
def create_contact(rower):
|
||||
print("idoklad create contact", rower)
|
||||
token = idoklad_token()
|
||||
if token is None:
|
||||
return None
|
||||
@@ -118,6 +126,14 @@ def create_contact(rower):
|
||||
res = requests.post(contacts_url, json=data, headers=headers)
|
||||
|
||||
if res.status_code not in [200, 201]:
|
||||
dologging('idoklad.log','Contact Created - reason '+str(res.reason)+'\n')
|
||||
_ = myqueue.enqueue(
|
||||
queuehigh, handle_send_email_noinvoice,
|
||||
rower.user.email,
|
||||
rower.user.first_name,
|
||||
rower.user.last_name,
|
||||
'idoklad Contact creation failed for '+str(rower.user.email)+'\n'+str(res.text)
|
||||
)
|
||||
return 0
|
||||
|
||||
id = res.json()['Data']['Id']
|
||||
@@ -199,6 +215,14 @@ def create_invoice(rower, amount, braintreeid, dosend=True, contact_id=None, nam
|
||||
dologging('idoklad.log','Invoice Sent - status code '+str(res.status_code)+'\n')
|
||||
if res.status_code not in [200, 201]:
|
||||
dologging('idoklad.log','Invoice Sent - reason '+str(res.text)+'\n')
|
||||
_ = myqueue.enqueue(
|
||||
queuehigh, handle_send_email_noinvoice,
|
||||
rower.user.email,
|
||||
rower.user.first_name,
|
||||
rower.user.last_name,
|
||||
'idoklad Invoice sending failed for '+str(rower.user.email)+'\n'+str(res.text)
|
||||
)
|
||||
|
||||
|
||||
return id
|
||||
|
||||
|
||||
@@ -1796,6 +1796,22 @@ def sigdig(value, digits=3):
|
||||
fmtstr = "%.0f"
|
||||
return fmtstr % (round(value, places))
|
||||
|
||||
@app.task
|
||||
def handle_send_email_noinvoice(
|
||||
useremail, userfirstname, userlastname, reason, **kwargs):
|
||||
|
||||
subject = "Reason"
|
||||
|
||||
from_email = 'Rowsandall <admin@rowsandall.com>'
|
||||
d = {
|
||||
'name': userfirstname+' '+userlastname,
|
||||
'siteurl': siteurl,
|
||||
'reason': reason,
|
||||
}
|
||||
|
||||
_ = send_template_email(from_email, support@rowsandall.com, subject,
|
||||
'paymentconfirmationemail_noinvoice.html',
|
||||
d, **kwargs)
|
||||
|
||||
@app.task
|
||||
def handle_send_email_alert(
|
||||
|
||||
12
rowers/templates/paymentconfirmationemail_noinvoice.html
Normal file
12
rowers/templates/paymentconfirmationemail_noinvoice.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% extends "emailbase.html" %}
|
||||
|
||||
{% block body %}
|
||||
<p>Dear Admin,</p>
|
||||
|
||||
|
||||
<p><strong>{{ name }}</strong>: {{ reason }}.</p>
|
||||
|
||||
<p>
|
||||
Best Regards, the Rowsandall Team
|
||||
</p>
|
||||
{% endblock %}
|
||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -58,7 +58,10 @@ def process_idokladcallback(request):
|
||||
t.acces_token = result['access_token'],
|
||||
t.refresh_token = result['refresh_token']
|
||||
t.expires_in = result['expires_in']
|
||||
t.id_token = result['id_token']
|
||||
try:
|
||||
t.id_token = result['id_token']
|
||||
except KeyError:
|
||||
pass
|
||||
t.save()
|
||||
except iDokladToken.DoesNotExist:
|
||||
t = iDokladToken(
|
||||
|
||||
Reference in New Issue
Block a user