Skip to content

Commit

Permalink
[WIP][MIG] connector_jira_tempo: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SilvioC2C committed Jul 11, 2024
1 parent 3d2104a commit 2dd16be
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 96 deletions.
2 changes: 2 additions & 0 deletions connector_jira_tempo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import components
from . import models
from . import reports
6 changes: 3 additions & 3 deletions connector_jira_tempo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

{
"name": "JIRA Connector Tempo",
"version": "15.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Connector",
"depends": ["connector_jira_tempo_base", "hr_timesheet"],
"website": "https://github.com/OCA/connector-jira",
"data": [
"data/cron.xml",
"views/jira_backend_view.xml",
"views/timesheet_account_analytic_line.xml",
"views/account_analytic_line.xml",
"views/jira_backend.xml",
],
"installable": True,
}
4 changes: 4 additions & 0 deletions connector_jira_tempo/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import jira_analytic_line_mapper
from . import jira_worklog_adapter
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
from odoo.addons.connector.components.mapper import mapping


class AnalyticLineMapper(Component):
class JiraAnalyticLineMapper(Component):
_inherit = "jira.analytic.line.mapper"

@mapping
def tempo_timesheets_approval(self, record):
approval = record.get("_tempo_timesheets_approval", {"status": {"key": "OPEN"}})
values = {
"jira_tempo_status": approval["status"]["key"].lower(),
}
return values
return {"jira_tempo_status": approval["status"]["key"].lower()}
32 changes: 32 additions & 0 deletions connector_jira_tempo/components/jira_worklog_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2019 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import datetime
import json

from odoo.addons.component.core import Component


class JiraWorklogAdapter(Component):
_inherit = "jira.worklog.adapter"

def read(self, issue_id, worklog_id):
worklog = super().read(issue_id, worklog_id)
if self.env.context.get("jira_worklog_no_tempo_timesheets_approval_data"):
return worklog
with self.handle_404():
approval = self.tempo_timesheets_approval_read(worklog)
worklog["_tempo_timesheets_approval"] = approval
return worklog

def tempo_timesheets_approval_read(self, worklog):
backend = self._tempo_timesheets_get_webservice()
account_id = worklog["author"]["accountId"]
period_start = datetime.date.today().isoformat()
endpoint = f"timesheet-approvals/user/{account_id}?from={period_start}"
return json.loads(backend.call("get", url_params={"endpoint": endpoint}))

def tempo_timesheets_approval_read_status_by_team(self, team_id, period_start):
backend = self._tempo_timesheets_get_webservice()
endpoint = f"timesheet-approvals/team/{team_id}?from={period_start}"
return json.loads(backend.call("get", url_params={"endpoint": endpoint}))
4 changes: 2 additions & 2 deletions connector_jira_tempo/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<field name="code">
model.search([])._scheduler_sync_tempo_timesheets_approval_status()
</field>
<field eval="False" name="active" />
<field name="active" eval="False" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field name="doall" eval="False" />
</record>
</odoo>
21 changes: 21 additions & 0 deletions connector_jira_tempo/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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


class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"

jira_tempo_status = fields.Selection(
selection=[
("approved", "Approved"),
("in_review", "In Review"),
# no longer used on cloud version
("waiting_for_approval", "Waiting for approval"),
# no longer used on cloud version
("ready_to_submit", "Ready to submit"),
("open", "Open"),
]
)
4 changes: 0 additions & 4 deletions connector_jira_tempo/models/account_analytic_line/__init__.py

This file was deleted.

62 changes: 0 additions & 62 deletions connector_jira_tempo/models/account_analytic_line/common.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

def get_past_week_1st_day():
today = datetime.today()
date = today - timedelta(days=today.weekday() % 7) - timedelta(weeks=1)
return date.strftime("%Y-%m-%d")
return (today - timedelta(weeks=1, days=today.weekday() % 7)).strftime("%Y-%m-%d")


