Skip to content

Commit

Permalink
Merge PR #15 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by guewen
  • Loading branch information
OCA-git-bot committed Nov 18, 2019
2 parents f3fb6b1 + c9b5caa commit 5dc22e6
Show file tree
Hide file tree
Showing 43 changed files with 4,853 additions and 40 deletions.
8 changes: 5 additions & 3 deletions connector_jira_tempo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

{
'name': 'JIRA Connector Tempo',
'version': '12.0.1.0.0',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'version': '12.0.2.0.0',
'author':
'Camptocamp, '
'Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Connector',
'depends': [
'connector_jira',
'connector_jira_tempo_base',
'hr_timesheet',
],
'website': 'https://github.com/OCA/connector-jira',
Expand Down
6 changes: 3 additions & 3 deletions connector_jira_tempo/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
-->
<odoo noupdate="1">

<record forcecreate="True" id="ir_cron_jira_sync_jira_tempo_status" model="ir.cron">
<field name="name">JIRA - Sync Timesheet approval status</field>
<record id="ir_cron_jira_sync_tempo_timesheets_approval_status" model="ir.cron">
<field name="name">JIRA - Sync Tempo Timesheet approval status</field>
<field name="model_id" ref="model_jira_backend"/>
<field name="state">code</field>
<field name="code">model.search([])._scheduler_sync_jira_tempo_status()</field>
<field name="code">model.search([])._scheduler_sync_tempo_timesheets_approval_status()</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
Expand Down
13 changes: 13 additions & 0 deletions connector_jira_tempo/migrations/12.0.2.0.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


def migrate(cr, version):
cr.execute(
"""UPDATE ir_model_data
SET
name = 'ir_cron_jira_sync_tempo_timesheets_approval_status',
WHERE
name = 'ir_cron_jira_sync_jira_tempo_status';
"""
)
47 changes: 21 additions & 26 deletions connector_jira_tempo/models/account_analytic_line/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
Expand All @@ -21,42 +22,36 @@ class AccountAnalyticLine(models.Model):
class WorklogAdapter(Component):
_inherit = 'jira.worklog.adapter'

# SPECS
# http://developer.tempo.io/doc/timesheets/api/rest/latest
# the base path must be overridden otherwise
# `_get_url` will give us back a bad path including the std JIRA one
_tempo_api_path_base = '{server}/rest/tempo-timesheets/3/{path}'

def _tempo_get_url(self, path):
return self.client._get_url(path, base=self._tempo_api_path_base)

def read(self, issue_id, worklog_id):
worklog = super().read(issue_id, worklog_id)
if self.env.context.get('jira_worklog_no_tempo_data'):
if self.env.context.get(
'jira_worklog_no_tempo_timesheets_approval_data'):
return worklog
with self.handle_404():
worklog['_timesheet'] = self.tempo_read_approval(worklog)
worklog['_tempo_timesheets_approval'] = \
self.tempo_timesheets_approval_read(worklog)
return worklog

# This one seems useless ATM.
# def tempo_read_worklog(self, worklog):
# url = self._tempo_get_url('worklogs')
# url = self._tempo_timesheets_get_url('worklogs')
# r = self.client._session.get(url, params={'dateFrom': '2018-01-01'})
# return {}

def tempo_read_approval(self, worklog):
username = worklog['author']['name']
url = self._tempo_get_url('timesheet-approval/current')
def tempo_timesheets_approval_read(self, worklog):
url = self._tempo_timesheets_get_url('timesheet-approval/current')
with self.handle_404():
resp = self.client._session.get(url, params={'username': username})
return resp.json()

def tempo_read_status_by_team(self, team_id, period_start):
url = self._tempo_get_url('timesheet-approval')
params = {
'teamId': team_id,
'periodStartDate': period_start
}
response = self.client._session.get(url, params={
'username': worklog['author']['name'],
})
return response.json()

def tempo_timesheets_approval_read_status_by_team(
self, team_id, period_start):
url = self._tempo_timesheets_get_url('timesheet-approval')
with self.handle_404():
resp = self.client._session.get(url, params=params)
return resp.json()
response = self.client._session.get(url, params={
'teamId': team_id,
'periodStartDate': period_start,
})
return response.json()
6 changes: 4 additions & 2 deletions connector_jira_tempo/models/account_analytic_line/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2018 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.addons.connector.components.mapper import mapping
Expand All @@ -9,8 +10,9 @@ class AnalyticLineMapper(Component):
_inherit = 'jira.analytic.line.mapper'

@mapping
def tempo(self, record):
def tempo_timesheets_approval(self, record):
approval = record['_tempo_timesheets_approval']
values = {
'jira_tempo_status': record['_timesheet']['status'],
'jira_tempo_status': approval['status'],
}
return values
13 changes: 9 additions & 4 deletions connector_jira_tempo/models/jira_backend/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models, api
Expand Down Expand Up @@ -36,7 +37,8 @@ class JiraBackend(models.Model):
)

