An open API service indexing awesome lists of open source software.

https://github.com/jankaritech/openprojecttmetricintegration

Tool to sync time entries between tmetric and OpenProject
https://github.com/jankaritech/openprojecttmetricintegration

openproject time-tracker tmetric

Last synced: 10 months ago
JSON representation

Tool to sync time entries between tmetric and OpenProject

Awesome Lists containing this project

README

          

# Preparation
## As the admin
There are some steps that need to be done as the tmetric admin and the OpenProject admin.

### tmetric
- get the client ID by selecting the client, whose data you want to sync with OpenProject, from Manage->Clients and copying the last number from the URL. For example, if the URL is `https://app.tmetric.com/#/account/12345/clients/67890`, the client ID is `67890`.
- create a dummy project. You can give it any name you like. No time will be logged to this project, but it's needed to create links to OpenProject.
- get the ID of the dummy project. For example, if the URL is `https://app.tmetric.com/#/account/12345/projects/989898` the project ID is `989898`.
- create work types. The names of the Work Types **must match** the names of the time tracking activities in OpenProject.
- assign the work types to the project which data you want to sync to OpenProject.
- create a tag called `transferred-to-openproject`. This tag will be used to mark time entries that have been transferred to OpenProject.

### OpenProject
- enable the 'Time and costs' module for the projects you want to sync with tmetric

## As the user
### get tokens
#### OpenProject
- go to your profile (by clicking on your avatar in the top right corner)
- click on `My account`
- click on `Access tokens`
- click on `+ API token`
- give the token a name and click on `Create`
- copy the token

#### t-metric
- go to your profile (by clicking on your avatar in the top right corner)
- click on `Profile Settings`
- click on `Get new API token`
- copy the token

### configure

in your home folder create a file called `.OpenProjectTmetricIntegration.yaml` with the following content (enter your tokens):

```yaml
openproject:
url: 'https://community.openproject.org'
token:
tmetric:
token:
clientId:
dummyProjectId:
```

### run

#### check and fix the time entries in tmetric
```bash
go run main.go check tmetric
```

The tool with show you any invalid or inconsistent time entries and ask you for data to fix them.
This step will only adjust data on tmetric, no data will be written to OpenProject.

#### transfer the time entries to OpenProject
```bash
go run main.go copy
```

This will copy the time entries from tmetric to OpenProject. The time entries will be marked with the tag `transferred-to-openproject` in tmetric. Any entry that already has this tag will be skipped.

#### validate if the data in tmetric and OpenProject is consistent
```bash
go run main.go diff
```
This will show you a table with the time entries in both systems and if there is any difference in the logged time per day. Check if the data is correct.

1. If some data is in tmetric but not in OpenProject, run the `copy` command again.
2. If some data is in OpenProject but not in tmetric, delete or edit it in OpenProject. To do so use the [cost-report feature](https://www.openproject.org/docs/user-guide/time-and-costs/reporting/).
3. If you want to sync data again from tmetric to OpenProject, remove the `transferred-to-openproject` tag from the time entries in tmetric. **This will create new entries in OpenProject and by that might lead to duplication.**

#### export data
Data can be exported using the [Go template system](https://pkg.go.dev/text/template). This is useful e.g. to generate an invoice.
First create a template file and then run:

```bash
go run main.go export --template template.tmpl
```

- **DetailedReport** with parameters: `clientName string, tagName string, groupName string`. Gets a detailed report from t-metric and returns a `tmetric.Report` object.
- **AllWorkTypes**. Gets all possible work types from t-metric and returns an array of `tmetric.Tag`
- **AllTeams**. Gets all teams from t-metric and returns an array of `tmetric.Team`
- **ServiceDate**. Returns the month of the `--start` date for the export in the format `01/2006`
- **AllTimeEntriesFromOpenProject** with parameter `user string`. Gets all time entries for that user from OpenProject and returns an array of `openproject.TimeEntry`
- **ArbitraryString** with parameter `i int`. Gets the data of the `arbitraryString` command line flag. Useful e.g. to add an invoice number.
- **formatFloat** with parameters `f float64, decimalSeparator string (optional)`. Formats the float value to `%.2f` with that given separator.
- all functions from [spring](https://masterminds.github.io/sprig/)

#### work for a specific time period
By default, the script will work with the current calendar month, but the start and end date can be configured with the `--start` and `--end` flags. The date format is `YYYY-MM-DD`.