59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
"""
|
|
This file is part of Accountant.
|
|
|
|
Accountant 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.
|
|
|
|
Accountant 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 Accountant. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
from sqlalchemy import desc
|
|
|
|
from accountant import db
|
|
|
|
from .accounts import Account
|
|
|
|
|
|
class ScheduledOperation(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
start_date = db.Column(db.Date, nullable=False)
|
|
stop_date = db.Column(db.Date, nullable=False)
|
|
day = db.Column(db.Integer, nullable=False)
|
|
frequency = db.Column(db.Integer, nullable=False)
|
|
label = db.Column(db.String(500), nullable=False)
|
|
value = db.Column(db.Numeric(15, 2), nullable=False)
|
|
account_id = db.Column(db.Integer, db.ForeignKey('account.id'))
|
|
|
|
account = db.relationship(Account, backref=db.backref('scheduled_operation',
|
|
lazy="dynamic"))
|
|
|
|
category = db.Column(db.String(100), nullable=True)
|
|
|
|
def __init__(self, start_date, stop_date, day, frequency, label, value,
|
|
account_id, category=None):
|
|
self.start_date = start_date
|
|
self.stop_date = stop_date
|
|
self.day = day
|
|
self.frequency = frequency
|
|
self.label = label
|
|
self.value = value
|
|
self.account_id = account_id
|
|
self.category = category
|
|
|
|
@classmethod
|
|
def query(cls, session):
|
|
return session.query(
|
|
cls
|
|
).order_by(
|
|
desc(cls.day),
|
|
cls.value,
|
|
cls.label,
|
|
)
|