Introduce new model of "Product Documents" to hold documents linked to a given product template/variant, displayed on: * quotations * confirmed sale orders * e-commerce product page This will also replace the previous "Digital Files" (website_sale_digital) logic & module, which allowed to specify product documents available to customers after the SO invoice was paid. This exact feature will be lost after upgrade, since we only keep the choice to link documents on quotations/orders, but: 1) on e-commerce, carts are supposed paid when confirmed 2) on portal, the "Online Payment" settings makes sure the users have to pay to confirm their quotation. therefore we consider new configuration sufficient, without needing a "paid order" choice as well. task-3249201 Part-of: odoo/odoo#132739
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# -*- 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'].with_context(
|
|
disable_product_documents_creation=True
|
|
).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)
|