Пример #1
0
def add_bill(cost=100.0):
    users = []
    group = sObj.getGroup(10204809)
    people = group.getMembers()

    expense = Expense()
    expense.setCost(str(cost))
    expense.setDescription("Capital One Transfer")
    # per_person = str(round(cost / len(people), 2))
    per_person = cost

    paying_user =sObj.getCurrentUser()
    paying_id = paying_user.getId()
    paying_expense_user = ExpenseUser()
    paying_expense_user.setId(paying_id)
    paying_expense_user.setPaidShare(str(cost))
    paying_expense_user.setOwedShare(per_person)
    users.append(paying_expense_user)


    for friend in people:
        id = friend.getId()
        if id == paying_id:
            continue
        user = ExpenseUser()
        user.setId(id)
        user.setPaidShare('0.0')
        user.setOwedShare(per_person)
        users.append(user)
        expense.setUsers(users)
        expense = sObj.createExpense(expense)
        print(expense.getId())
Пример #2
0
 def test_expense_flow(self):
     receipt = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                            "receipt.jpg")
     expense = Expense()
     expense.setDescription("End2EndTest")
     expense.setCost('10')
     expense.setGroupId(19571167)
     expense.setSplitEqually()
     expense.setReceipt(receipt)
     # create expense
     expense, error = self.sObj.createExpense(expense)
     self.assertIsNone(error)
     self.assertIsNotNone(expense.getId())
     # delete expense
     success, error = self.sObj.deleteExpense(expense.getId())
     self.assertIsNone(error)
     self.assertTrue(success)
Пример #3
0
    def process(self, input):
        app.logger.debug("Processing New Transaction Request")

        output = BotConstants.NEW_EXPENSE_OUTPUT
        splitwise_obj = SplitwiseProcessor.getSplitwiseObject(input)

        current_user = splitwise_obj.getCurrentUser()
        friends_list = splitwise_obj.getFriends()

        user_list = []
        split = SplitwiseProcessor.getInputFromRequest(
            input, TransactionProcessor.SplitType.SPLIT, ErrorMessages.SPLIT,
            True)
        split = split.lower()

        if split not in TransactionProcessor.SplitType.getSplitList():
            raise BotException(ErrorMessages.WRONG_SPLIT)

        name = SplitwiseProcessor.getInputFromRequest(input, BotConstants.NAME,
                                                      ErrorMessages.NAME, True)
        currency = SplitwiseProcessor.getInputFromRequest(
            input, BotConstants.CURRENCY)
        description = SplitwiseProcessor.getInputFromRequest(
            input, BotConstants.DESCRIPTION)

        if description == "":
            description = BotConstants.FROM_BOT

        amount = 0

        if BotConstants.AMOUNT in currency:
            amount = currency[BotConstants.AMOUNT]
        else:
            amount = SplitwiseProcessor.getInputFromRequest(
                input, BotConstants.AMOUNT, self.getAmountError(split), True)

        group = str(
            SplitwiseProcessor.getInputFromRequest(input, BotConstants.GROUP))
        group_id = self.getGroupId(group, splitwise_obj.getGroups())

        expense = Expense()
        expense.setCost(amount)

        if not group_id == -1:
            expense.setGroupId(group_id)

        mode = split.lower()

        expense.setDescription(description)

        # current user
        paid, owed = self.getDistribution(mode, amount)
        expense_user = self.getExpenseUser(current_user, paid, owed)
        user_list.append(expense_user)

        match = False
        for friend in friends_list:
            if friend.getFirstName().lower() == name.lower():
                expense_user = self.getExpenseUser(friend, owed, paid)
                match = True
                if mode != TransactionProcessor.SplitType.PAID and mode != TransactionProcessor.SplitType.OWE:
                    expense_user.setPaidShare(str(0))
                    expense_user.setOwedShare(str(owed))

                output += friend.getFirstName()
                user_list.append(expense_user)
                break

        if not match:
            raise BotException(ErrorMessages.NO_FRIEND.format(name=name))

        expense.setUsers(user_list)

        expense = splitwise_obj.createExpense(expense)

        if expense.getId() is None:
            raise BotException(ErrorMessages.GENERAL)

        app.logger.debug("New Expense is created")

        return output