diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 197ec14f3c3..0da2bd0ce5d 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -1,9 +1,6 @@ # -*- 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, MissingError @@ -31,11 +28,9 @@ class PortalAccount(CustomerPortal): } return self._get_page_view_values(invoice, access_token, values, 'my_invoices_history', False, **kwargs) - @http.route(['/my/invoices', '/my/invoices/page/'], type='http', auth="user", website=True) def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None, **kw): values = self._prepare_portal_layout_values() - partner = request.env.user.partner_id AccountInvoice = request.env['account.invoice'] domain = [] @@ -82,42 +77,18 @@ class PortalAccount(CustomerPortal): return request.render("account.portal_my_invoices", values) @http.route(['/my/invoices/'], type='http', auth="public", website=True) - def portal_my_invoice_detail(self, invoice_id, access_token=None, **kw): + def portal_my_invoice_detail(self, invoice_id, access_token=None, report_type=None, download=False, **kw): try: invoice_sudo = self._document_check_access('account.invoice', invoice_id, access_token) except (AccessError, MissingError): return request.redirect('/my') + if report_type in ('html', 'pdf', 'text'): + return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download) + values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) return request.render("account.portal_invoice_page", values) - @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._document_check_access('account.invoice', invoice_id, access_token) - except (AccessError, MissingError): - return request.redirect('/my') - - # print report as sudo, since it require access to taxes, payment term, ... and portal - # does not have those access rights. - 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/models/account_invoice.py b/addons/account/models/account_invoice.py index 500d727befd..4c2f73b3396 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -479,7 +479,7 @@ class AccountInvoice(models.Model): sequence.number_next = int(result.group(2)) @api.multi - def _get_printed_report_name(self): + def _get_report_base_filename(self): self.ensure_one() return self.type == 'out_invoice' and self.state == 'draft' and _('Draft Invoice') or \ self.type == 'out_invoice' and self.state in ('open','in_payment','paid') and _('Invoice - %s') % (self.number) or \ @@ -1512,15 +1512,6 @@ class AccountInvoice(models.Model): len(res), ) for r in res] - @api.multi - def get_portal_url(self, suffix=None): - """ - Get a portal url for this invoice, including access_token. - - suffix: string to append to the url, before the query string - """ - self.ensure_one() - return self.access_url + '%s?access_token=%s' % (suffix if suffix else '', self._portal_ensure_token()) - @api.multi def preview_invoice(self): self.ensure_one() diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index e882b4a402d..110ea082a75 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -186,5 +186,5 @@ class ReportInvoiceWithPayment(models.AbstractModel): 'doc_ids': docids, 'doc_model': report.model, 'docs': self.env[report.model].browse(docids), - 'type_html': data and data.get('report_type') == 'html', + 'report_type': data.get('report_type') if data else '', } diff --git a/addons/account/static/src/js/account_portal_sidebar.js b/addons/account/static/src/js/account_portal_sidebar.js index 5323c09e0f3..59b499adcad 100644 --- a/addons/account/static/src/js/account_portal_sidebar.js +++ b/addons/account/static/src/js/account_portal_sidebar.js @@ -32,7 +32,9 @@ var AccountPortalSidebar = PortalSidebar.extend({ var self = this; this._super.apply(this, arguments); var $invoiceHtml = this.$el.find('iframe#invoice_html'); - $invoiceHtml.on('load', self._onLoadIframe.bind(self, $invoiceHtml)); + var updateIframeSize = self._updateIframeSize.bind(self, $invoiceHtml); + $invoiceHtml.on('load', updateIframeSize); + $(window).on('resize', updateIframeSize); }, //-------------------------------------------------------------------------- @@ -40,17 +42,17 @@ var AccountPortalSidebar = PortalSidebar.extend({ //-------------------------------------------------------------------------- /** - * Called when the iframe is load on custome portal - * here we set height and width of html preview (iframe) + * Called when the iframe is loaded or the window is resized on customer portal. + * The goal is to expand the iframe height to display the full report without scrollbar. * * @private + * @param {object} $el: the iframe */ - _onLoadIframe: function ($el) { + _updateIframeSize: 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%'); + // Set it to 0 first to handle the case where scrollHeight is too big for its content. + $el.height(0); + $el.height($body[0].scrollHeight); }, /** * @private diff --git a/addons/account/static/src/scss/section_and_note_backend.scss b/addons/account/static/src/scss/section_and_note_backend.scss index 2c86b3e241f..766ea6ac657 100644 --- a/addons/account/static/src/scss/section_and_note_backend.scss +++ b/addons/account/static/src/scss/section_and_note_backend.scss @@ -3,13 +3,14 @@ // section and note on sale order and invoice. table.o_section_and_note_list_view tr.o_data_row.o_is_line_note, +table.o_section_and_note_list_view tr.o_data_row.o_is_line_note textarea[name="name"], div.oe_kanban_card.o_is_line_note { - color: #999; + font-style: italic; } table.o_section_and_note_list_view tr.o_data_row.o_is_line_section, div.oe_kanban_card.o_is_line_section { font-weight: bold; - background-color: #EEE; + background-color: #DDDDDD; } table.o_section_and_note_list_view tr.o_data_row.o_is_line_section { border-top: 1px solid #BBB; diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index dd84f7fc299..6ad002f1c51 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -490,8 +490,8 @@ - - + + diff --git a/addons/account/views/account_portal_templates.xml b/addons/account/views/account_portal_templates.xml index 0ed3ee95414..7dd506c2cf0 100644 --- a/addons/account/views/account_portal_templates.xml +++ b/addons/account/views/account_portal_templates.xml @@ -6,7 +6,8 @@ Invoices @@ -42,7 +43,10 @@ - + + + Draft Invoice + @@ -85,34 +89,47 @@
Your Contact:
- Contact - Contact - - Contact us +
+
+ Contact + Contact +
+ +
-
- Powered by Odoo -
+ +
+ Powered by Odoo
+
-