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 OdooLibBin(models.Model):
  6. _inherit = "abstract.action.mixin"
  7. _name = "odoo.lib.bin"
  8. _description = "Odoo Lib Bin"
  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_bin_rel",
  16. column1="lib_bin_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_bin_ids")
  27. def _compute_module_version_qty(self):
  28. for lib_bin in self:
  29. lib_bin.module_version_qty = len(lib_bin.module_version_ids)
  30. # Custom Section
  31. @api.model
  32. def create_if_not_exist(self, name):
  33. lib_bin = self.search([("name", "=", name)])
  34. if not lib_bin:
  35. lib_bin = self.create({"name": name})
  36. return lib_bin
上海开阖软件有限公司 沪ICP备12045867号-1