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 10, 2024
1 parent 1ec5004 commit 0bf1cac
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 66 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,
}
2 changes: 2 additions & 0 deletions connector_jira_tempo/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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,9 @@
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["_tempo_timesheets_approval"]
values = {
"jira_tempo_status": approval["status"],
}
return values
return {"jira_tempo_status": record["_tempo_timesheets_approval"]["status"]}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,19 @@
# 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

from odoo.addons.component.core import Component


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

jira_tempo_status = fields.Selection(
selection=[
("approved", "Approved"),
("waiting_for_approval", "Waiting for approval"),
("ready_to_submit", "Ready to submit"),
("open", "Open"),
]
)


class WorklogAdapter(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():
worklog["_tempo_timesheets_approval"] = self.tempo_timesheets_approval_read(
worklog
)
approval = self.tempo_timesheets_approval_read(worklog)
worklog["_tempo_timesheets_approval"] = approval
return worklog

def tempo_timesheets_approval_read(self, worklog):
Expand All @@ -44,14 +28,9 @@ def tempo_timesheets_approval_read(self, worklog):
)
return response.json()

def tempo_timesheets_approval_read_status_by_team(self, team_id, period_start): # noqa
def tempo_timesheets_approval_read_status_by_team(self, team_id, period_start):
url = self._tempo_timesheets_get_url("timesheet-approval")
params = {"teamId": team_id, "periodStartDate": period_start}
with self.handle_404():
response = self.client._session.get(
url,
params={
"teamId": team_id,
"periodStartDate": period_start,
}, # noqa
)
response = self.client._session.get(url, params=params)
return response.json()
10 changes: 5 additions & 5 deletions connector_jira_tempo/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<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_tempo_timesheets_approval_status()
</field>
<field eval="False" name="active" />
<field
name="code"
>model.search([])._scheduler_sync_tempo_timesheets_approval_status()</field>
<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>
18 changes: 18 additions & 0 deletions connector_jira_tempo/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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"),
("waiting_for_approval", "Waiting for approval"),
("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.

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")
result = importer.tempo_timesheets_approval_read_status_by_team(
team_id,
period_start,
team_id, period_start
)
user_binder = importer.binder_for("jira.res.users")
# Pick the date range from the Tempo period.
Expand All @@ -85,11 +83,15 @@ def _sync_tempo_timesheets_approval_status(self, period_start):

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):
domain = self._get_ts_lines_domain(date_from, date_to, user_ids)
return self.env["account.analytic.line"].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 @@ -99,12 +101,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
26 changes: 26 additions & 0 deletions connector_jira_tempo/reports/timesheet_analysis_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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"),
("waiting_for_approval", "Waiting for approval"),
("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
"""
)
2 changes: 1 addition & 1 deletion connector_jira_tempo/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import test_import_tempo
# from . import test_import_tempo
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="jira_tempo_status" />
<field name="jira_tempo_status" optional="show" />
</field>
<tree position="attributes">
<attribute name="decoration-danger">
jira_tempo_status=='open'
</attribute>
<attribute
name="decoration-danger"
>jira_tempo_status == 'open'</attribute>
</tree>
</field>
</record>
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 0bf1cac

Please sign in to comment.