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.

51 lines
1.5KB

  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 OdooAuthor(models.Model):
  6. _inherit = "abstract.action.mixin"
  7. _name = "odoo.author"
  8. _description = "Odoo Author"
  9. _order = "module_qty desc, name"
  10. # Column Section
  11. name = fields.Char(string="Name", store=True, readonly=True, index=True)
  12. module_version_ids = fields.Many2many(
  13. string="Module Versions",
  14. comodel_name="odoo.module.version",
  15. relation="github_module_version_author_rel",
  16. column1="author_id",
  17. column2="module_version_id",
  18. readonly=True,
  19. )
  20. module_ids = fields.Many2many(
  21. string="Modules",
  22. comodel_name="odoo.module",
  23. relation="github_module_author_rel",
  24. column1="author_id",
  25. column2="module_id",
  26. readonly=True,
  27. )
  28. module_qty = fields.Integer(
  29. string="Number of Modules", compute="_compute_module_qty", store=True
  30. )
  31. @api.depends("module_ids.author_ids")
  32. def _compute_module_qty(self):
  33. for author in self:
  34. author.module_qty = len(author.module_ids)
  35. # Custom Section
  36. @api.model
  37. def create_if_not_exist(self, name):
  38. author = self.search([("name", "=", name)])
  39. if not author:
  40. author = self.create({"name": name})
  41. return author
上海开阖软件有限公司 沪ICP备12045867号-1