@@ -0,0 +1,1465 @@
+from maediprojects import db, models%0Afrom sqlalchemy import *%0Aimport datetime%0A%0Adef isostring_date(value):%0A    # Returns a date object from a string of format YYYY-MM-DD%0A    return datetime.datetime.strptime(value, %22%25Y-%25m-%25d%22)%0A%0Adef isostring_year(value):%0A    # Returns a date object from a string of format YYYY%0A    return datetime.datetime.strptime(value, %22%25Y%22)%0A%0Adef add_finances(activity_id, data):%0A    aF = models.ActivityFinances()%0A    aF.activity_id = activity_id%0A    #aF.transaction_date = data%5B%22transaction_date%22%5D%0A    aF.transaction_type = data%5B%22transaction_type%22%5D%0A    #aF.transaction_value = data%5B%22transaction_value%22%5D%0A    #aF.transaction_description = data%5B%22transaction_description%22%5D%0A    db.session.add(aF)%0A    db.session.commit()%0A    return aF.id%0A%0Adef delete_finances(activity_id, finances_id):%0A    checkF = models.ActivityFinances.query.filter_by(%0A        activity_id = activity_id,%0A        id = finances_id%0A    ).first()%0A    if checkF:%0A        db.session.delete(checkF)%0A        db.session.commit()%0A        return True%0A    return False%0A%0Adef update_attr(data):%0A    finance = models.ActivityFinances.query.filter_by(%0A        id = data%5B'finances_id'%5D%0A    ).first()%0A    if data%5B'attr'%5D.endswith('date'):%0A        if data%5B%22value%22%5D == %22%22: %0A            data%5B%22value%22%5D = None%0A        else:%0A            data%5B'value'%5D = isostring_date(data%5B'value'%5D)%0A    setattr(finance, data%5B'attr'%5D, data%5B'value'%5D)%0A    db.session.add(finance)%0A    db.session.commit()%0A    return True%0A

Add ability to create and update financial data