Andy Mikhailenko avatar Andy Mikhailenko committed cfce2dd

ext.finances: Improved commands, cleaned template and admin.

Comments (0)

Files changed (3)


 class ContractAdmin(PlanAdmin):
     namespace = NAMESPACE
     list_names = [
-        'summary', 'dates_rrule_text', 'fee', 'total_fee', 'currency'
+        'summary', 'fee', 'total_fee', 'currency'
     order_by = 'summary'


 def get_contracts(query):
     db = app.get_feature('document_storage').default_db
-    contracts = Contract.objects(db)
+    contracts = db.find(Contract)
     if query:
         return contracts.where(summary__matches_caseless=query)
 def get_payments(query=None, contract_query=None):
     db = app.get_feature('document_storage').default_db
     contracts = get_contracts(contract_query) if contract_query else None
-    payments = Payment.objects(db)
+    payments = db.find(Payment)
     if query:
         payments = payments.where(summary__matches_caseless=query)
     if contract_query:
 @arg('-q', '--query')
 @arg('-c', '--contract')
+@arg('--sum', default=False, help='print total sum of matching payments')
+@arg('--dump', default=False, help='dump contents of each payment document')
 def list_payments(args):
     "Displays a list of matching payments."
     args_to_unicode(args, ['query', 'contract'])
     payments = get_payments(args.query, args.contract)
+    if args.since:
+        since = datetime.datetime.strptime(args.since, '%Y-%m-%d')
+        payments = payments.where(date_time__gte=since)
+    if args.sum:
+        yield sum(p.amount for p in payments)
+        return
     for p in payments:
         yield unicode(p)
+        if args.dump:
+            yield '\n'.join(p.dump())
+            yield ''
 @arg('amount', help='e.g. "-9.99" (negative = expences, positive = income)')
 @arg('currency', help='e.g. "USD"')
 @arg('-c', '--contract', help='contract (query on summary)')
 @arg('--balance', help='balance after the payment')
 @arg('-s', '--summary', help='usually not needed when a contract is specified')
+@arg('--dry-run', default=False)
 def add_payment(args):
     "Logs a payment with given properties."
     args_to_unicode(args, ['currency', 'summary', 'contract'])
     if args.contract:
         contracts = get_contracts(args.contract)
         if not contracts:
-            raise COmmandError('no contracts matching query')
+            raise CommandError('no contracts matching query')
         if 1 < len(contracts):
             yield 'Mare than one contract matched query:'
             for c in contracts:
         amount = amount,
         currency = args.currency,
         plan = contract,
-        summary = args.summary,
+        summary = args.summary or u'payment',
         balance = balance,
-        source = DATA_SOURCE+'.add_payment',
+        source = unicode(DATA_SOURCE+'.add_payment'),
     if not args.dry_run:


             {% for plan in column %}
                 {#% if plan.next_date_time %#}
                     <h2><a href="{{ url_for('orgtool.ext.finances.plan', }}">{{ plan }}</a></h2>
                         {% if plan.next_date_time < today %}
                         {% endif %}
                         <span class="{% if plan.expected_payment_amount|float > 0 %}income{% else %}expense{% endif %}">
                             <strong>{{ plan.get_expected_payment_amount_as(default_currency)|string|replace("-","&minus;")}}&nbsp;{{ default_currency }}</strong>
                             {% if not plan.currency == default_currency %}
                             {% endif %}
                             {% if not plan.is_fee_fixed %}(approx.){% endif %}
                         <span title="{{ plan.next_date_time.strftime("%d %B %Y") }}">{{ render_rel_delta(plan.next_date_time) }}</span>
                         {% set chart_url = chart_url_for_payments(,
                                     scale='months', max_intervals=6, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.