summaryrefslogtreecommitdiff
path: root/addons/mrp/controller
diff options
context:
space:
mode:
authorAnkita Raval <anr@odoo.com>2019-12-10 13:15:08 +0000
committersvs-odoo <svs@odoo.com>2020-03-04 10:12:46 +0000
commit65513ef3f92d82806d03bd5fe55c7f9af4f1484d (patch)
treebb8b71b6d1c19713abd5e81729459672ae0f2131 /addons/mrp/controller
parenta56a4f8aeeebf946745b09b0b1a649293b806546 (diff)
[IMP] mrp: mrp_document
Purpose: Modernizes and facilitates files upload in manufacturing app. In this Commit: - Show the image in Kanban. - Allow to access a preview of the file when clicking on it in the Kanban view. - Add a 'Edit', 'Delete' and 'Download' in kanban card dropdown menu. - Add Upload button in control panel to upload document which will create new record of `mrp.document` and also add a testcase for it. task-1960733 closes odoo/odoo#42168 Related: odoo/enterprise#8977 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/mrp/controller')
-rw-r--r--addons/mrp/controller/__init__.py4
-rw-r--r--addons/mrp/controller/main.py36
2 files changed, 40 insertions, 0 deletions
diff --git a/addons/mrp/controller/__init__.py b/addons/mrp/controller/__init__.py
new file mode 100644
index 00000000000..5d4b25db9c0
--- /dev/null
+++ b/addons/mrp/controller/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import main
diff --git a/addons/mrp/controller/main.py b/addons/mrp/controller/main.py
new file mode 100644
index 00000000000..0c8b40f0621
--- /dev/null
+++ b/addons/mrp/controller/main.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import base64
+import json
+import logging
+
+from odoo import http
+from odoo.http import request
+from odoo.tools.mimetypes import neuter_mimetype
+from odoo.tools.translate import _
+
+logger = logging.getLogger(__name__)
+
+
+class MrpDocumentRoute(http.Controller):
+
+ @http.route('/mrp/upload_attachment', type='http', methods=['POST'], auth="user")
+ def upload_document(self, ufile, **kwargs):
+ files = request.httprequest.files.getlist('ufile')
+ result = {'success': _("All files uploaded")}
+ for ufile in files:
+ try:
+ mimetype = neuter_mimetype(ufile.content_type, http.request.env.user)
+ request.env['mrp.document'].create({
+ 'name': ufile.filename,
+ 'res_model': kwargs.get('res_model'),
+ 'res_id': kwargs.get('res_id'),
+ 'mimetype': mimetype,
+ 'datas': base64.encodebytes(ufile.read()),
+ })
+ except Exception as e:
+ logger.exception("Fail to upload document %s" % ufile.filename)
+ result = {'error': str(e)}
+
+ return json.dumps(result)