def add_finances(activity_id, data): aF = models.ActivityFinances() aF.activity_id = activity_id classifications = data.get("classifications") data.pop("classifications") data["transaction_date"] = isostring_date(data["transaction_date"]) for key, value in data.items(): setattr(aF, key, value) _classifications = [] for key, value in classifications.items(): _c = models.ActivityFinancesCodelistCode() _c.codelist_id = key _c.codelist_code_id = value _classifications.append(_c) aF.classifications = _classifications db.session.add(aF) db.session.commit() qactivity.activity_updated( activity_id, { "user_id": current_user.id, "mode": "add", "target": "ActivityFinances", "target_id": aF.id, "old_value": None, "value": aF.as_dict() }) return aF.id
def update_attr(data): finance = models.ActivityFinances.query.filter_by( id=data['finances_id']).first() old_value = getattr(finance, data['attr']) if data['attr'].endswith('date'): if data["value"] == "": data["value"] = None else: data['value'] = isostring_date(data['value']) elif data['attr'] == "transaction_value": if data['value'] == "": data['value'] = 0.0 setattr(finance, data['attr'], data['value']) db.session.add(finance) db.session.commit() qactivity.activity_updated( finance.activity_id, { "user_id": current_user.id, "mode": "update", "target": "ActivityFinances", "target_id": finance.id, "old_value": { data['attr']: old_value }, "value": { data['attr']: data['value'] } }) return True
def update_entry(data): cf = models.ActivityCounterpartFunding.query.filter_by( id=data['id']).first() old_value = getattr(cf, data['attr']) if data['attr'].endswith('date'): if data["value"] == "": data["value"] = None else: data['value'] = isostring_date(data['value']) elif data['attr'] == "required_value": if data['value'] == "": data['value'] = 0.0 setattr(cf, data['attr'], data['value']) db.session.add(cf) db.session.commit() qactivity.activity_updated( cf.activity_id, { "user_id": current_user.id, "mode": "update", "target": "ActivityCounterpartFunding", "target_id": cf.id, "old_value": { data['attr']: old_value }, "value": { data['attr']: data['value'] } }) return True
def delete_entry(activity_id, counterpartfunding_id): checkCF = models.ActivityCounterpartFunding.query.filter_by( activity_id=activity_id, id=counterpartfunding_id).first() if checkCF: old_value = checkCF.as_dict() db.session.delete(checkCF) db.session.commit() qactivity.activity_updated( checkCF.activity_id, { "user_id": current_user.id, "mode": "delete", "target": "ActivityCounterpartFunding", "target_id": old_value["id"], "old_value": old_value, "value": None }) return True return False
def add_entry(activity_id, data): CF = models.ActivityCounterpartFunding() CF.activity_id = activity_id data["required_date"] = isostring_date(data["required_date"]) for key, value in data.items(): setattr(CF, key, value) db.session.add(CF) db.session.commit() qactivity.activity_updated( activity_id, { "user_id": current_user.id, "mode": "add", "target": "ActivityCounterpartFunding", "target_id": CF.id, "old_value": None, "value": CF.as_dict() }) return CF.id
def update_activity_codelist(activitycodelistcode_id, data): activity_codelist = models.ActivityCodelistCode.query.filter_by( id=activitycodelistcode_id).first() if not activity_codelist: return False old_value = getattr(activity_codelist, data['attr']) setattr(activity_codelist, data['attr'], data['value']) db.session.add(activity_codelist) db.session.commit() qactivity.activity_updated( activity_codelist.activity_id, { "user_id": current_user.id, "mode": "update", "target": "ActivityCodelistCode", "target_id": activity_codelist.id, "old_value": { data['attr']: old_value }, "value": { data['attr']: data['value'] } }) print data return True
def delete_finances(activity_id, finances_id): print "Delete activity id {} finances id {}".format( activity_id, finances_id) checkF = models.ActivityFinances.query.filter_by(activity_id=activity_id, id=finances_id).first() if checkF: old_value = checkF.as_dict() db.session.delete(checkF) db.session.commit() print "Return True" qactivity.activity_updated( checkF.activity_id, { "user_id": current_user.id, "mode": "delete", "target": "ActivityFinances", "target_id": old_value["id"], "old_value": old_value, "value": None }) return True print "Return False" return False
def update_finances_classification(data): checkF = models.ActivityFinancesCodelistCode.query.filter_by( activityfinance_id=data["finances_id"], codelist_id=data["attr"]).first() if not checkF: return False old_value = checkF.codelist_code_id checkF.codelist_code_id = data["value"] db.session.add(checkF) db.session.commit() qactivity.activity_updated( data["activity_id"], { "user_id": current_user.id, "mode": "update", "target": "ActivityFinancesCodelistCode", "target_id": checkF.id, "old_value": { data["attr"]: old_value }, "value": { data["attr"]: data["value"] } })