gooderp18绿色标准版
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.

36 line
1.2KB

  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import base64
  4. import json
  5. import logging
  6. from odoo import http
  7. from odoo.http import request
  8. from odoo.tools.translate import _
  9. logger = logging.getLogger(__name__)
  10. class MrpDocumentRoute(http.Controller):
  11. @http.route('/mrp/upload_attachment', type='http', methods=['POST'], auth="user")
  12. def upload_document(self, ufile, **kwargs):
  13. files = request.httprequest.files.getlist('ufile')
  14. result = {'success': _("All files uploaded")}
  15. for ufile in files:
  16. try:
  17. mimetype = ufile.content_type
  18. request.env['mrp.document'].create({
  19. 'name': ufile.filename,
  20. 'res_model': kwargs.get('res_model'),
  21. 'res_id': int(kwargs.get('res_id')),
  22. 'mimetype': mimetype,
  23. 'datas': base64.encodebytes(ufile.read()),
  24. })
  25. except Exception as e:
  26. logger.exception("Fail to upload document %s" % ufile.filename)
  27. result = {'error': str(e)}
  28. return json.dumps(result)
上海开阖软件有限公司 沪ICP备12045867号-1