# 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 . from drcr.database import db from drcr.models import Amount from drcr.webapp import eofy_date 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): return Amount(sum(a.cost_adjustment for a in self.cost_adjustments), '$') def cost_adjustment_brought_forward(self): date1 = eofy_date() date1 = date1.replace(year=date1.year - 1) return Amount(sum(a.cost_adjustment for a in self.cost_adjustments if a.dt <= date1), '$') def cost_adjustment_current_period(self): date1 = eofy_date() date1 = date1.replace(year=date1.year - 1) date2 = eofy_date() return Amount(sum(a.cost_adjustment for a in self.cost_adjustments if a.dt > date1 and a.dt <= date2), '$') 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, '$')