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.

69 lines
2.4 KiB

7 years ago
7 years ago
7 years ago
  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 os
  20. import base64
  21. import uuid
  22. import logging
  23. import mimetypes
  24. from odoo import _, api, fields, models
  25. from odoo.addons.muk_utils.tools.http import get_response
  26. from odoo.addons.muk_converter.tools import converter
  27. _logger = logging.getLogger(__name__)
  28. class ConverterWizard(models.TransientModel):
  29. _inherit = "muk_converter.convert"
  30. res_model = fields.Char(
  31. string="Model")
  32. res_id = fields.Integer(
  33. string="ID")
  34. res_name = fields.Char(
  35. compute='_compute_res_name',
  36. string='Record',
  37. store=True)
  38. @api.depends('res_model', 'res_id')
  39. def _compute_res_name(self):
  40. for record in self:
  41. if record.res_model and record.res_id:
  42. rec = self.env[record.res_model].browse(record.res_id)
  43. record.res_name = rec.display_name
  44. @api.multi
  45. def convert_and_save(self):
  46. self.convert()
  47. for record in self:
  48. if record.res_model and record.res_id:
  49. self.env['ir.attachment'].create({
  50. 'type': "binary",
  51. 'name': record.output_name,
  52. 'datas_fname': record.output_name,
  53. 'datas': record.output_binary})
  54. else:
  55. raise ValueError("To save the converted file, a record has to be set.")
  56. return {
  57. 'type': 'ir.actions.client',
  58. 'tag': 'reload',
  59. }