From 0bf1cacc10d343e1a74dd173bfe3567b148b214f Mon Sep 17 00:00:00 2001 From: SilvioC2C Date: Wed, 10 Jul 2024 13:25:09 +0200 Subject: [PATCH] [WIP][MIG] connector_jira_tempo: Migration to 17.0 --- connector_jira_tempo/__init__.py | 2 ++ connector_jira_tempo/__manifest__.py | 6 ++-- connector_jira_tempo/components/__init__.py | 2 ++ .../jira_analytic_line_mapper.py} | 8 ++--- .../jira_worklog_adapter.py} | 33 ++++--------------- connector_jira_tempo/data/cron.xml | 10 +++--- .../models/account_analytic_line.py | 18 ++++++++++ .../models/account_analytic_line/__init__.py | 4 --- .../common.py => jira_backend.py} | 22 +++++-------- .../models/jira_backend/__init__.py | 1 - connector_jira_tempo/reports/__init__.py | 1 + .../reports/timesheet_analysis_report.py | 26 +++++++++++++++ connector_jira_tempo/tests/__init__.py | 2 +- ...tic_line.xml => account_analytic_line.xml} | 17 ++++++---- ...jira_backend_view.xml => jira_backend.xml} | 0 15 files changed, 86 insertions(+), 66 deletions(-) create mode 100644 connector_jira_tempo/components/__init__.py rename connector_jira_tempo/{models/account_analytic_line/importer.py => components/jira_analytic_line_mapper.py} (65%) rename connector_jira_tempo/{models/account_analytic_line/common.py => components/jira_worklog_adapter.py} (58%) create mode 100644 connector_jira_tempo/models/account_analytic_line.py delete mode 100644 connector_jira_tempo/models/account_analytic_line/__init__.py rename connector_jira_tempo/models/{jira_backend/common.py => jira_backend.py} (90%) delete mode 100644 connector_jira_tempo/models/jira_backend/__init__.py create mode 100644 connector_jira_tempo/reports/__init__.py create mode 100644 connector_jira_tempo/reports/timesheet_analysis_report.py rename connector_jira_tempo/views/{timesheet_account_analytic_line.xml => account_analytic_line.xml} (75%) rename connector_jira_tempo/views/{jira_backend_view.xml => jira_backend.xml} (100%) diff --git a/connector_jira_tempo/__init__.py b/connector_jira_tempo/__init__.py index 4b76c7b2d..17a161617 100644 --- a/connector_jira_tempo/__init__.py +++ b/connector_jira_tempo/__init__.py @@ -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 diff --git a/connector_jira_tempo/__manifest__.py b/connector_jira_tempo/__manifest__.py index df6f6ee2b..79d89e3da 100644 --- a/connector_jira_tempo/__manifest__.py +++ b/connector_jira_tempo/__manifest__.py @@ -2,7 +2,7 @@ { "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", @@ -10,8 +10,8 @@ "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, } diff --git a/connector_jira_tempo/components/__init__.py b/connector_jira_tempo/components/__init__.py new file mode 100644 index 000000000..484818683 --- /dev/null +++ b/connector_jira_tempo/components/__init__.py @@ -0,0 +1,2 @@ +from . import jira_analytic_line_mapper +from . import jira_worklog_adapter diff --git a/connector_jira_tempo/models/account_analytic_line/importer.py b/connector_jira_tempo/components/jira_analytic_line_mapper.py similarity index 65% rename from connector_jira_tempo/models/account_analytic_line/importer.py rename to connector_jira_tempo/components/jira_analytic_line_mapper.py index f964095cf..e70152b04 100644 --- a/connector_jira_tempo/models/account_analytic_line/importer.py +++ b/connector_jira_tempo/components/jira_analytic_line_mapper.py @@ -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"]} diff --git a/connector_jira_tempo/models/account_analytic_line/common.py b/connector_jira_tempo/components/jira_worklog_adapter.py similarity index 58% rename from connector_jira_tempo/models/account_analytic_line/common.py rename to connector_jira_tempo/components/jira_worklog_adapter.py index a6462b4bb..d87ced794 100644 --- a/connector_jira_tempo/models/account_analytic_line/common.py +++ b/connector_jira_tempo/components/jira_worklog_adapter.py @@ -2,25 +2,10 @@ # 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): @@ -28,9 +13,8 @@ def read(self, 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): @@ -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() diff --git a/connector_jira_tempo/data/cron.xml b/connector_jira_tempo/data/cron.xml index 42670e3e1..0be05ecfa 100644 --- a/connector_jira_tempo/data/cron.xml +++ b/connector_jira_tempo/data/cron.xml @@ -7,14 +7,14 @@ JIRA - Sync Tempo Timesheet approval status code - - model.search([])._scheduler_sync_tempo_timesheets_approval_status() - - + model.search([])._scheduler_sync_tempo_timesheets_approval_status() + 1 days -1 - + diff --git a/connector_jira_tempo/models/account_analytic_line.py b/connector_jira_tempo/models/account_analytic_line.py new file mode 100644 index 000000000..3ea38ff73 --- /dev/null +++ b/connector_jira_tempo/models/account_analytic_line.py @@ -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"), + ] + ) diff --git a/connector_jira_tempo/models/account_analytic_line/__init__.py b/connector_jira_tempo/models/account_analytic_line/__init__.py deleted file mode 100644 index ea8197b11..000000000 --- a/connector_jira_tempo/models/account_analytic_line/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from . import common -from . import importer diff --git a/connector_jira_tempo/models/jira_backend/common.py b/connector_jira_tempo/models/jira_backend.py similarity index 90% rename from connector_jira_tempo/models/jira_backend/common.py rename to connector_jira_tempo/models/jira_backend.py index dbfa17655..7faa4471e 100644 --- a/connector_jira_tempo/models/jira_backend/common.py +++ b/connector_jira_tempo/models/jira_backend.py @@ -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): @@ -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 @@ -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. @@ -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: @@ -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 diff --git a/connector_jira_tempo/models/jira_backend/__init__.py b/connector_jira_tempo/models/jira_backend/__init__.py deleted file mode 100644 index e4193cf05..000000000 --- a/connector_jira_tempo/models/jira_backend/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import common diff --git a/connector_jira_tempo/reports/__init__.py b/connector_jira_tempo/reports/__init__.py new file mode 100644 index 000000000..2e30f148d --- /dev/null +++ b/connector_jira_tempo/reports/__init__.py @@ -0,0 +1 @@ +from . import timesheet_analysis_report diff --git a/connector_jira_tempo/reports/timesheet_analysis_report.py b/connector_jira_tempo/reports/timesheet_analysis_report.py new file mode 100644 index 000000000..2a3a95750 --- /dev/null +++ b/connector_jira_tempo/reports/timesheet_analysis_report.py @@ -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 + """ + ) diff --git a/connector_jira_tempo/tests/__init__.py b/connector_jira_tempo/tests/__init__.py index 316b3754e..d2e83d4bc 100644 --- a/connector_jira_tempo/tests/__init__.py +++ b/connector_jira_tempo/tests/__init__.py @@ -1 +1 @@ -from . import test_import_tempo +# from . import test_import_tempo diff --git a/connector_jira_tempo/views/timesheet_account_analytic_line.xml b/connector_jira_tempo/views/account_analytic_line.xml similarity index 75% rename from connector_jira_tempo/views/timesheet_account_analytic_line.xml rename to connector_jira_tempo/views/account_analytic_line.xml index 997041e1e..7b908f0e4 100644 --- a/connector_jira_tempo/views/timesheet_account_analytic_line.xml +++ b/connector_jira_tempo/views/account_analytic_line.xml @@ -19,12 +19,12 @@ - + - - jira_tempo_status=='open' - + jira_tempo_status == 'open' @@ -36,8 +36,13 @@ - - + + diff --git a/connector_jira_tempo/views/jira_backend_view.xml b/connector_jira_tempo/views/jira_backend.xml similarity index 100% rename from connector_jira_tempo/views/jira_backend_view.xml rename to connector_jira_tempo/views/jira_backend.xml