Skip to content

Commit

Permalink
[FIX] various: clean up portal and reports (sales and invoices)
Browse files Browse the repository at this point in the history
The goal of this commit is to fix the various views and reports of sales and invoices.

======
Portal
======

Fix breadcrumbs

Fix BS4 issues, alignment of various elements

Better auto resize of the invoice iframe

Fix invoice list for draft invoices

Fix previous/next document pagers

Remove unnecessary monetary widgets (not needed when using t-field if the field is Monetary)

Standardize invoice and sale routes:
- especially when related to displaying: html, pdf (print and download), text
- by using the get_portal_url() also for invoices

Add the total on the left column of sales order

================
Section and note
================

Improve general style:
- notes in italics
- sections: less padding, darker background, no borders

=========
Demo Data
=========

Fix sales order demo data to appear for the admin (instead of system)

PR: odoo#25997
task-1869469
  • Loading branch information
seb-odoo committed Aug 29, 2018
1 parent 984554f commit 4a3fd02
Show file tree
Hide file tree
Showing 30 changed files with 417 additions and 436 deletions.
37 changes: 4 additions & 33 deletions addons/account/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,11 +28,9 @@ def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
}
return self._get_page_view_values(invoice, access_token, values, 'my_invoices_history', False, **kwargs)


@http.route(['/my/invoices', '/my/invoices/page/<int: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 = []
Expand Down Expand Up @@ -82,42 +77,18 @@ def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None
return request.render("account.portal_my_invoices", values)

@http.route(['/my/invoices/<int:invoice_id>'], 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/<int:invoice_id>',
'/my/invoices/html/<int:invoice_id>/<string:access_token>'
], 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
# ------------------------------------------------------------
Expand Down
11 changes: 1 addition & 10 deletions addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def _set_sequence_next(self):
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 \
Expand Down Expand Up @@ -1512,15 +1512,6 @@ def _amount_by_group(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion addons/account/report/account_invoice_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def _get_report_values(self, docids, data=None):
'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 '',
}
18 changes: 10 additions & 8 deletions addons/account/static/src/js/account_portal_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ 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);
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* 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
Expand Down
5 changes: 3 additions & 2 deletions addons/account/static/src/scss/section_and_note_backend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions addons/account/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@
<field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags" options="{'color_field': 'color'}"/>
<field name="quantity"/>
<field name="uom_id" groups="uom.group_uom"/>
<field name="price_unit"/>
<field name="discount" groups="base.group_no_one"/>
<field name="price_unit" string="Price"/>
<field name="discount" groups="base.group_no_one" string="Disc (%)"/>
<field name="invoice_line_tax_ids" widget="many2many_tags" options="{'no_create': True}" context="{'type':parent.type, 'tree_view_ref': 'account.account_tax_view_tree', 'search_view_ref': 'account.account_tax_view_search'}"
domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]"/>
<field name="price_subtotal" string="Subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
Expand Down
43 changes: 30 additions & 13 deletions addons/account/views/account_portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<t t-else="">Invoices</t>
</li>
<li t-if="invoice" class="breadcrumb-item">
<t t-esc="invoice.number"/>
<t t-esc="invoice.number" t-if="invoice.number"/>
<t t-else="">Draft Invoice</t>
</li>
</xpath>
</template>
Expand Down Expand Up @@ -42,7 +43,10 @@
<t t-foreach="invoices" t-as="invoice">
<tr>
<td>
<a t-attf-href="/my/invoices/#{invoice.id}" t-att-title="invoice.number"><t t-esc="invoice.number"/></a>
<a t-att-href="invoice.get_portal_url()" t-att-title="invoice.number">
<t t-esc="invoice.number" t-if="invoice.number"/>
<t t-else="">Draft Invoice</t>
</a>
</td>
<td><span t-field="invoice.date_invoice"/></td>
<td class='d-none d-md-table-cell'><span t-field="invoice.date_due"/></td>
Expand Down Expand Up @@ -85,34 +89,47 @@
</div>
<div class="o_payment_button">
<div class="text-center mb8 ml16 mr16 o_download_pdf">
<a class="btn btn-secondary btn-block o_download_btn" t-att-href="'/my/invoices/pdf/%s?%s' % (invoice.id, keep_query())" title="Download"><i class="fa fa-download"/> Download</a>
<a class="btn btn-secondary btn-block d-none d-lg-inline-block o_print_btn o_portal_invoice_print" t-att-href="'/my/invoices/pdf/%s?%s&amp;print=true' % (invoice.id, keep_query())" id="print_invoice_report" title="Print"><i class="fa fa-print"/> Print</a>
<a class="btn btn-secondary btn-block o_download_btn" t-att-href="invoice.get_portal_url(report_type='pdf', download=True)" title="Download"><i class="fa fa-download"/> Download</a>
<a class="btn btn-secondary btn-block d-none d-lg-inline-block o_print_btn o_portal_invoice_print" t-att-href="invoice.get_portal_url(report_type='pdf')" id="print_invoice_report" title="Print"><i class="fa fa-print"/> Print</a>
</div>
</div>
<hr t-if="invoice.user_id" class="mt0 mb0"/>
<div class="pb8 ml16 mr16 container">
<t t-if="invoice.user_id">
<div><strong>Your Contact:</strong></div>
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="invoice.user_id.image" t-attf-src="data:image/png;base64,#{invoice.user_id.image}" alt="Contact"/>
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="not invoice.user_id.image" src="/web/static/src/img/placeholder.png" alt="Contact"/>
<span t-field="invoice.user_id" t-options='{"widget": "contact", "fields": ["name", "phone"], "no_marker": True}'/>
<a data-toggle="modal" href="#" data-target="#invoice_chatter">Contact us</a>
<div class="d-flex h-100">
<div class="align-self-center">
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="invoice.user_id.image" t-attf-src="data:image/png;base64,#{invoice.user_id.image}" alt="Contact"/>
<img class="rounded-circle mr4 float-left o_portal_contact_img" t-if="not invoice.user_id.image" src="/web/static/src/img/placeholder.png" alt="Contact"/>
</div>
<div class="align-self-center">
<span t-field="invoice.user_id" t-options='{"widget": "contact", "fields": ["name", "phone"], "no_marker": True}'/>
<a data-toggle="modal" href="#" data-target="#invoice_chatter"><i class="fa fa-comment"></i> Contact us</a>
</div>
</div>
</t>
<div t-if="not invoice.user_id" class="text-center mr16">
<a data-toggle="modal" href="#" data-target="#invoice_chatter">Contact us</a>
<a data-toggle="modal" href="#" data-target="#invoice_chatter"><i class="fa fa-comment"></i> Contact us</a>
</div>
</div>
<div class="text-center d-none d-md-block mt4 o_portal_brand">
Powered by <a target="_blank" href="http://www.odoo.com?utm_source=db&amp;utm_medium=portal">Odoo</a>
</div>
</div>
<div class="text-center d-none d-md-block o_portal_brand">
Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&amp;utm_medium=portal">Odoo</a>
</div>
</div>
<!-- Page Content -->
<div id="invoice_content" class="col-lg-9 o_portal_page_content d-print-none">
<div t-ignore="true" class="float-md-right css_editable_mode_hidden d-print-none">
<ul class="list-inline">
<li groups="sales_team.group_sale_salesman" class="list-inline-item">
<a role="button" class="btn btn-info mt16 mr16" t-att-href="'/web#return_label=Website&amp;model=%s&amp;id=%s&amp;action=%s&amp;view_type=form' % (invoice._name, invoice.id, invoice.env.ref('account.action_invoice_tree1').id)"><t t-if="invoice.state == 'draft'">Edit Invoice</t><t t-else="">Leave Portal</t></a>
</li>
</ul>
</div>
<t t-if="error or warning" t-call="account.portal_invoice_error"/>
<t t-if="success and (not error and not warning)" t-call="account.portal_invoice_success"/>
<div class="o_portal_html_view">
<iframe id="invoice_html" class="mt8 mb8" width="100%" height="100%" frameborder="0" scrolling="no" t-attf-src="/my/invoices/html/#{invoice.id}/#{invoice.access_token}?report_type=html"/>
<iframe id="invoice_html" class="mt8 mb8" width="100%" height="100%" frameborder="0" scrolling="no" t-att-src="invoice.get_portal_url(report_type='html')"/>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions addons/account/views/account_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name="account.report_invoice_with_payments"
file="account.report_invoice_with_payments"
attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(object._get_printed_report_name())"
print_report_name="(object._get_report_base_filename())"
groups="account.group_account_invoice"
/>

Expand All @@ -22,7 +22,7 @@
name="account.report_invoice"
file="account.report_invoice"
attachment="(object.state in ('open','in_payment','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(object._get_printed_report_name())"
print_report_name="(object._get_report_base_filename())"
/>

<report
Expand Down
Loading

0 comments on commit 4a3fd02

Please sign in to comment.