Пример #1
0
def person_assign_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None or user.is_administrator == False:
            return HTTPFound(request.application_url)

        person_id = long(request.matchdict.get('person_id'))
        assignment_id = long(request.matchdict.get('assignment_id'))

        person = DBSession.query(User).filter_by(id=person_id).filter_by(account_id=account_id).first()
        if person == None:
            return HTTPFound(request.application_url)

        source_type_text = request.params.get("source_type")
        if source_type_text is None:
            source_type = "office"
        elif source_type_text == "ghost_client":
            source_type = "ghost/client"
        elif source_type_text == "client":
            source_type = source_type_text
        else:
            source_type = "office"
        source_id_text = request.params.get("source_id")
        if source_id_text is None:
            source_id = person.office_id
        else:
            source_id = long(source_id_text)


        user_allocation = DBSession.query(UserAllocation).filter_by(id=assignment_id).first()
        if user_allocation == None or user_allocation.user_id != person.id:
            return HTTPFound(request.application_url)
        DBSession.delete(user_allocation)
        DBSession.flush()

        return HTTPFound(location=request.application_url + "/person/" + str(
            person_id) + "/assign/edit?source_type=" + source_type + "&source_id=" + str(source_id))
    except:
        print("*****")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Пример #2
0
def freelancer_delete(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        freelancer_id = request.matchdict.get('freelancer_id')
        freelancer = DBSession.query(Freelancer).filter_by(id=freelancer_id).filter_by(account_id=account_id).first()

        if freelancer is None:
            return HTTPFound(request.application_url)

        if freelancer.office is None and freelancer.client is None:
            return HTTPFound(request.application_url)

        if freelancer.office is not None and user.can_access_office(freelancer.office, "utilization") == False:
            return HTTPFound(request.application_url)

        if freelancer.client is not None and user.can_access_client(freelancer.client, "utilization") == False:
            return HTTPFound(request.application_url)

        source_id = freelancer.client_id

        DBSession.delete(freelancer)
        DBSession.flush()

        return HTTPFound(
            request.application_url + "/client/" + str(source_id) + "/utilization/" + str(datetime.datetime.now().year))

    except:
        print("*************")
        traceback.print_exc()
        return HTTPFound(request.application_url)
Пример #3
0
def project_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        project_id = long(request.matchdict['project_id'])
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(account_id=account_id).first()

        if project is None or user.can_access_client(project.client, "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]

            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]), long(start_dateparts[0]), long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]), long(end_dateparts[0]), long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client, "financials") == False:
                return HTTPFound(request.application_url)

            for p in client.projects:
                if p.name == name and p.id != project.id:
                    return HTTPFound(request.application_url)

            matched_departments = []
            for department in account.departments:
                percent_allocation = request.params.get(str(department.id) + "-allocation")
                for budget_allocation in project.budget_allocations:
                    if budget_allocation.department_id == department.id:
                        matched_departments.append(department.id)
                        if percent_allocation is None or percent_allocation == "":
                            DBSession.delete(budget_allocation)
                        else:
                            budget_allocation.percent_allocation = percent_allocation

            for department in account.departments:
                if department.id not in matched_departments:
                    percent_allocation = request.params.get(str(department.id) + "-allocation")
                    if percent_allocation is not None and percent_allocation != "":
                        ba = BudgetAllocation(department, project, None, int(percent_allocation))
                        DBSession.add(ba)

            project.name = name
            project.code = code
            project.client = client
            project.revenue = revenue
            project.start_date = start_date
            project.end_date = end_date
            DBSession.flush()

            return HTTPFound(request.application_url + "/client/" + str(client_id) + "/projects/" + str(
                datetime.datetime.now().year))

        matched_departments = []
        for budget_allocation in project.budget_allocations:
            matched_departments.append(budget_allocation.department_id)

        budgetAllocations = project.budget_allocations

        for department in account.departments:
            if department.id not in matched_departments:
                budgetAllocations.append(BudgetAllocation(department, project, None, 0))

        clients_all = DBSession.query(Client).filter_by(account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request), header=Header("financials"), clients=clients, user=user,
                    account=account, project=project, budgetAllocations=budgetAllocations)
    except:
        return HTTPFound(request.application_url)
