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.

30 lines
1.0 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. from odoo.tools.safe_eval import safe_eval
  6. class IrModuleType(models.Model):
  7. _name = 'ir.module.type.rule'
  8. _description = 'Modules Types Rules'
  9. _order = 'sequence'
  10. sequence = fields.Integer(string='Sequence')
  11. module_domain = fields.Char(
  12. string='Module Domain', required=True, default='[]')
  13. module_type_id = fields.Many2one(
  14. string='Module type', comodel_name='ir.module.type', required=True)
  15. @api.multi
  16. def _get_module_type_id_from_module(self, module):
  17. IrModuleModule = self.env['ir.module.module']
  18. for rule in self:
  19. domain = safe_eval(rule.module_domain)
  20. domain.append(('id', '=', module.id))
  21. if IrModuleModule.search(domain):
  22. return rule.module_type_id.id
  23. return False