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.

39 lines
1.2 KiB

  1. # Copyright (C) 2019-Today: GRAP (<http://www.grap.coop/>)
  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 IrModuleAuthor(models.Model):
  6. _name = 'ir.module.author'
  7. _description = 'Modules Authors'
  8. name = fields.Char(string='Name', required=True)
  9. installed_module_ids = fields.Many2many(
  10. string='Modules', comodel_name='ir.module.module',
  11. relation='ir_module_module_author_rel')
  12. installed_module_qty = fields.Integer(
  13. string="Installed Modules Quantity",
  14. compute='_compute_installed_module_qty', store=True)
  15. _sql_constraints = [
  16. ('name_uniq', 'unique(name)',
  17. 'The name of the modules author should be unique per database!'),
  18. ]
  19. @api.multi
  20. @api.depends('installed_module_ids')
  21. def _compute_installed_module_qty(self):
  22. for author in self:
  23. author.installed_module_qty = len(author.installed_module_ids)
  24. @api.model
  25. def _get_or_create(self, name):
  26. authors = self.search([('name', '=', name)])
  27. if authors:
  28. return authors[0]
  29. else:
  30. return self.create({'name': name})