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.

51 lines
1.6 KiB

  1. # Copyright 2019 Camptocamp SA
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. from ..tools import _default_sequence
  5. class AgreementParameterValue(models.Model):
  6. _name = 'agreement.parameter.value'
  7. _description = 'Possible values for agreement m2o parameters'
  8. _order = "parameter, sequence"
  9. name = fields.Char(required=True, translate=True)
  10. code = fields.Char(
  11. required=True,
  12. index=True,
  13. help="code of the value, can be used to search for it "
  14. "in a language neutral way",
  15. )
  16. sequence = fields.Integer(
  17. required=True,
  18. default=_default_sequence,
  19. help="order the values for a given parameter",
  20. )
  21. parameter = fields.Char(
  22. required=True,
  23. help='set to the name of the agreement field which '
  24. 'can have this value (not strictly required but it helps)',
  25. )
  26. is_default = fields.Boolean(
  27. string="Is the default value?",
  28. help="Set this on 1 record for a given parameter to flag the value as "
  29. "the default value. If a parameter has no default value, then its "
  30. "default is False",
  31. )
  32. @api.model
  33. def get(self, parameter, code):
  34. res = self.search(
  35. [('parameter', '=', parameter), ('code', '=', code)], limit=1
  36. )
  37. if res:
  38. return res
  39. else:
  40. raise ValueError((parameter, code))
  41. @api.model
  42. def get_default(self, parameter):
  43. res = self.search(
  44. [('parameter', '=', parameter), ('is_default', '=', True)], limit=1
  45. )
  46. return res or False