diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 155c38d1a05..f78f8d45935 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import re +from werkzeug.exceptions import NotFound + from odoo import http, _ from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager from odoo.exceptions import AccessError @@ -113,9 +116,14 @@ class PortalAccount(CustomerPortal): return request.redirect('/my') values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) + # force to hide orginal breadcrumbs if we have access_token or not + values['no_breadcrumbs'] = True return request.render("account.portal_invoice_page", values) - @http.route(['/my/invoices/pdf/'], type='http', auth="public", website=True) + @http.route([ + '/my/invoices/pdf/', + '/my/invoices/html//' + ], type='http', auth="public", website=True) def portal_my_invoice_report(self, invoice_id, access_token=None, **kw): try: invoice_sudo = self._invoice_check_access(invoice_id, access_token) @@ -124,12 +132,20 @@ class PortalAccount(CustomerPortal): # print report as sudo, since it require access to taxes, payment term, ... and portal # does not have those access rights. - pdf = request.env.ref('account.account_invoices').sudo().render_qweb_pdf([invoice_sudo.id])[0] - pdfhttpheaders = [ - ('Content-Type', 'application/pdf'), - ('Content-Length', len(pdf)), - ] - return request.make_response(pdf, headers=pdfhttpheaders) + accountInvoiceReport = request.env.ref('account.account_invoices').sudo() + report_type = kw.get('report_type', 'pdf') + method_name = 'render_qweb_%s' % (report_type) + if hasattr(accountInvoiceReport, method_name): + invoice_report = getattr(accountInvoiceReport, method_name)([invoice_sudo.id], data={'report_type': report_type})[0] + reporthttpheaders = [ + ('Content-Type', 'application/pdf' if report_type == 'pdf' else 'text/html'), + ('Content-Length', len(invoice_report)), + ] + if report_type == 'pdf' and not kw.get('print'): + filename = "%s.pdf" % (re.sub('\W+', '-', invoice_sudo._get_printed_report_name())) + reporthttpheaders.append(('Content-Disposition', http.content_disposition(filename))) + return request.make_response(invoice_report, headers=reporthttpheaders) + raise NotFound() # ------------------------------------------------------------ # My Home diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 791d0820f63..0282010032e 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -171,3 +171,17 @@ class AccountInvoiceReport(models.Model): )""" % ( self._table, self.env['res.currency']._select_companies_rates(), self._select(), self._sub_select(), self._from(), self._group_by())) + + +class ReportInvoiceWithPayment(models.AbstractModel): + _name = 'report.account.report_invoice_with_payments' + + @api.model + def get_report_values(self, docids, data=None): + report = self.env['ir.actions.report']._get_report_from_name('account.report_invoice_with_payments') + return { + 'doc_ids': docids, + 'doc_model': report.model, + 'docs': self.env[report.model].browse(docids), + 'type_html': data and data.get('report_type') == 'html', + } diff --git a/addons/account/static/src/js/account_portal_sidebar.js b/addons/account/static/src/js/account_portal_sidebar.js new file mode 100644 index 00000000000..3b0ab0e6afe --- /dev/null +++ b/addons/account/static/src/js/account_portal_sidebar.js @@ -0,0 +1,58 @@ +odoo.define('account.AccountPortalSidebar', function (require) { +"use strict"; + +require('web.dom_ready'); +var PortalSidebar = require('portal.PortalSidebar'); + +var AccountPortalSidebar = PortalSidebar.extend({ + events: { + 'click .o_portal_invoice_print': '_onPrintInvoice', + }, + /** + * @override + */ + start: function () { + var self = this; + this._super.apply(this, arguments); + var $invoiceHtml = this.$el.find('iframe#invoice_html'); + $invoiceHtml.on('load', self._onLoadIframe.bind(self, $invoiceHtml)); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Called when the iframe is load on custome portal + * here we set height and width of html preview (iframe) + * + * @private + */ + _onLoadIframe: function ($el) { + var $body = $el.contents().find('body'); + // expand iframe height for display full report on the custome portal (no scrollbar in iframe) + $el.height($body.scrollParent().height()); + // removed extra space in html preview (specially left and right margin) + $body.width('100%'); + }, + /** + * @private + * @param {MouseEvent} ev + */ + _onPrintInvoice: function (ev) { + ev.preventDefault(); + var href = $(ev.currentTarget).attr('href'); + this._printIframeContent(href); + }, +}); + +$(function () { + if (!$('.o_portal_invoice_sidebar').length) { + return $.Deferred().reject("DOM doesn't contain '.o_portal_invoice_sidebar'"); + } + var account_portal_sidebar = new AccountPortalSidebar(); + account_portal_sidebar.attachTo($('.o_portal_invoice_sidebar')); +}); + +return AccountPortalSidebar; +}); diff --git a/addons/account/views/account.xml b/addons/account/views/account.xml index d8153c82871..e7218152387 100644 --- a/addons/account/views/account.xml +++ b/addons/account/views/account.xml @@ -24,6 +24,12 @@ + + -