mirror of
https://github.com/nikdoof/pacmanager.git
synced 2025-12-13 07:32:15 +00:00
Completed work on transaction processing from a Payments wallet
This commit is contained in:
@@ -2,7 +2,7 @@ from django.contrib import admin
|
||||
from .models import Setting, Character, Corporation, Key, Transaction, MonthTotal, APICache
|
||||
|
||||
class SettingAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
list_display = ('key', 'value')
|
||||
|
||||
class CharacterAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name')
|
||||
@@ -33,6 +33,7 @@ class MonthTotalAdmin(admin.ModelAdmin):
|
||||
class APICacheAdmin(admin.ModelAdmin):
|
||||
list_display = ('key', 'cache_until')
|
||||
|
||||
|
||||
admin.site.register(Setting, SettingAdmin)
|
||||
admin.site.register(Character, CharacterAdmin)
|
||||
admin.site.register(Corporation, CorporationAdmin)
|
||||
|
||||
0
pacmanager/core/management/__init__.py
Normal file
0
pacmanager/core/management/__init__.py
Normal file
0
pacmanager/core/management/commands/__init__.py
Normal file
0
pacmanager/core/management/commands/__init__.py
Normal file
11
pacmanager/core/management/commands/updatecorps.py
Normal file
11
pacmanager/core/management/commands/updatecorps.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import logging
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from core.tasks import process_corps
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Process all corporation wallet journals'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
process_corps()
|
||||
11
pacmanager/core/management/commands/updatepayments.py
Normal file
11
pacmanager/core/management/commands/updatepayments.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import logging
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from core.tasks import process_pac_wallet
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Process the payments wallet for new payments'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
process_pac_wallet()
|
||||
@@ -16,6 +16,9 @@ class Setting(models.Model):
|
||||
key = models.CharField(max_length=32)
|
||||
value = models.CharField(max_length=200)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.key
|
||||
|
||||
|
||||
class Character(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -33,7 +36,7 @@ class Corporation(models.Model):
|
||||
balance = models.DecimalField('Current Balance', max_digits=25, decimal_places=2, default=0)
|
||||
|
||||
last_transaction = models.BigIntegerField('Last Transaction ID', default=0)
|
||||
payment_id = models.CharField('Payment ID', max_length=36)
|
||||
payment_id = models.CharField('Payment ID', max_length=36, default=uuid4)
|
||||
|
||||
objects = CorporationManager()
|
||||
|
||||
@@ -42,11 +45,6 @@ class Corporation(models.Model):
|
||||
return u'%s' % self.name
|
||||
return u'%s' % self.pk
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.payment_id is None or self.payment_id == '':
|
||||
self.payment_id = uuid4()
|
||||
return super(Corporation, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class MonthTotal(models.Model):
|
||||
"""Holds the monthly fee totals for a corporation"""
|
||||
@@ -176,4 +174,7 @@ class APICache(models.Model):
|
||||
if obj.cache_until >= datetime.utcnow().replace(tzinfo=utc):
|
||||
return obj.document
|
||||
return None
|
||||
|
||||
def __unicode__(self):
|
||||
return self.key
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.utils.timezone import utc
|
||||
|
||||
from eveapi import EVEAPIConnection, Error, Rowset
|
||||
from .conf import managerconf
|
||||
from .models import Corporation, APICache, MonthTotal
|
||||
from .models import Corporation, APICache, MonthTotal, Transaction
|
||||
|
||||
def import_wallet_journal(corporation_id):
|
||||
corp = Corporation.objects.get(pk=corporation_id)
|
||||
@@ -18,7 +18,7 @@ def import_wallet_journal(corporation_id):
|
||||
def get_records(corp=None, fromID=None, rowCount=2560):
|
||||
if fromID and fromID <= corp.last_transaction:
|
||||
return None
|
||||
print "get_records: ", corp, fromID
|
||||
#print "get_records: ", corp, fromID
|
||||
try:
|
||||
res = auth.corp.WalletJournal(rowCount=rowCount, fromID=fromID)
|
||||
except Error, e:
|
||||
@@ -35,12 +35,12 @@ def import_wallet_journal(corporation_id):
|
||||
|
||||
# Process Rows
|
||||
rows = get_records(corp).SortedBy('refID', reverse=True)
|
||||
print "Total rows: ", len(rows)
|
||||
logging.info("Total rows: %s" % len(rows))
|
||||
totals = {}
|
||||
for record in rows:
|
||||
if int(record.refID) > corp.last_transaction:
|
||||
if int(record.refTypeID) in getattr(settings, 'PAC_TAX_REFIDS', [85, 99]):
|
||||
print record.refID, int(record.refTypeID), record.amount
|
||||
#print record.refID, int(record.refTypeID), record.amount
|
||||
dt = datetime.fromtimestamp(record.date).replace(tzinfo=utc)
|
||||
if not totals.has_key('%s-%s' % (dt.year, dt.month)):
|
||||
totals['%s-%s' % (dt.year, dt.month)], created = MonthTotal.objects.get_or_create(corporation=corp, year=dt.year, month=dt.month)
|
||||
@@ -67,15 +67,33 @@ def process_pac_wallet():
|
||||
for corp in Corporation.objects.all():
|
||||
paymentid[corp.payment_id] = corp
|
||||
|
||||
if not 'payments.keyid' in managerconf or not 'payments.vcode' in managerconf:
|
||||
logging.error('No payments Key ID / vCode set!')
|
||||
return
|
||||
|
||||
api = EVEAPIConnection(cacheHandler=APICache.DjangoCacheHandler())
|
||||
auth = api.auth(keyID=managerconf['payments.keyid'], vCode=managerconf['payments.vcode'])
|
||||
try:
|
||||
res = auth.corp.WalletJournal(rowCount=2560)
|
||||
entries = auth.corp.WalletJournal(rowCount=2560).entries.SortedBy('refID', reverse=True)
|
||||
except Error, e:
|
||||
print e
|
||||
logging.error('Error importing Payments wallet: %s' % e)
|
||||
return
|
||||
|
||||
for record in res.entries:
|
||||
if int(record.refID) > managerconf['payments.last_id'] and record.reason.replace('DESC:', '') in paymentid.keys():
|
||||
continue
|
||||
if not 'payments.last_id' in managerconf:
|
||||
managerconf['payments.last_id'] = 0
|
||||
|
||||
logging.info('Last processed Ref ID: %s' % managerconf['payments.last_id'])
|
||||
for record in entries:
|
||||
if int(record.refID) > int(managerconf['payments.last_id']):
|
||||
res = record.reason.replace('DESC: ', '').strip()
|
||||
if paymentid.has_key(res):
|
||||
corp = paymentid[res]
|
||||
logging.info('Payment Found, %s, Ref ID %s, Amount: %s ISK' % (corp.name, record.refID, record.amount))
|
||||
# Payment found
|
||||
trans = Transaction.objects.create(corporation=corp, value=record.amount, comment="Wallet Ref ID %s" % record.refID, type=Transaction.TRANSACTION_TYPE_PAYMENT)
|
||||
corp.balance += Decimal(str(record.amount))
|
||||
corp.save()
|
||||
else:
|
||||
break
|
||||
|
||||
managerconf['payments.last_id'] = entries[0].refID
|
||||
|
||||
@@ -24,11 +24,12 @@ span.negative { color: red; }
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No wallet balance information is available at this time.</p>
|
||||
<p><small>No wallet balance information is available at this time.</small></p>
|
||||
{% endif %}
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h2>Balance Payment</h2>
|
||||
<p>To make a payment towards this corporation's fees, send money to <b>{{ payment_corp }}</b> with <b>{{ object.payment_id }}</b> as the "Reason" field.</p>
|
||||
<p> </p>
|
||||
{% if object.totals.count %}
|
||||
<h2>Tax Period Overview</h2>
|
||||
<p><small>Total transactions by taxable periods and related fees</small></p>
|
||||
|
||||
@@ -29,6 +29,6 @@
|
||||
</table>
|
||||
</p>
|
||||
{% else %}
|
||||
<p><small>No corporations are currently available, consider <a href="{% url key-create %}">adding a API key</a>.</small></p>
|
||||
<p><small>No corporations are currently available to you{% if perms.add_key %}, consider <a href="{% url key-create %}">adding a API key</a>{% endif %}.</small></p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
<p><small>No keys are currently stored.</small></p>
|
||||
{% endif %}
|
||||
|
||||
{% if perms.add_key %}
|
||||
<p><a href="{% url key-create %}" class="btn"><i class="icon-plus"></i> Add Key</a></p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
|
||||
@@ -16,6 +16,7 @@ from braces.views import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from .tasks import import_wallet_journal
|
||||
from .forms import KeyForm, CorporationContactForm, ManualAdjustmentForm
|
||||
from .models import Corporation, Key, APICache, Transaction, MonthTotal
|
||||
from .conf import managerconf
|
||||
|
||||
class KeyListView(LoginRequiredMixin, ListView):
|
||||
|
||||
@@ -128,6 +129,7 @@ class CorporationDetailView(LoginRequiredMixin, DetailView):
|
||||
ctx.update({
|
||||
'balances': balances,
|
||||
'last_update': last_update,
|
||||
'payment_corp': managerconf.get('payment.corpname', 'Upvote'),
|
||||
})
|
||||
|
||||
return ctx
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<link href="{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet">
|
||||
<style>
|
||||
body { padding-top: 60px; }
|
||||
.navbar .nav > li > a { color: #BFBFBF; }
|
||||
div.navbar-inner {
|
||||
background-color: #204066;
|
||||
background-image: url(https://forum.pleaseignore.com/public/style_images/master/branding_bg.png);
|
||||
|
||||
Reference in New Issue
Block a user