forked from trytonus/nereid-webshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.py
34 lines (27 loc) · 861 Bytes
/
invoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
import tempfile
from trytond.pool import PoolMeta, Pool
from nereid import route, login_required, abort, \
current_user
from nereid.helpers import send_file
__all__ = ['Invoice']
__metaclass__ = PoolMeta
class Invoice:
__name__ = 'account.invoice'
@route('/orders/invoice/<int:active_id>/download')
@login_required
def download_invoice(self):
"""
Allow user to download invoice.
"""
Report = Pool().get('account.invoice', type='report')
if self.party != current_user.party:
abort(403)
vals = Report.execute([self.id], {})
with tempfile.NamedTemporaryFile(delete=False) as file:
file.write(vals[1])
return send_file(
file.name,
as_attachment=True,
attachment_filename=vals[3],
)