You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6KB

  1. # Copyright (C) 2016-Today: Odoo Community Association (OCA)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. class ResPartner(models.Model):
  6. _name = "res.partner"
  7. _inherit = ["res.partner", "abstract.github.model"]
  8. _github_type = "user"
  9. _github_login_field = "login"
  10. _need_individual_call = True
  11. _field_list_prevent_overwrite = ["name", "website", "email", "image_1920"]
  12. # Column Section
  13. is_bot_account = fields.Boolean(
  14. string="Is Bot Github Account",
  15. help="Check this box if this " "account is a bot or similar.",
  16. )
  17. github_team_ids = fields.Many2many(
  18. string="Teams",
  19. comodel_name="github.team.partner",
  20. # inverse_name="partner_id",
  21. readonly=True,
  22. )
  23. github_team_qty = fields.Integer(
  24. string="Number of Teams", compute="_compute_github_team_qty", store=True
  25. )
  26. organization_ids = fields.Many2many(
  27. string="Organizations",
  28. comodel_name="github.organization",
  29. relation="github_organization_partner_rel",
  30. column1="partner_id",
  31. column2="organization_id",
  32. readonly=True,
  33. )
  34. organization_qty = fields.Integer(
  35. string="Number of Organizations",
  36. compute="_compute_organization_qty",
  37. store=True,
  38. )
  39. # Constraints Section
  40. _sql_constraints = [
  41. (
  42. "github_login_uniq",
  43. "unique(github_login)",
  44. "Two different partners cannot have the same Github Login",
  45. )
  46. ]
  47. @api.constrains("github_login", "is_company")
  48. def _check_login_company(self):
  49. for partner in self:
  50. if partner.is_company and partner.github_login:
  51. raise Warning(
  52. _("A company ('%s') can not have a Github login" " associated.")
  53. % partner.name
  54. )
  55. # Compute Section
  56. @api.depends("organization_ids", "organization_ids.member_ids")
  57. def _compute_organization_qty(self):
  58. for partner in self:
  59. partner.organization_qty = len(partner.organization_ids)
  60. @api.depends("github_team_ids")
  61. def _compute_github_team_qty(self):
  62. for partner in self:
  63. partner.github_team_qty = len(partner.github_team_ids)
  64. # Custom Section
  65. @api.model
  66. def get_conversion_dict(self):
  67. res = super().get_conversion_dict()
  68. res.update({"website": "blog", "email": "email"})
  69. return res
  70. @api.model
  71. def get_odoo_data_from_github(self, data):
  72. res = super().get_odoo_data_from_github(data)
  73. res.update({"name": data["name"] or "%s (Github)" % data["login"]})
  74. if "avatar_url" in data:
  75. res.update(
  76. {"image_1920": self.get_base64_image_from_github(data["avatar_url"])}
  77. )
  78. return res
  79. def action_github_organization(self):
  80. self.ensure_one()
  81. action = self.env.ref("github_connector.action_github_organization").read()[0]
  82. action["context"] = dict(self.env.context)
  83. action["context"].pop("group_by", None)
  84. action["context"]["search_default_member_ids"] = self.id
  85. return action
  86. def action_github_team_partner_from_partner(self):
  87. self.ensure_one()
  88. action = self.env.ref(
  89. "github_connector.action_github_team_partner_from_partner"
  90. ).read()[0]
  91. action["context"] = dict(self.env.context)
  92. action["context"].pop("group_by", None)
  93. action["context"]["search_default_partner_id"] = self.id
  94. return action
上海开阖软件有限公司 沪ICP备12045867号-1