@api.multi
def _scheduler_sync_jira_tempo_status(self, period_start=None):
def _scheduler_sync_tempo_timesheets_approval_status(
self, period_start=None):
"""Synchronize JIRA Tempo timesheet status on Odoo TS lines.
Look up for previous week timesheets and update Odoo status.
Expand All @@ -55,14 +57,17 @@ def _scheduler_sync_jira_tempo_status(self, period_start=None):
# the past week period.
period_start = get_past_week_1st_day()
for backend in self:
backend._sync_jira_tempo_status(period_start)
backend._sync_tempo_timesheets_approval_status(period_start)

def _sync_jira_tempo_status(self, period_start):
def _sync_tempo_timesheets_approval_status(self, period_start):
"""Find users and TS lines and update tempo status."""
team_id = self.jira_company_team_id
with self.work_on('jira.account.analytic.line') as work:
importer = work.component(usage='backend.adapter')
result = importer.tempo_read_status_by_team(team_id, period_start)
result = importer.tempo_timesheets_approval_read_status_by_team(
team_id,
period_start,
)
user_binder = importer.binder_for('jira.res.users')
# Pick the date range from the Tempo period.
# In this way we make sure we affect only the dates we want.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,57 @@ interactions:
X-XSS-Protection: [1; mode=block]
content-length: ['1436']
status: {code: 200, message: ''}
- request:
body: null
headers:
Accept:
- !!binary |
YXBwbGljYXRpb24vanNvbiwqLio7cT0wLjk=
Accept-Encoding:
- !!binary |
Z3ppcCwgZGVmbGF0ZQ==
Cache-Control:
- !!binary |
bm8tY2FjaGU=
Connection:
- !!binary |
a2VlcC1hbGl2ZQ==
Content-Type:
- !!binary |
YXBwbGljYXRpb24vanNvbg==
Cookie:
- !!binary |
YXRsYXNzaWFuLnhzcmYudG9rZW49QjdEUy1PMllVLUlUMDAtTDhGRF9iOGU1YjdkZjcyMGYwMjY5
OWNmZTQyZWRjNjQwODVhOTQyNjNiNzFkX2xpbjsgSlNFU1NJT05JRD1FMDhEMzZFQUI3NTk3NjEx
NjkxQURFODE2MDBERTA3Qw==
User-Agent:
- !!binary |
cHl0aG9uLXJlcXVlc3RzLzIuMjEuMA==
X-Atlassian-Token:
- !!binary |
bm8tY2hlY2s=
method: GET
uri: http://jira:8080/rest/tempo-timesheets/3/worklogs/10000
response:
body: {string: '{"timeSpentSeconds":1200,"dateStarted":"2019-09-02T00:00:00.000","dateCreated":"2019-09-02T12:38:44.000","dateUpdated":"2019-09-02T12:38:44.000","comment":"daily call","self":"http://jira:8080/rest/api/2/tempo-timesheets/3/worklogs/10000","id":10000,"jiraWorklogId":10000,"author":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"updateAuthor":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"issue":{"self":"http://jira:8080/rest/api/2/issue/10000","id":10000,"projectId":10000,"key":"SIMO-1","remainingEstimateSeconds":171600,"issueType":{"name":"Task","iconUrl":"http://jira:8080/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype"},"summary":"testing this thing"},"worklogAttributes":[],"workAttributeValues":[]}'}
headers:
Cache-Control: ['no-cache, no-store, no-transform']
Content-Security-Policy: [frame-ancestors 'self']
Content-Type: [application/json;charset=UTF-8]
Date: ['Thu, 09 May 2019 09:34:08 GMT']
Set-Cookie: [JSESSIONID=03E4CCF463F68701010AD8F3E984F62D; Path=/; HttpOnly]
Transfer-Encoding: [chunked]
Vary: [User-Agent]
X-AREQUESTID: [574x238x1]
X-ASEN: [SEN-L13572467]
X-ASESSIONID: [6j7zw5]
X-AUSERNAME: [sorsi]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Seraph-LoginReason: [OK]
X-XSS-Protection: [1; mode=block]
content-length: ['1757']
status: {code: 200, message: ''}
- request:
body: null
headers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,57 @@ interactions:
X-XSS-Protection: [1; mode=block]
content-length: ['1436']
status: {code: 200, message: ''}
- request:
body: null
headers:
Accept:
- !!binary |
YXBwbGljYXRpb24vanNvbiwqLio7cT0wLjk=
Accept-Encoding:
- !!binary |
Z3ppcCwgZGVmbGF0ZQ==
Cache-Control:
- !!binary |
bm8tY2FjaGU=
Connection:
- !!binary |
a2VlcC1hbGl2ZQ==
Content-Type:
- !!binary |
YXBwbGljYXRpb24vanNvbg==
Cookie:
- !!binary |
YXRsYXNzaWFuLnhzcmYudG9rZW49QjdEUy1PMllVLUlUMDAtTDhGRF9iOGU1YjdkZjcyMGYwMjY5
OWNmZTQyZWRjNjQwODVhOTQyNjNiNzFkX2xpbjsgSlNFU1NJT05JRD1FMDhEMzZFQUI3NTk3NjEx
NjkxQURFODE2MDBERTA3Qw==
User-Agent:
- !!binary |
cHl0aG9uLXJlcXVlc3RzLzIuMjEuMA==
X-Atlassian-Token:
- !!binary |
bm8tY2hlY2s=
method: GET
uri: http://jira:8080/rest/tempo-timesheets/3/worklogs/10000
response:
body: {string: '{"timeSpentSeconds":1200,"dateStarted":"2019-09-02T00:00:00.000","dateCreated":"2019-09-02T12:38:44.000","dateUpdated":"2019-09-02T12:38:44.000","comment":"daily call","self":"http://jira:8080/rest/api/2/tempo-timesheets/3/worklogs/10000","id":10000,"jiraWorklogId":10000,"author":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"updateAuthor":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"issue":{"self":"http://jira:8080/rest/api/2/issue/10000","id":10000,"projectId":10000,"key":"SIMO-1","remainingEstimateSeconds":171600,"issueType":{"name":"Task","iconUrl":"http://jira:8080/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype"},"summary":"testing this thing"},"worklogAttributes":[],"workAttributeValues":[]}'}
headers:
Cache-Control: ['no-cache, no-store, no-transform']
Content-Security-Policy: [frame-ancestors 'self']
Content-Type: [application/json;charset=UTF-8]
Date: ['Thu, 09 May 2019 09:34:08 GMT']
Set-Cookie: [JSESSIONID=03E4CCF463F68701010AD8F3E984F62D; Path=/; HttpOnly]
Transfer-Encoding: [chunked]
Vary: [User-Agent]
X-AREQUESTID: [574x238x1]
X-ASEN: [SEN-L13572467]
X-ASESSIONID: [6j7zw5]
X-AUSERNAME: [sorsi]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Seraph-LoginReason: [OK]
X-XSS-Protection: [1; mode=block]
content-length: ['1757']
status: {code: 200, message: ''}
- request:
body: null
headers:
Expand Down Expand Up @@ -1624,6 +1675,57 @@ interactions:
X-XSS-Protection: [1; mode=block]
content-length: ['1439']
status: {code: 200, message: ''}
- request:
body: null
headers:
Accept:
- !!binary |
YXBwbGljYXRpb24vanNvbiwqLio7cT0wLjk=
Accept-Encoding:
- !!binary |
Z3ppcCwgZGVmbGF0ZQ==
Cache-Control:
- !!binary |
bm8tY2FjaGU=
Connection:
- !!binary |
a2VlcC1hbGl2ZQ==
Content-Type:
- !!binary |
YXBwbGljYXRpb24vanNvbg==
Cookie:
- !!binary |
YXRsYXNzaWFuLnhzcmYudG9rZW49QjdEUy1PMllVLUlUMDAtTDhGRF9iOGU1YjdkZjcyMGYwMjY5
OWNmZTQyZWRjNjQwODVhOTQyNjNiNzFkX2xpbjsgSlNFU1NJT05JRD1FMDhEMzZFQUI3NTk3NjEx
NjkxQURFODE2MDBERTA3Qw==
User-Agent:
- !!binary |
cHl0aG9uLXJlcXVlc3RzLzIuMjEuMA==
X-Atlassian-Token:
- !!binary |
bm8tY2hlY2s=
method: GET
uri: http://jira:8080/rest/tempo-timesheets/3/worklogs/10001
response:
body: {string: '{"timeSpentSeconds":1200,"dateStarted":"2019-09-02T00:00:00.000","dateCreated":"2019-09-02T12:38:44.000","dateUpdated":"2019-09-02T12:38:44.000","comment":"daily call","self":"http://jira:8080/rest/api/2/tempo-timesheets/3/worklogs/10001","id":10000,"jiraWorklogId":10000,"author":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"updateAuthor":{"self":"http://jira:8080/rest/api/2/user?username=sorsi","name":"sorsi","key":"sorsi","emailAddress":"simone.orsi@camptocamp.com","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/70277b85d2dd0aa7368c6b803836808e?d=mm&s=32"},"displayName":"simone.orsi@camptocamp.com","active":true,"timeZone":"GMT"},"issue":{"self":"http://jira:8080/rest/api/2/issue/10001","id":10000,"projectId":10000,"key":"SIMO-1","remainingEstimateSeconds":171600,"issueType":{"name":"Task","iconUrl":"http://jira:8080/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype"},"summary":"testing this thing"},"worklogAttributes":[],"workAttributeValues":[]}'}
headers:
Cache-Control: ['no-cache, no-store, no-transform']
Content-Security-Policy: [frame-ancestors 'self']
Content-Type: [application/json;charset=UTF-8]
Date: ['Thu, 09 May 2019 09:34:08 GMT']
Set-Cookie: [JSESSIONID=03E4CCF463F68701010AD8F3E984F62D; Path=/; HttpOnly]
Transfer-Encoding: [chunked]
Vary: [User-Agent]
X-AREQUESTID: [574x238x1]
X-ASEN: [SEN-L13572467]
X-ASESSIONID: [6j7zw5]
X-AUSERNAME: [sorsi]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Seraph-LoginReason: [OK]
X-XSS-Protection: [1; mode=block]
content-length: ['1757']
status: {code: 200, message: ''}
- request:
body: null
headers:
Expand Down

0 comments on commit 5dc22e6

Please sign in to comment.