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.

83 lines
3.1 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (C) 2017 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import logging
  20. import textwrap
  21. from odoo import api, fields, models
  22. class ResConfigSettings(models.TransientModel):
  23. _inherit = 'res.config.settings'
  24. converter_service = fields.Selection(
  25. selection=[
  26. ("unoconv", "Local"),
  27. ("provider", "Service")],
  28. string="Converter",
  29. default="provider",
  30. help=textwrap.dedent("""\
  31. Converter engine, which is used for the conversion:
  32. - Local: Use a locally installed unoconv installation
  33. - Service: Use a service to do the conversion
  34. """))
  35. converter_max_store = fields.Integer(
  36. string="Storage Size",
  37. help=textwrap.dedent("""\
  38. To certify the conversion, converted files can be saved
  39. and loaded from memory if necessary. You can set a maximum
  40. size of the storage to prevent massive memory requirements.
  41. """))
  42. converter_credit = fields.Boolean(
  43. compute='_compute_converter_credit',
  44. string="Converter insufficient credit")
  45. @api.multi
  46. def set_values(self):
  47. res = super(ResConfigSettings, self).set_values()
  48. param = self.env['ir.config_parameter'].sudo()
  49. param.set_param("muk_converter.service", self.converter_service)
  50. param.set_param("muk_converter.max_store", self.converter_max_store)
  51. return res
  52. @api.model
  53. def get_values(self):
  54. res = super(ResConfigSettings, self).get_values()
  55. params = self.env['ir.config_parameter'].sudo()
  56. res.update(
  57. converter_service=params.get_param("muk_converter.service", default="provider"),
  58. converter_max_store=int(params.get_param("muk_converter.max_store", default=20))
  59. )
  60. return res
  61. @api.multi
  62. def _compute_converter_credit(self):
  63. credits = self.env['iap.account'].get_credits('muk_converter')
  64. for record in self:
  65. record.converter_credit = credits <= 0
  66. @api.multi
  67. def redirect_to_buy_converter_credit(self):
  68. url = self.env['iap.account'].get_credits_url('muk_converter')
  69. return {
  70. 'type': 'ir.actions.act_url',
  71. 'url': url,
  72. 'target': '_new',
  73. }