2023-01-07 02:05:21 +11:00
|
|
|
# DrCr: Web-based double-entry bookkeeping framework
|
2024-11-09 18:14:25 +11:00
|
|
|
# Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
|
2023-01-07 02:05:21 +11:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2023-01-07 14:07:58 +11:00
|
|
|
from drcr.database import db
|
2024-11-09 18:14:25 +11:00
|
|
|
from drcr.models import Amount, reporting_commodity
|
2023-09-18 21:29:58 +10:00
|
|
|
from drcr.webapp import eofy_date
|
2023-09-10 19:36:33 +10:00
|
|
|
|
2023-01-07 02:05:21 +11:00
|
|
|
class CGTAsset(Amount):
|
|
|
|
def __init__(self, quantity, commodity, account, acquisition_date):
|
|
|
|
super().__init__(quantity, commodity)
|
|
|
|
|
|
|
|
self.account = account
|
|
|
|
self.acquisition_date = acquisition_date
|
|
|
|
|
|
|
|
self.disposal_date = None
|
|
|
|
self.disposal_value = None
|
2023-01-07 14:07:58 +11:00
|
|
|
|
|
|
|
self.cost_adjustments = []
|
2023-01-07 02:05:21 +11:00
|
|
|
|
|
|
|
def __repr__(self):
|
2023-01-07 15:39:04 +11:00
|
|
|
return '<{}: {} [{:%Y-%m-%d}]>'.format(self.__class__.__name__, self.format('force'), self.acquisition_date)
|
2023-01-07 02:05:21 +11:00
|
|
|
|
|
|
|
def commodity_name(self):
|
|
|
|
return self.commodity[:self.commodity.index('{')].strip()
|
2023-01-07 14:07:58 +11:00
|
|
|
|
|
|
|
def cost_adjustment(self):
|
2024-11-09 18:14:25 +11:00
|
|
|
return Amount(sum(a.cost_adjustment for a in self.cost_adjustments), reporting_commodity())
|
2023-01-07 14:07:58 +11:00
|
|
|
|
2023-09-10 19:36:33 +10:00
|
|
|
def cost_adjustment_brought_forward(self):
|
|
|
|
date1 = eofy_date()
|
|
|
|
date1 = date1.replace(year=date1.year - 1)
|
|
|
|
|
2024-11-09 18:14:25 +11:00
|
|
|
return Amount(sum(a.cost_adjustment for a in self.cost_adjustments if a.dt <= date1), reporting_commodity())
|
2023-09-10 19:36:33 +10:00
|
|
|
|
|
|
|
def cost_adjustment_current_period(self):
|
|
|
|
date1 = eofy_date()
|
|
|
|
date1 = date1.replace(year=date1.year - 1)
|
|
|
|
date2 = eofy_date()
|
|
|
|
|
2024-11-09 18:14:25 +11:00
|
|
|
return Amount(sum(a.cost_adjustment for a in self.cost_adjustments if a.dt > date1 and a.dt <= date2), reporting_commodity())
|
2023-09-10 19:36:33 +10:00
|
|
|
|
2023-01-07 14:07:58 +11:00
|
|
|
def gain(self):
|
|
|
|
return self.disposal_value - (self.as_cost() + self.cost_adjustment())
|
|
|
|
|
|
|
|
class CGTCostAdjustment(db.Model):
|
|
|
|
__tablename__ = 'austax_cgt_cost_adjustments'
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
|
|
|
|
quantity = db.Column(db.Integer)
|
|
|
|
commodity = db.Column(db.String)
|
|
|
|
account = db.Column(db.String)
|
|
|
|
acquisition_date = db.Column(db.DateTime)
|
|
|
|
|
|
|
|
dt = db.Column(db.DateTime)
|
|
|
|
description = db.Column(db.String)
|
|
|
|
cost_adjustment = db.Column(db.Integer)
|
|
|
|
|
|
|
|
def asset(self):
|
|
|
|
return CGTAsset(self.quantity, self.commodity, self.account, self.acquisition_date)
|
|
|
|
|
|
|
|
def cost_adjustment_amount(self):
|
2024-11-09 18:14:25 +11:00
|
|
|
return Amount(self.cost_adjustment, reporting_commodity())
|