namaggarwal / splitwise

Python SDK for Splitwise
MIT License
183 stars 46 forks source link

Error creating Expense with several ExpenseUser #71

Closed RitaSousa09 closed 1 year ago

RitaSousa09 commented 2 years ago

Hello, We are trying to add an inconstant number of ExpenseUser according to the number of key:values in the previously created usersInfo dictionary, something like this: {'349': '1,34', '396': '0,00', '345': '2,00', '409: '5,11'}, with the key being the Splitwise user ID and the value being the owed share.

Part of the code is below:

s = Splitwise(SPLITWISE_API_KEY, SPLITWISE_API_SECRET, api_key=TOKEN_API_KEY)
expense = Expense()

for userId in usersInfo:
    user = ExpenseUser()
    user.setId(userId)
    if whoPaid == userId:
        user.setPaidShare(paidQuantity)
    else:
        user.setPaidShare('0.00')
    user.setOwedShare(usersInfo[userId])
    expense.addUser(user)

created_expense, errors = s.createExpense(expense)

But we're getting this error: {'base': ['There are zero people involved in this expense! Make sure to add some before saving.']}

Can you tell me what the problem could be? If I run expense.getUsers() before s.createExpense(expense), I can see the several ExpenseUser correctly.

namaggarwal commented 1 year ago

Hi,

Apologies for late reply. May I know if you did resolve the issue.

RitaSousa09 commented 1 year ago

Hello,

No problem. Unfortunately, not.

namaggarwal commented 1 year ago

Hi,

I tried with this script and it works

expense = Expense()
expense.setCost('10')
expense.setDescription("Testing")
expense.setCurrencyCode("USD")

user1 = ExpenseUser()
user1.setId(79774)
user1.setPaidShare('10.00')
user1.setOwedShare('2.0')

user2 = ExpenseUser()
user2.setId(33497394)
user2.setPaidShare('0.00')
user2.setOwedShare('8.00')

users = []
users.append(user1)
users.append(user2)

expense.setUsers(users)

expense, errors = sObj.createExpense(expense)
print(expense.getId())