Skip to content

Commit

Permalink
[WIP][MIG] connector_jira_servicedesk: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SilvioC2C committed Jul 9, 2024
1 parent 291b3c0 commit adb0992
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 304 deletions.
2 changes: 2 additions & 0 deletions connector_jira_servicedesk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import components
from . import models
from . import wizards
8 changes: 4 additions & 4 deletions connector_jira_servicedesk/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

{
"name": "JIRA Connector - Service Desk Extension",
"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"],
"website": "https://github.com/OCA/connector-jira",
"data": [
"views/jira_backend_views.xml",
"views/project_project_views.xml",
"views/project_link_jira_views.xml",
"security/ir.model.access.csv",
"views/jira_backend.xml",
"views/jira_project_project.xml",
"wizards/project_link_jira.xml",
],
"installable": True,
}
8 changes: 8 additions & 0 deletions connector_jira_servicedesk/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from . import jira_analytic_line_importer
from . import jira_organization_adapter
from . import jira_organization_batch_importer
from . import jira_organization_from_task
from . import jira_organization_mapper
from . import jira_project_binder
from . import jira_project_task_importer
from . import jira_task_project_matcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019-2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component


class JiraAnalyticLineImporter(Component):
_inherit = "jira.analytic.line.importer"

@property
def _issue_fields_to_read(self):
org_fname = self.backend_record.organization_field_name
return super()._issue_fields_to_read + ([org_fname] if org_fname else [])
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class Organization(Resource):
"""A Service Desk Organization."""

def __init__(self, options, session, raw=None):
super().__init__(
"organization/{0}", options, session, "{server}/rest/servicedeskapi/{path}"
)
base_url = "{server}/rest/servicedeskapi/{path}"
super().__init__("organization/{0}", options, session, base_url)
if raw:
self._parse_raw(raw)

Expand All @@ -33,7 +32,7 @@ class OrganizationAdapter(Component):
_apply_on = ["jira.organization"]

# The Service Desk REST API returns an error if this header
# is not used. The API may change so they want an agreement for
# is not used. The API may change, so they want an agreement for
# the client about this.
_desk_headers = CaseInsensitiveDict({"X-ExperimentalApi": "opt-in"})

Expand All @@ -54,20 +53,15 @@ def search(self):
# A GET on the REST API returns only one page with the
# first 50 rows. Fetch all pages.
orgs = []
start = 0
while True:
# 50 items per page is the maximum allowed by Jira
start, end = 0, 50
result = {}
while not result.get("isLastPage"):
result = self.client._get_json(
"organization",
params={
"start": start,
# 50 items per page is the maximum allowed by Jira
"limit": start + 50,
},
params={"start": start, "limit": end},
base=self._desk_api_path_base,
)
start += 50
start, end = end, end + 50
orgs += result["values"]
if result["isLastPage"]:
break

return orgs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component
from odoo.addons.connector.components.mapper import mapping


class OrganizationMapper(Component):
_name = "jira.organization.mapper"
_inherit = ["jira.import.mapper"]
_apply_on = "jira.organization"

direct = [
("name", "name"),
]

@mapping
def backend_id(self, record):
return {"backend_id": self.backend_record.id}


