summaryrefslogtreecommitdiff
path: root/addons/account/controllers
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account/controllers
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account/controllers')
-rw-r--r--addons/account/controllers/__init__.py5
-rw-r--r--addons/account/controllers/onboarding.py41
-rw-r--r--addons/account/controllers/portal.py127
3 files changed, 173 insertions, 0 deletions
diff --git a/addons/account/controllers/__init__.py b/addons/account/controllers/__init__.py
new file mode 100644
index 00000000..1a195b71
--- /dev/null
+++ b/addons/account/controllers/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import onboarding
+from . import portal
diff --git a/addons/account/controllers/onboarding.py b/addons/account/controllers/onboarding.py
new file mode 100644
index 00000000..3c0afa38
--- /dev/null
+++ b/addons/account/controllers/onboarding.py
@@ -0,0 +1,41 @@
+from odoo import http
+from odoo.http import request
+
+
+class OnboardingController(http.Controller):
+
+ @http.route('/account/account_invoice_onboarding', auth='user', type='json')
+ def account_invoice_onboarding(self):
+ """ Returns the `banner` for the account invoice onboarding panel.
+ It can be empty if the user has closed it or if he doesn't have
+ the permission to see it. """
+
+ company = request.env.company
+ if not request.env.is_admin() or \
+ company.account_invoice_onboarding_state == 'closed':
+ return {}
+
+ return {
+ 'html': request.env.ref('account.account_invoice_onboarding_panel')._render({
+ 'company': company,
+ 'state': company.get_and_update_account_invoice_onboarding_state()
+ })
+ }
+
+ @http.route('/account/account_dashboard_onboarding', auth='user', type='json')
+ def account_dashboard_onboarding(self):
+ """ Returns the `banner` for the account dashboard onboarding panel.
+ It can be empty if the user has closed it or if he doesn't have
+ the permission to see it. """
+ company = request.env.company
+
+ if not request.env.is_admin() or \
+ company.account_dashboard_onboarding_state == 'closed':
+ return {}
+
+ return {
+ 'html': request.env.ref('account.account_dashboard_onboarding_panel')._render({
+ 'company': company,
+ 'state': company.get_and_update_account_dashboard_onboarding_state()
+ })
+ }
diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py
new file mode 100644
index 00000000..540aec11
--- /dev/null
+++ b/addons/account/controllers/portal.py
@@ -0,0 +1,127 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import http, _
+from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
+from odoo.exceptions import AccessError, MissingError
+from collections import OrderedDict
+from odoo.http import request
+
+
+class PortalAccount(CustomerPortal):
+
+ def _prepare_home_portal_values(self, counters):
+ values = super()._prepare_home_portal_values(counters)
+ if 'invoice_count' in counters:
+ invoice_count = request.env['account.move'].search_count([
+ ('move_type', 'in', ('out_invoice', 'in_invoice', 'out_refund', 'in_refund', 'out_receipt', 'in_receipt')),
+ ]) if request.env['account.move'].check_access_rights('read', raise_exception=False) else 0
+ values['invoice_count'] = invoice_count
+ return values
+
+ # ------------------------------------------------------------
+ # My Invoices
+ # ------------------------------------------------------------
+
+ def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
+ values = {
+ 'page_name': 'invoice',
+ 'invoice': invoice,
+ }
+ 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, filterby=None, **kw):
+ values = self._prepare_portal_layout_values()
+ AccountInvoice = request.env['account.move']
+
+ domain = [('move_type', 'in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]
+
+ searchbar_sortings = {
+ 'date': {'label': _('Date'), 'order': 'invoice_date desc'},
+ 'duedate': {'label': _('Due Date'), 'order': 'invoice_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']
+
+ searchbar_filters = {
+ 'all': {'label': _('All'), 'domain': []},
+ 'invoices': {'label': _('Invoices'), 'domain': [('move_type', '=', ('out_invoice', 'out_refund'))]},
+ 'bills': {'label': _('Bills'), 'domain': [('move_type', '=', ('in_invoice', 'in_refund'))]},
+ }
+ # default filter by value
+ if not filterby:
+ filterby = 'all'
+ domain += searchbar_filters[filterby]['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 = portal_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'])
+ request.session['my_invoices_history'] = invoices.ids[:100]
+
+ values.update({
+ 'date': date_begin,
+ 'invoices': invoices,
+ 'page_name': 'invoice',
+ 'pager': pager,
+ 'default_url': '/my/invoices',
+ 'searchbar_sortings': searchbar_sortings,
+ 'sortby': sortby,
+ 'searchbar_filters': OrderedDict(sorted(searchbar_filters.items())),
+ 'filterby':filterby,
+ })
+ 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, report_type=None, download=False, **kw):
+ try:
+ invoice_sudo = self._document_check_access('account.move', 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)
+ acquirers = values.get('acquirers')
+ if acquirers:
+ country_id = values.get('partner_id') and values.get('partner_id')[0].country_id.id
+ values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id)
+
+ return request.render("account.portal_invoice_page", values)
+
+ # ------------------------------------------------------------
+ # My Home
+ # ------------------------------------------------------------
+
+ def details_form_validate(self, data):
+ error, error_message = super(PortalAccount, self).details_form_validate(data)
+ # prevent VAT/name change if invoices exist
+ partner = request.env['res.users'].browse(request.uid).partner_id
+ if not partner.can_edit_vat():
+ if 'vat' in data 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.'))
+ if 'company_name' in data and (data['company_name'] or False) != (partner.company_name or False):
+ error['company_name'] = 'error'
+ error_message.append(_('Changing your company name is not allowed once invoices have been issued for your account. Please contact us directly for this operation.'))
+ return error, error_message