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.

44 lines
1.4 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. module_ids = fields.Many2many(
  10. string='Modules', comodel_name='ir.module.module')
  11. module_qty = fields.Integer(
  12. string="Modules Quantity",
  13. compute='_compute_modules', store=True)
  14. installed_module_qty = fields.Integer(
  15. string="Installed Modules Quantity",
  16. compute='_compute_modules', store=True)
  17. _sql_constraints = [
  18. ('name_uniq', 'unique(name)',
  19. 'The name of the modules author should be unique per database!'),
  20. ]
  21. @api.multi
  22. @api.depends('module_ids')
  23. def _compute_modules(self):
  24. for author in self:
  25. author.module_qty = len(author.module_ids)
  26. author.installed_module_qty = len(
  27. author.module_ids.filtered(lambda x: x.state == 'installed'))
  28. @api.model
  29. def _get_or_create(self, name):
  30. authors = self.search([('name', '=', name)])
  31. if authors:
  32. return authors[0]
  33. else:
  34. return self.create({'name': name})