class OrganizationBatchImporter(Component):
class JiraOrganizationBatchImporter(Component):
"""Import the Jira Organizations
For every id in in the list of organizations, a direct import is done.
Expand All @@ -31,6 +16,5 @@ class OrganizationBatchImporter(Component):

def run(self):
"""Run the synchronization"""
records = self.backend_adapter.search()
for record in records:
for record in self.backend_adapter.search():
self._import_record(record["id"], record=record)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-Today Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component


class JiraOrganizationsFromTask(Component):
_name = "jira.organization.from.task"
_inherit = ["jira.base"]
_usage = "organization.from.task"

def get_jira_org_ids(self, jira_task_data):
if fields := jira_task_data.get("fields", {}):
if org_fname := self.backend_record.organization_field_name:
if recs := fields.get(org_fname):
return [r["id"] for r in recs]
return []
17 changes: 17 additions & 0 deletions connector_jira_servicedesk/components/jira_organization_mapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component
from odoo.addons.connector.components.mapper import mapping


class OrganizationMapper(Component):
_name = "jira.organization.mapper"
_inherit = ["jira.import.mapper"]
_apply_on = "jira.organization"

direct = [("name", "name")]

@mapping
def backend_id(self, record):
return {"backend_id": self.backend_record.id}
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,25 @@ def to_internal(self, external_id, unwrap=False, organizations=None):
(self._backend_field, "=", self.backend_record.id),
]
if not organizations:
domain.append(
("organization_ids", "=", False),
)
domain.append(("organization_ids", "=", False))
candidates = self.model.with_context(active_test=False).search(domain)
if organizations:
fallback = self.model.browse()
binding = self.model.browse()
for candidate in candidates:
# No organization set on candidate: use it as fallback
if not candidate.organization_ids:
fallback = candidate
continue

if organizations in candidate.organization_ids:
# All organizations are included in the candidate's organizations: it's
# the binding we were looking for
elif organizations <= candidate.organization_ids:
binding = candidate
break
if not binding:
# No feasible candidate found: use fallback
else:
binding = fallback
else:
# No organization set: all candidates are feasible
binding = candidates

if not binding:
if unwrap:
return self.model.browse()[self._odoo_field]
return self.model.browse()

binding.ensure_one()
if unwrap:
binding = binding[self._odoo_field]
return binding
# Binding must be exactly 1
binding = (binding and binding.ensure_one()) or self.model.browse()
return binding[self._odoo_field] if unwrap else binding
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-Today Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component


class JiraProjectTaskImporter(Component):
_inherit = "jira.project.task.importer"

def _import_dependencies(self):
# OVERRIDE: import organizations
res = super()._import_dependencies()
for jorg_id in self.component(usage="organization.from.task").get_jira_org_ids(
self.external_record
):
self._import_dependency(jorg_id, "jira.organization")
return res
20 changes: 20 additions & 0 deletions connector_jira_servicedesk/components/jira_task_project_matcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2016-Today Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component


class JiraTaskProjectMatcher(Component):
_inherit = "jira.task.project.matcher"

def find_project_binding(self, jira_task_data, unwrap=False):
component = self.component(usage="organization.from.task")
binder = self.binder_for("jira.organization")
org_ids = set()
for j_org_id in component.get_jira_org_ids(jira_task_data):
org_ids.update(binder.to_internal(j_org_id).ids)
return self.binder_for("jira.project.project").to_internal(
jira_task_data["fields"]["project"]["id"],
unwrap=unwrap,
organizations=self.env["jira.organization"].browse(org_ids),
)
5 changes: 3 additions & 2 deletions connector_jira_servicedesk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import account_analytic_line
from . import jira_account_analytic_line
from . import jira_backend
from . import project_project
from . import jira_organization
from . import project_task
from . import jira_project_base_mixin
from . import jira_project_project
22 changes: 22 additions & 0 deletions connector_jira_servicedesk/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2020-2021 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, fields, models


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

jira_servicedesk_issue_url = fields.Char(
string="Original JIRA service desk issue Link",
compute="_compute_jira_servicedesk_issue_url",
)

@api.depends("jira_bind_ids.jira_servicedesk_issue_url")
def _compute_jira_servicedesk_issue_url(self):
"""Compute the service desk references to JIRA.
We assume that we have only one external record for a line
"""
for record in self:
bind = record.jira_bind_ids[:1]
record.jira_servicedesk_issue_url = bind.jira_servicedesk_issue_url or ""

This file was deleted.

48 changes: 0 additions & 48 deletions connector_jira_servicedesk/models/account_analytic_line/common.py

This file was deleted.

This file was deleted.

22 changes: 22 additions & 0 deletions connector_jira_servicedesk/models/jira_account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2020-2021 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, fields, models


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

jira_servicedesk_issue_url = fields.Char(
string="Original JIRA service desk issue Link",
compute="_compute_jira_servicedesk_issue_url",
)

@api.depends("jira_issue_key", "project_id.jira_bind_ids")
def _compute_jira_servicedesk_issue_url(self):
"""Compute the external URL to JIRA service desk."""
for record in self:
url = ""
if jira_key := record.jira_issue_key:
if jira_project := record.project_id.jira_bind_ids[:1]:
url = jira_project.make_servicedesk_issue_url(jira_key)
record.jira_servicedesk_issue_url = url
Loading

0 comments on commit adb0992

Please sign in to comment.