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.

55 lines
1.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 OdooLicense(models.Model):
  6. _inherit = "abstract.action.mixin"
  7. _name = "odoo.license"
  8. _description = "Odoo License"
  9. _order = "name"
  10. # Column Section
  11. name = fields.Char(string="Name", index=True, required=True, readonly=True)
  12. module_version_ids = fields.One2many(
  13. comodel_name="odoo.module.version",
  14. inverse_name="license_id",
  15. string="Module Versions",
  16. )
  17. module_version_qty = fields.Integer(
  18. string="Number of Module Versions",
  19. compute="_compute_module_version_qty",
  20. store=True,
  21. )
  22. website = fields.Char(string="Website")
  23. image = fields.Binary(string="Icon Image", attachment=True)
  24. description = fields.Text(string="Description")
  25. active = fields.Boolean(string="Active", default=True)
  26. # Constrains Section
  27. _sql_constraints = [
  28. ("name_uniq", "unique (name)", "Name already exists !"),
  29. ]
  30. # Compute Section
  31. @api.depends("module_version_ids.license_id")
  32. def _compute_module_version_qty(self):
  33. for module in self:
  34. module.module_version_qty = len(module.module_version_ids)
  35. # Custom Section
  36. @api.model
  37. def create_if_not_exist(self, name):
  38. module = self.search([("name", "=", name)])
  39. if not module:
  40. module = self.create({"name": name})
  41. return module
上海开阖软件有限公司 沪ICP备12045867号-1