From 5a86365439ae3f408f0fe9131a201344aa58b2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 24 Apr 2017 17:35:18 +0200 Subject: [PATCH 1/9] [MOV][ADD] website_account: move account code out of website_portal_sale Purpose: separate and locate website code for main addons in their correct module. This commit targets accounting related customer portal. This commit adds a new bridge module between website and account. It contains code related to website portal of invoices. It was located in website_portal_sale but this one should only be the quotation and sales portal. A dependency from website_sale to website_account is added to ensure the behavior and available features of eCommerce are not impacted by this commit. No code modification is performed in this commit except one unnecessary less rule. It contains only code move. --- addons/website_account/__init__.py | 5 + addons/website_account/__manifest__.py | 25 +++++ .../website_account/controllers/__init__.py | 4 + .../controllers/portal_account.py | 106 ++++++++++++++++++ addons/website_account/models/__init__.py | 4 + .../models/account_invoice.py | 0 addons/website_account/security/account.xml | 18 +++ .../security/ir.model.access.csv | 3 + .../views/account_templates.xml | 74 ++++++++++++ .../website_account/views/account_views.xml | 13 +++ addons/website_portal_sale/__manifest__.py | 6 +- .../website_portal_sale/controllers/main.py | 93 --------------- addons/website_portal_sale/models/__init__.py | 1 - .../security/ir.model.access.csv | 4 +- .../security/sale_order_security.xml | 17 --- .../static/src/less/website_portal_sale.less | 4 - .../views/sale_order_views.xml | 11 -- .../views/website_portal_sale_templates.xml | 73 ------------ addons/website_sale/__manifest__.py | 2 +- 19 files changed, 257 insertions(+), 206 deletions(-) create mode 100644 addons/website_account/__init__.py create mode 100644 addons/website_account/__manifest__.py create mode 100644 addons/website_account/controllers/__init__.py create mode 100644 addons/website_account/controllers/portal_account.py create mode 100644 addons/website_account/models/__init__.py rename addons/{website_portal_sale => website_account}/models/account_invoice.py (100%) create mode 100644 addons/website_account/security/account.xml create mode 100644 addons/website_account/security/ir.model.access.csv create mode 100644 addons/website_account/views/account_templates.xml create mode 100644 addons/website_account/views/account_views.xml diff --git a/addons/website_account/__init__.py b/addons/website_account/__init__.py new file mode 100644 index 00000000000..7d34c7c054a --- /dev/null +++ b/addons/website_account/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import controllers +from . import models diff --git a/addons/website_account/__manifest__.py b/addons/website_account/__manifest__.py new file mode 100644 index 00000000000..ad4d55c2f45 --- /dev/null +++ b/addons/website_account/__manifest__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Account Customer Portal', + 'category': 'Website', + 'summary': 'Add your accounting document in the frontend portal', + 'version': '1.0', + 'description': """ +Add your accounting document in the frontend portal. Give customers the list and the state of their invoices. + """, + 'depends': [ + 'account', + 'website_portal', + 'website_payment', + ], + 'data': [ + 'views/account_views.xml', + 'views/account_templates.xml', + 'security/ir.model.access.csv', + 'security/account.xml', + ], + 'demo': [], + 'installable': True, +} diff --git a/addons/website_account/controllers/__init__.py b/addons/website_account/controllers/__init__.py new file mode 100644 index 00000000000..67dc7006e4c --- /dev/null +++ b/addons/website_account/controllers/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import portal_account diff --git a/addons/website_account/controllers/portal_account.py b/addons/website_account/controllers/portal_account.py new file mode 100644 index 00000000000..9ae2e743003 --- /dev/null +++ b/addons/website_account/controllers/portal_account.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import http, _ +from odoo.exceptions import AccessError +from odoo.http import request + +from odoo.addons.website_portal.controllers.main import website_account + + +class PortalAccount(website_account): + + def _prepare_portal_layout_values(self): + values = super(PortalAccount, self)._prepare_portal_layout_values() + partner = request.env.user.partner_id + + invoice_count = request.env['account.invoice'].search_count([ + ('type', 'in', ['out_invoice', 'out_refund']), + ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), + ('state', 'in', ['open', 'paid', 'cancel']) + ]) + + values['invoice_count'] = invoice_count + return values + + @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 = [ + ('type', 'in', ['out_invoice', 'out_refund']), + ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), + ('state', 'in', ['open', 'paid', 'cancelled']) + ] + + searchbar_sortings = { + 'date': {'label': _('Invoice Date'), 'order': 'date_invoice desc'}, + 'duedate': {'label': _('Due Date'), 'order': 'date_due desc'}, + 'name': {'label': _('Reference'), 'order': 'name desc'}, + 'state': {'label': _('Status'), 'order': 'state'}, + } + # default sort by order + if not sortby: + sortby = 'date' + order = searchbar_sortings[sortby]['order'] + + archive_groups = self._get_archive_groups('account.invoice', domain) + if date_begin and date_end: + domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)] + + # count for pager + invoice_count = AccountInvoice.search_count(domain) + # pager + pager = request.website.pager( + url="/my/invoices", + url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby}, + total=invoice_count, + page=page, + step=self._items_per_page + ) + # content according to pager and archive selected + invoices = AccountInvoice.search(domain, order=order, limit=self._items_per_page, offset=pager['offset']) + values.update({ + 'date': date_begin, + 'invoices': invoices, + 'page_name': 'invoice', + 'pager': pager, + 'archive_groups': archive_groups, + 'default_url': '/my/invoices', + 'searchbar_sortings': searchbar_sortings, + 'sortby': sortby, + }) + return request.render("website_account.portal_my_invoices", values) + + @http.route(['/my/invoices/'], type='http', auth="user", website=True) + def portal_my_invoices_report(self, invoice_id, **kw): + invoice = request.env['account.invoice'].browse(invoice_id) + try: + invoice.check_access_rights('read') + invoice.check_access_rule('read') + except AccessError: + return request.render("website.403") + # 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_id])[0] + pdfhttpheaders = [ + ('Content-Type', 'application/pdf'), + ('Content-Length', len(pdf)), + ] + return request.make_response(pdf, headers=pdfhttpheaders) + + def details_form_validate(self, data): + error, error_message = super(website_account, self).details_form_validate(data) + # prevent VAT/name change if invoices exist + partner = request.env['res.users'].browse(request.uid).partner_id + invoices = request.env['account.invoice'].sudo().search_count([('partner_id', '=', partner.id), ('state', 'not in', ['draft', 'cancel'])]) + if invoices: + if 'vat' in partner and (data['vat'] or False) != (partner.vat or False): + error['vat'] = 'error' + error_message.append(_('Changing VAT number is not allowed once invoices have been issued for your account. Please contact us directly for this operation.')) + if 'name' in data and (data['name'] or False) != (partner.name or False): + error['name'] = 'error' + error_message.append(_('Changing your name is not allowed once invoices have been issued for your account. Please contact us directly for this operation.')) + return error, error_message diff --git a/addons/website_account/models/__init__.py b/addons/website_account/models/__init__.py new file mode 100644 index 00000000000..0967df7c738 --- /dev/null +++ b/addons/website_account/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import account_invoice diff --git a/addons/website_portal_sale/models/account_invoice.py b/addons/website_account/models/account_invoice.py similarity index 100% rename from addons/website_portal_sale/models/account_invoice.py rename to addons/website_account/models/account_invoice.py diff --git a/addons/website_account/security/account.xml b/addons/website_account/security/account.xml new file mode 100644 index 00000000000..1a3889d8280 --- /dev/null +++ b/addons/website_account/security/account.xml @@ -0,0 +1,18 @@ + + + + + Portal Personal Account Invoices + + [('message_partner_ids','child_of',[user.commercial_partner_id.id])] + + + + + Portal Invoice Lines + + [('invoice_id.message_partner_ids','child_of',[user.commercial_partner_id.id])] + + + + diff --git a/addons/website_account/security/ir.model.access.csv b/addons/website_account/security/ir.model.access.csv new file mode 100644 index 00000000000..6bf20086200 --- /dev/null +++ b/addons/website_account/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_invoice,account.invoice,account.model_account_invoice,base.group_portal,1,0,0,0 +access_account_invoice_line,account.invoice.line,account.model_account_invoice_line,base.group_portal,1,0,0,0 \ No newline at end of file diff --git a/addons/website_account/views/account_templates.xml b/addons/website_account/views/account_templates.xml new file mode 100644 index 00000000000..ad9cd8c46b6 --- /dev/null +++ b/addons/website_account/views/account_templates.xml @@ -0,0 +1,74 @@ + + + + + + + \ No newline at end of file diff --git a/addons/website_account/views/account_views.xml b/addons/website_account/views/account_views.xml new file mode 100644 index 00000000000..55f659686fc --- /dev/null +++ b/addons/website_account/views/account_views.xml @@ -0,0 +1,13 @@ + + + + account.invoice.select.share + account.invoice + + + + [('share','=', False)] + + + + diff --git a/addons/website_portal_sale/__manifest__.py b/addons/website_portal_sale/__manifest__.py index cb2311347e5..a58003929b8 100644 --- a/addons/website_portal_sale/__manifest__.py +++ b/addons/website_portal_sale/__manifest__.py @@ -4,10 +4,10 @@ { 'name': 'Website Portal for Sales', 'category': 'Website', - 'summary': 'Add your sales document in the frontend portal (sales order, quotations, invoices)', + 'summary': 'Add your sales document in the frontend portal (sales order, quotations)', 'version': '1.0', 'description': """ -Add your sales document in the frontend portal. Your customers will be able to connect to their portal to see the list (and the state) of their invoices (pdf report), sales orders and quotations (web pages). +Add your sales document in the frontend portal. Your customers will be able to connect to their portal to see the list (and the state) of their sales orders and quotations (web pages). """, 'depends': [ 'sale', @@ -16,8 +16,8 @@ Add your sales document in the frontend portal. Your customers will be able to c ], 'data': [ 'views/crm_team_views.xml', - 'views/website_portal_sale_templates.xml', 'views/sale_order_views.xml', + 'views/website_portal_sale_templates.xml', 'security/ir.model.access.csv', 'security/sale_order_security.xml', ], diff --git a/addons/website_portal_sale/controllers/main.py b/addons/website_portal_sale/controllers/main.py index 0edaffb85de..0b7a1e18724 100644 --- a/addons/website_portal_sale/controllers/main.py +++ b/addons/website_portal_sale/controllers/main.py @@ -15,7 +15,6 @@ class website_account(website_account): partner = request.env.user.partner_id SaleOrder = request.env['sale.order'] - Invoice = request.env['account.invoice'] quotation_count = SaleOrder.search_count([ ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), ('state', 'in', ['sent', 'cancel']) @@ -24,16 +23,10 @@ class website_account(website_account): ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), ('state', 'in', ['sale', 'done']) ]) - invoice_count = Invoice.search_count([ - ('type', 'in', ['out_invoice', 'out_refund']), - ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), - ('state', 'in', ['open', 'paid', 'cancel']) - ]) values.update({ 'quotation_count': quotation_count, 'order_count': order_count, - 'invoice_count': invoice_count, }) return values @@ -160,89 +153,3 @@ class website_account(website_account): } values.update(get_records_pager(history, order)) return request.render("website_portal_sale.orders_followup", values) - - # - # Invoices - # - - @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 = [ - ('type', 'in', ['out_invoice', 'out_refund']), - ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]), - ('state', 'in', ['open', 'paid', 'cancelled']) - ] - - searchbar_sortings = { - 'date': {'label': _('Invoice Date'), 'order': 'date_invoice desc'}, - 'duedate': {'label': _('Due Date'), 'order': 'date_due desc'}, - 'name': {'label': _('Reference'), 'order': 'name desc'}, - 'state': {'label': _('Status'), 'order': 'state'}, - } - # default sort by order - if not sortby: - sortby = 'date' - order = searchbar_sortings[sortby]['order'] - - archive_groups = self._get_archive_groups('account.invoice', domain) - if date_begin and date_end: - domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)] - - # count for pager - invoice_count = AccountInvoice.search_count(domain) - # pager - pager = request.website.pager( - url="/my/invoices", - url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby}, - total=invoice_count, - page=page, - step=self._items_per_page - ) - # content according to pager and archive selected - invoices = AccountInvoice.search(domain, order=order, limit=self._items_per_page, offset=pager['offset']) - values.update({ - 'date': date_begin, - 'invoices': invoices, - 'page_name': 'invoice', - 'pager': pager, - 'archive_groups': archive_groups, - 'default_url': '/my/invoices', - 'searchbar_sortings': searchbar_sortings, - 'sortby': sortby, - }) - return request.render("website_portal_sale.portal_my_invoices", values) - - @http.route(['/my/invoices/'], type='http', auth="user", website=True) - def portal_my_invoices_report(self, invoice_id, **kw): - invoice = request.env['account.invoice'].browse(invoice_id) - try: - invoice.check_access_rights('read') - invoice.check_access_rule('read') - except AccessError: - return request.render("website.403") - # 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_id])[0] - pdfhttpheaders = [ - ('Content-Type', 'application/pdf'), - ('Content-Length', len(pdf)), - ] - return request.make_response(pdf, headers=pdfhttpheaders) - - def details_form_validate(self, data): - error, error_message = super(website_account, self).details_form_validate(data) - # prevent VAT/name change if invoices exist - partner = request.env['res.users'].browse(request.uid).partner_id - invoices = request.env['account.invoice'].sudo().search_count([('partner_id', '=', partner.id), ('state', 'not in', ['draft', 'cancel'])]) - if invoices: - if 'vat' in partner and (data['vat'] or False) != (partner.vat or False): - error['vat'] = 'error' - error_message.append(_('Changing VAT number is not allowed once invoices have been issued for your account. Please contact us directly for this operation.')) - if 'name' in data and (data['name'] or False) != (partner.name or False): - error['name'] = 'error' - error_message.append(_('Changing your name is not allowed once invoices have been issued for your account. Please contact us directly for this operation.')) - return error, error_message diff --git a/addons/website_portal_sale/models/__init__.py b/addons/website_portal_sale/models/__init__.py index 9aa8c7def03..d23316440e4 100644 --- a/addons/website_portal_sale/models/__init__.py +++ b/addons/website_portal_sale/models/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import account_invoice from . import crm_team from . import sale_order from . import payment diff --git a/addons/website_portal_sale/security/ir.model.access.csv b/addons/website_portal_sale/security/ir.model.access.csv index 2033898fc32..fa1ee2d0443 100644 --- a/addons/website_portal_sale/security/ir.model.access.csv +++ b/addons/website_portal_sale/security/ir.model.access.csv @@ -1,5 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_sale_order,sale.order,sale.model_sale_order,base.group_portal,1,0,0,0 -access_sale_order_line,sale.order.line,sale.model_sale_order_line,base.group_portal,1,0,0,0 -access_account_invoice,account.invoice,account.model_account_invoice,base.group_portal,1,0,0,0 -access_account_invoice_line,account.invoice.line,account.model_account_invoice_line,base.group_portal,1,0,0,0 +access_sale_order_line,sale.order.line,sale.model_sale_order_line,base.group_portal,1,0,0,0 \ No newline at end of file diff --git a/addons/website_portal_sale/security/sale_order_security.xml b/addons/website_portal_sale/security/sale_order_security.xml index aa97cba3ea0..8f5b5b4cc80 100644 --- a/addons/website_portal_sale/security/sale_order_security.xml +++ b/addons/website_portal_sale/security/sale_order_security.xml @@ -1,7 +1,6 @@ - Portal Personal Quotations/Sales Orders @@ -20,21 +19,5 @@ [('order_id.message_partner_ids','child_of',[user.commercial_partner_id.id])] - - - - Portal Personal Account Invoices - - [('message_partner_ids','child_of',[user.commercial_partner_id.id])] - - - - - Portal Invoice Lines - - [('invoice_id.message_partner_ids','child_of',[user.commercial_partner_id.id])] - - - diff --git a/addons/website_portal_sale/static/src/less/website_portal_sale.less b/addons/website_portal_sale/static/src/less/website_portal_sale.less index dfdc8ec75f2..dd3528e3628 100644 --- a/addons/website_portal_sale/static/src/less/website_portal_sale.less +++ b/addons/website_portal_sale/static/src/less/website_portal_sale.less @@ -8,7 +8,3 @@ .orders_label_text_align { vertical-align: 15%; } - -.cell_overflow { - overflow: hidden; -} diff --git a/addons/website_portal_sale/views/sale_order_views.xml b/addons/website_portal_sale/views/sale_order_views.xml index 0a06daf69fd..002866c781f 100644 --- a/addons/website_portal_sale/views/sale_order_views.xml +++ b/addons/website_portal_sale/views/sale_order_views.xml @@ -1,16 +1,5 @@ - - account.invoice.select.share - account.invoice - - - - [('share','=', False)] - - - - sale.order.form sale.order diff --git a/addons/website_portal_sale/views/website_portal_sale_templates.xml b/addons/website_portal_sale/views/website_portal_sale_templates.xml index 5e3eec666da..8a67a279532 100644 --- a/addons/website_portal_sale/views/website_portal_sale_templates.xml +++ b/addons/website_portal_sale/views/website_portal_sale_templates.xml @@ -17,14 +17,6 @@ - - - - - -