Private
Public Access
1
0

sending invoices

This commit is contained in:
2024-12-26 12:49:29 +01:00
parent c0e1df04d8
commit b58dacb863
6 changed files with 58 additions and 1 deletions

View File

@@ -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")

View File

@@ -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

View File

@@ -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(

View 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 %}

Binary file not shown.

View File

@@ -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(