DrCr/austax/models.py

64 lines
2.1 KiB
Python

# DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo)
#
# 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/>.
from drcr.database import db
from drcr.models import Amount
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
self.cost_adjustments = []
def __repr__(self):
return '<{}: {} [{:%Y-%m-%d}]>'.format(self.__class__.__name__, self.format('force'), self.acquisition_date)
def commodity_name(self):
return self.commodity[:self.commodity.index('{')].strip()
def cost_adjustment(self):
# TODO: brought forward vs current period
return Amount(sum(a.cost_adjustment for a in self.cost_adjustments), '$')
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):
return Amount(self.cost_adjustment, '$')