[NEW] Add refresh issues functionnality
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class GitIssue(models.Model):
|
||||
_name = "git.issue"
|
||||
_description = "Issue Git"
|
||||
|
||||
issue_id = fields.Integer(string="ID", required=True)
|
||||
name = fields.Char(string="Title", required=True, copy=True)
|
||||
platform = fields.Many2one("git.platform", string="Git platform", required=True)
|
||||
repo = fields.Many2one(
|
||||
@@ -24,3 +26,8 @@ class GitIssue(models.Model):
|
||||
url = fields.Char(string="Link", required=True, copy=False)
|
||||
|
||||
task_id = fields.Many2one("project.task", required=True, copy=True)
|
||||
|
||||
def refresh_data(self):
|
||||
raise UserError(
|
||||
"A Git platform connector addons must be installed to refresh the issues data."
|
||||
)
|
||||
|
@@ -25,3 +25,8 @@ class Task(models.Model):
|
||||
"res_model": "create.git.issue",
|
||||
"target": "new",
|
||||
}
|
||||
|
||||
def refresh_issues(self):
|
||||
for record in self:
|
||||
for issue in record.issue_ids:
|
||||
issue.refresh_data()
|
||||
|
@@ -10,6 +10,7 @@
|
||||
<page name="git_issues" string="Git Issues">
|
||||
<button string="Create an issue" name="create_issue" type="object" class="oe_stat_button" icon="fa-plus-circle" style="margin: 0px 4px 0px 0px" />
|
||||
<button string="Link an issue" name="link_issue" type="object" class="oe_stat_button" icon="fa-link" style="margin: 0px 4px 0px 0px" />
|
||||
<button string="Refresh" name="refresh_issues" type="object" class="oe_stat_button" icon="fa-refresh" style="margin: 0px 4px 0px 0px" />
|
||||
<separator string="Current linked issues" />
|
||||
<field name="issue_ids" nolabel="1" mode="tree">
|
||||
<tree create="0" delete="1">
|
||||
|
@@ -2,3 +2,4 @@
|
||||
|
||||
from . import res_user
|
||||
from . import git_platform
|
||||
from . import git_issue
|
||||
|
24
dev_github_connector/models/git_issue.py
Normal file
24
dev_github_connector/models/git_issue.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models
|
||||
from github import Github
|
||||
|
||||
|
||||
class GitIssue(models.Model):
|
||||
_inherit = "git.issue"
|
||||
|
||||
def _convert_issue_status(self, status):
|
||||
if status == "open":
|
||||
return "opened"
|
||||
elif status == "closed":
|
||||
return "closed"
|
||||
else:
|
||||
return status
|
||||
|
||||
def refresh_data(self):
|
||||
for record in self:
|
||||
if record.platform.tool == "github":
|
||||
github = Github()
|
||||
repo = github.get_repo(self.repo.displayed_name)
|
||||
issue = repo.get_issue(number=self.issue_id)
|
||||
record.status = self._convert_issue_status(issue.state)
|
@@ -24,6 +24,7 @@ class CreateGitIssue(models.TransientModel):
|
||||
title=self.issue_name, body=self.issue_description
|
||||
)
|
||||
values = {
|
||||
"issue_id": issue.number,
|
||||
"name": issue.title,
|
||||
"platform": self.issue_platform.id,
|
||||
"repo": self.issue_repo.id,
|
||||
|
@@ -22,6 +22,7 @@ class LinkGitIssue(models.TransientModel):
|
||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||
issue = repo.get_issue(number=self.issue_number)
|
||||
values = {
|
||||
"issue_id": issue.number,
|
||||
"name": issue.title,
|
||||
"platform": self.issue_platform.id,
|
||||
"repo": self.issue_repo.id,
|
||||
|
Reference in New Issue
Block a user