mirror of
https://github.com/bringout/oca-ocb-mrp.git
synced 2026-04-20 05:51:59 +02:00
Initial commit: Mrp packages
This commit is contained in:
commit
50d736b3bd
739 changed files with 538193 additions and 0 deletions
35
odoo-bringout-oca-ocb-mrp/mrp/controller/main.py
Normal file
35
odoo-bringout-oca-ocb-mrp/mrp/controller/main.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# -*- 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.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 = ufile.content_type
|
||||
request.env['mrp.document'].create({
|
||||
'name': ufile.filename,
|
||||
'res_model': kwargs.get('res_model'),
|
||||
'res_id': int(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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue