austax: Add links to CGT assets report

This commit is contained in:
RunasSudo 2023-01-07 18:37:09 +11:00
parent a4faca5ea8
commit 46b041d9dc
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 23 additions and 6 deletions

View File

@ -50,12 +50,12 @@
<tbody>
{% for asset in assets %}
<tr>
<td>{{ asset.account }}</td>
<td><a href="/account-transactions?account={{ asset.account }}&commodity-detail=1">{{ asset.account }}</a></td>
<td>{{ asset.commodity_name() }}</td>
<td class="text-end">{{ asset.format('hide') }}</td>
<td style="border-left-width:1px">{{ asset.acquisition_date.strftime('%Y-%m-%d') }}</td>
<td class="text-end">{{ asset.as_cost().format() }}</td>
<td style="border-left-width:1px" class="text-end">{{ asset.cost_adjustment().format_accounting() if asset.cost_adjustments }}</td>
<td style="border-left-width:1px" class="text-end">{{ asset.cost_adjustment().format_accounting(link="/tax/cgt-adjustments?account={}&commodity={}&quantity={}&acquisition_date={:%Y-%m-%d}".format(asset.account, asset.commodity, asset.quantity, asset.acquisition_date)) if asset.cost_adjustments }}</td>
<td>{# TODO #}</td>
<td class="text-center d-print-none"><a href="/tax/cgt-adjustments/new?account={{ asset.account }}&asset={{ asset.quantity_string() }}&acquisition_date={{ asset.acquisition_date.strftime('%Y-%m-%d') }}"><i class="bi bi-plus-lg text-muted"></i></a></td>
<td style="border-left-width:1px">{{ asset.disposal_date.strftime('%Y-%m-%d') if asset.disposal_date else '' }}</td>

View File

@ -29,7 +29,17 @@ from math import copysign
@app.route('/tax/cgt-adjustments')
def cgt_adjustments():
adjustments = db.session.scalars(db.select(CGTCostAdjustment).order_by(CGTCostAdjustment.dt, CGTCostAdjustment.account)).all()
adjustments = db.select(CGTCostAdjustment).order_by(CGTCostAdjustment.dt, CGTCostAdjustment.account)
if 'account' in request.args:
adjustments = adjustments.where(CGTCostAdjustment.account == request.args['account'])
if 'quantity' in request.args:
adjustments = adjustments.where(CGTCostAdjustment.quantity == request.args['quantity'])
if 'commodity' in request.args:
adjustments = adjustments.where(CGTCostAdjustment.commodity == request.args['commodity'])
if 'acquisition_date' in request.args:
adjustments = adjustments.where(CGTCostAdjustment.acquisition_date == datetime.strptime(request.args['acquisition_date'], '%Y-%m-%d'))
adjustments = db.session.scalars(adjustments).all()
return render_plugin_template('austax', 'cgt_adjustments.html', cgt_adjustments=adjustments)
@app.route('/tax/cgt-adjustments/new', methods=['GET', 'POST'])

View File

@ -122,11 +122,18 @@ class Amount:
else:
return Markup('{1:,.{dps}f} {0}'.format(self.commodity, self.quantity / (10**AMOUNT_DPS), dps=AMOUNT_DPS).replace(',', '&#x202F;'))
def format_accounting(self):
def format_accounting(self, link=None):
if self.quantity >= 0:
return Markup('{:,.{dps}f}&nbsp;'.format(self.quantity / (10**AMOUNT_DPS), dps=AMOUNT_DPS).replace(',', '&#x202F;'))
text = '{:,.{dps}f}'.format(self.quantity / (10**AMOUNT_DPS), dps=AMOUNT_DPS).replace(',', '&#x202F;')
space = '&nbsp;'
else:
return Markup('({:,.{dps}f})'.format(-self.quantity / (10**AMOUNT_DPS), dps=AMOUNT_DPS).replace(',', '&#x202F;'))
text = '({:,.{dps}f})'.format(-self.quantity / (10**AMOUNT_DPS), dps=AMOUNT_DPS).replace(',', '&#x202F;')
space = ''
if link is None:
return Markup(text + space)
else:
return Markup('<a href="{}">{}</a>{}'.format(link, text, space))
def quantity_string(self):
if self.commodity == '$':