class JiraBackend(models.Model):
Expand Down Expand Up @@ -47,7 +46,7 @@ def _scheduler_sync_tempo_timesheets_approval_status(self, period_start=None):
if period_start is None:
# NOTE: it seems that the preciseness of this date
# is not really important.
# If you don't pass the very begin date of the period
# If you don't pass the very beginning date of the period
# but a date in the middle, the api will give you back
# the right period range matching that date.
# Still, we want to put clear that we want to retrieve
Expand All @@ -62,8 +61,7 @@ def _sync_tempo_timesheets_approval_status(self, period_start):
with self.work_on("jira.account.analytic.line") as work:
importer = work.component(usage="backend.adapter")
response = importer.tempo_timesheets_approval_read_status_by_team(
team_id,
period_start,
team_id, period_start
)
user_binder = importer.binder_for("jira.res.users")
mapping = defaultdict(list)
Expand All @@ -76,18 +74,22 @@ def _sync_tempo_timesheets_approval_status(self, period_start):
except ValueError:
_logger.error("User %s not found", user_data)
continue
status = result["status"]["key"].lower()
mapping[(date_from, date_to, status)].append(user.id)
mapping[(date_from, date_to, result["status"]["key"].lower())] += [user.id]
for (date_from, date_to, state), user_ids in mapping.items():
self._update_ts_line_status(date_from, date_to, state, user_ids)

def _update_ts_line_status(self, date_from, date_to, state, user_ids):
lines = self._get_ts_lines(date_from, date_to, user_ids)
lines.mapped("jira_bind_ids").write({"jira_tempo_status": state})
lines.jira_bind_ids.write({"jira_tempo_status": state})
self._validate_ts(date_from, date_to, state, user_ids)

def _get_ts_lines(self, date_from, date_to, user_ids):
ts_line_model = self.env["account.analytic.line"]
domain = self._get_ts_lines_domain(date_from, date_to, user_ids)
return ts_line_model.search(domain)

def _get_ts_lines_domain(self, date_from, date_to, user_ids):
domain = [
return [
# TODO: any better filter here?
# `is_timesheet` is not available since we don't use ts_grid
# But `is_timesheet` is a computed field with value:
Expand All @@ -97,12 +99,6 @@ def _get_ts_lines_domain(self, date_from, date_to, user_ids):
("date", "<=", date_to),
("user_id", "in", user_ids),
]
return domain

def _get_ts_lines(self, date_from, date_to, user_ids):
ts_line_model = self.env["account.analytic.line"]
domain = self._get_ts_lines_domain(date_from, date_to, user_ids)
return ts_line_model.search(domain)

def _validate_ts(self, date_from, date_to, state, user_ids):
# hook here and do what you want depending on the state
Expand Down
1 change: 0 additions & 1 deletion connector_jira_tempo/models/jira_backend/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions connector_jira_tempo/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import timesheet_analysis_report
24 changes: 24 additions & 0 deletions connector_jira_tempo/reports/timesheet_analysis_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class TimesheetsAnalysisReport(models.Model):
_inherit = "timesheets.analysis.report"

jira_tempo_status = fields.Selection(
selection=[
("approved", "Approved"),
("in_review", "In Review"),
# no longer used on cloud version
("waiting_for_approval", "Waiting for approval"),
# no longer used on cloud version
("ready_to_submit", "Ready to submit"),
("open", "Open"),
],
readonly=True,
)

@api.model
def _select(self):
return super()._select() + ", A.jira_tempo_status AS jira_tempo_status"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form" />
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="jira_tempo_status" />
<field name="jira_tempo_status" optional="show" />
</field>
</field>
</record>
Expand All @@ -23,7 +23,7 @@
</field>
<tree position="attributes">
<attribute name="decoration-danger">
jira_tempo_status=='open'
jira_tempo_status == 'open'
</attribute>
</tree>
</field>
Expand All @@ -36,8 +36,13 @@
<field name="task_id" position="after">
<field name="jira_tempo_status" />
</field>
<filter name="groupby_date" position="after">
<field name="jira_tempo_status" />
<filter name="groupby_employee" position="after">
<filter
string="Jira Tempo Status"
name="groupby_jira_tempo_status"
domain="[]"
context="{'group_by': 'jira_tempo_status'}"
/>
</filter>
</field>
</record>
Expand Down
File renamed without changes.

0 comments on commit 2dd16be

Please sign in to comment.