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.

45 lines
1.4KB

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