cozy / cozy-doctypes

The doctypes used in cozy-stack
https://docs.cozy.io/en/cozy-doctypes/docs/
GNU Affero General Public License v3.0
2 stars 28 forks source link

Shared expenses #40

Open ptbrowne opened 6 years ago

ptbrowne commented 6 years ago

The Tricount and Splitwise connectors are bringing shared expenses into the realm of Cozy. For now, they are saved in a format very close to how they are consumed by their respective web-apps. For shared expenses to be interesting from a Cozy point of view, and to be exploitable in the same way by Banks for example, we should have a common format for this kind of expenses.

Here are two examples of shared expenses, one from Tricount and one from Splitwise. I do not have now the time to think of a common format, I am putting this here not to forget :)

com.tricount.expenses

{
  "_id": "5b59918ce0ecdfefb90b76ac17014b5c",
  "addedBy": {
    "email": null,
    "id": 22774410,
    "name": null
  },
  "amount": 5.5,
  "amountOfParts": 1,
  "currency": "€",
  "id": 71467317,
  "name": "fou de pâtisserie",
  "payedBy": {
    "email": null,
    "id": 22774408,
    "name": "Patou"
  },
  "repartition": [
    {
      "amount": -1,
      "amountOfPart": 1,
      "user": {
        "email": null,
        "id": 22774410,
        "name": "Py"
      }
    }
  ],
  "tricountId": 5697832
}

com.splitwise.expenses

{
  "_id": "0f3d1d1e6e66f7a4ace61081f30377e4",
  "category": {
    "id": 18,
    "name": "Général"
  },
  "comments_count": 0,
  "cost": "22.0",
  "created_at": "2017-11-07T08:54:03Z",
  "created_by": {
    "first_name": "maureen",
    "id": 999663,
    "last_name": null,
    "picture": {
      "medium": "https://splitwise.s3.amazonaws.com/uploads/user/avatar/999663/medium_P7211233.JPG"
    }
  },
  "creation_method": "split",
  "currency_code": "EUR",
  "date": "2017-11-07T08:53:46Z",
  "deleted_at": null,
  "deleted_by": null,
  "description": "Biocbon",
  "details": "",
  "email_reminder": true,
  "email_reminder_in_advance": null,
  "expense_bundle_id": null,
  "friendship_id": null,
  "group_id": 2468147,
  "id": 279457166,
  "next_repeat": null,
  "payment": false,
  "receipt": {
    "large": null,
    "original": null
  },
  "repayments": [
    {
      "amount": "7.33",
      "from": 975791,
      "to": 999663
    },
    {
      "amount": "7.33",
      "from": 2752687,
      "to": 999663
    }
  ],
  "repeat_interval": "never",
  "repeats": false,
  "transaction_confirmed": false,
  "transaction_id": null,
  "transaction_method": "offline",
  "updated_at": "2017-11-07T08:54:03Z",
  "updated_by": null,
  "users": [
    {
      "net_balance": "-7.33",
      "owed_share": "7.33",
      "paid_share": "0.0",
      "user": {
        "first_name": "paulpeyret",
        "id": 2752687,
        "last_name": null,
        "picture": {
          "medium": "https://splitwise.s3.amazonaws.com/uploads/user/avatar/2752687/medium_e7c65326-4fe5-45c4-aeb5-14e6ff9f2548.jpg"
        }
      },
      "user_id": 2752687
    },
    {
      "net_balance": "14.66",
      "owed_share": "7.34",
      "paid_share": "22.0",
      "user": {
        "first_name": "maureen",
        "id": 999663,
        "last_name": null,
        "picture": {
          "medium": "https://splitwise.s3.amazonaws.com/uploads/user/avatar/999663/medium_P7211233.JPG"
        }
      },
      "user_id": 999663
    },
    {
      "net_balance": "-7.33",
      "owed_share": "7.33",
      "paid_share": "0.0",
      "user": {
        "first_name": "Patrick",
        "id": 975791,
        "last_name": "Browne",
        "picture": {
          "medium": "https://splitwise.s3.amazonaws.com/uploads/user/avatar/975791/medium_2ecb75c1-a460-45ca-a80a-3d6f14c517d4.jpg"
        }
      },
      "user_id": 975791
    }
  ]
}
ptbrowne commented 6 years ago

ping @aenario

fffflo commented 6 years ago

It is easier to give my opinion for splitwise that has more structured data. My idea so far is to be able to interpret data from these providers by using our existing banking doctypes.

To interpret Splitwise : 1) we create a new account in io.cozy.banks.accounts for each user_id : account_id : user_id label : thanks to the first&lastname of the user_id ("Patrick's splitwise") account type : something like "Reimbursements state" balance of the account : net _balance of the user_id

if we want to show the user his own balance in his cozy banks app it means we know wich user_id is the cozynaute.

2) if we want to dig in more in the details, it is possible to create entries in io.cozy.operations attached to the bank account we created. for one user_id : we create one operation for every expense that has a "repayments" with the same user_id in the "from" attribute. amount of the operation : amount in the concerned "repayments" date : date of the expense label : "description"+"cost"+"created by"/"firstname" of the expense

For tricount the repartition is limited to a unique user in the example, which makes it hard for me to understand the structure of the current doc. but the idea would be the same by interpreting the repartition section of the data to begin the creation of bank accounts.