Пример #4
0
def project_edit(request):
    try:
        account_id = long(request.session['aid'])
        user_id = long(request.session['uid'])
        user = DBSession.query(User).filter_by(id=user_id).first()
        account = DBSession.query(Account).filter_by(id=account_id).first()

        if user is None or account is None:
            return HTTPFound(request.application_url)

        project_id = long(request.matchdict['project_id'])
        project = DBSession.query(Project).filter_by(id=project_id).filter_by(
            account_id=account_id).first()

        if project is None or user.can_access_client(project.client,
                                                     "financials") == False:
            return HTTPFound(request.application_url)

        if request.method == "POST":

            name = request.params["name"].lower()
            code = request.params["project_code"]

            client_id = long(request.params["client_id"])
            revenue_local = long(request.params["revenue"])

            if user.currency is None:
                revenue = revenue_local
            else:
                revenue = revenue_local * user.currency.currency_to_usd

            start_date_text = request.params["start_date"]
            start_dateparts = start_date_text.split("/")
            start_date = datetime.date(long(start_dateparts[2]),
                                       long(start_dateparts[0]),
                                       long(start_dateparts[1]))

            end_date_text = request.params["end_date"]
            end_dateparts = end_date_text.split("/")
            end_date = datetime.date(long(end_dateparts[2]),
                                     long(end_dateparts[0]),
                                     long(end_dateparts[1]))

            client = DBSession.query(Client).filter_by(
                account_id=account_id).filter_by(id=client_id).first()

            if client is None or user.can_access_client(client,
                                                        "financials") == False:
                return HTTPFound(request.application_url)

            for p in client.projects:
                if p.name == name and p.id != project.id:
                    return HTTPFound(request.application_url)

            matched_departments = []
            for department in account.departments:
                percent_allocation = request.params.get(
                    str(department.id) + "-allocation")
                for budget_allocation in project.budget_allocations:
                    if budget_allocation.department_id == department.id:
                        matched_departments.append(department.id)
                        if percent_allocation is None or percent_allocation == "":
                            DBSession.delete(budget_allocation)
                        else:
                            budget_allocation.percent_allocation = percent_allocation

            for department in account.departments:
                if department.id not in matched_departments:
                    percent_allocation = request.params.get(
                        str(department.id) + "-allocation")
                    if percent_allocation is not None and percent_allocation != "":
                        ba = BudgetAllocation(department, project, None,
                                              int(percent_allocation))
                        DBSession.add(ba)

            project.name = name
            project.code = code
            project.client = client
            project.revenue = revenue
            project.start_date = start_date
            project.end_date = end_date
            DBSession.flush()

            return HTTPFound(request.application_url + "/client/" +
                             str(client_id) + "/projects/" +
                             str(datetime.datetime.now().year))

        matched_departments = []
        for budget_allocation in project.budget_allocations:
            matched_departments.append(budget_allocation.department_id)

        budgetAllocations = project.budget_allocations

        for department in account.departments:
            if department.id not in matched_departments:
                budgetAllocations.append(
                    BudgetAllocation(department, project, None, 0))

        clients_all = DBSession.query(Client).filter_by(
            account_id=account_id).all()
        clients = []
        if user.is_administrator or user.permissions_global_utilization:
            clients = clients_all
        else:
            for client in clients_all:
                if user.can_access_client(client, "utilization"):
                    clients.append(client)
        if len(clients) == 0:
            return HTTPFound(request.application_url)
        return dict(logged_in=authenticated_userid(request),
                    header=Header("financials"),
                    clients=clients,
                    user=user,
                    account=account,
                    project=project,
                    budgetAllocations=budgetAllocations)
    except:
        return HTTPFound(request.application_url)