36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
|
|
import base64
|
|
import datetime
|
|
|
|
import werkzeug
|
|
|
|
from odoo.http import request, route
|
|
from odoo.addons.portal.controllers.portal import CustomerPortal
|
|
|
|
|
|
class SaleControlPortal(CustomerPortal):
|
|
|
|
@route(['/my/closing_document'], type='http', auth='user', website=True)
|
|
def submit_closing_document(self, redirect=None, **post):
|
|
"""Приём закрывающего документа (скан) от клиента из портала."""
|
|
name = post.get('name')
|
|
invoice_id = post.get('invoice_id')
|
|
redirect_url = post.get('url') or '/my/invoices'
|
|
|
|
file_data = False
|
|
for uploaded in request.httprequest.files.getlist('image_1920'):
|
|
content = uploaded.read()
|
|
if content:
|
|
file_data = base64.b64encode(content)
|
|
|
|
if name and invoice_id and file_data:
|
|
request.env['doc.closeddoc'].sudo().create({
|
|
'name': name,
|
|
'date_doc': datetime.date.today(),
|
|
'invoice_id': int(invoice_id),
|
|
'channel': 'scan',
|
|
'file_inv': file_data,
|
|
})
|
|
return werkzeug.utils.redirect('/my/invoices')
|
|
return werkzeug.utils.redirect(redirect_url)
|