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.

86 lines
3.1 KiB

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