[ADD]16.0-bank_and_contract_portal:add rules for internal user using portal
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# Copyright 2020 Lokavaluto ()
|
||||
# Copyright 2024 Lokavaluto ()
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
from odoo import http, tools, _
|
||||
from odoo.exceptions import AccessError, MissingError
|
||||
from odoo.http import request
|
||||
@@ -49,45 +48,10 @@ class CustomerPortalBankAccount(CustomerPortal):
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_id_fields(self):
|
||||
fields = [
|
||||
"bank_id",
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_main_boolean_bank_account_fields(self):
|
||||
'''Provides the fields for which we must check the presence
|
||||
in form's kw to know the value to save in the partner field.
|
||||
All of them MUST start with "main_".'''
|
||||
fields = []
|
||||
return fields
|
||||
|
||||
def _transform_res_partner_fields(self, kw, bank_account_fields, prefix=""):
|
||||
'''Transforms kw's values in res_partner fields and values'''
|
||||
return {key[len(prefix):]: kw[key] for key in bank_account_fields if key in kw}
|
||||
|
||||
def _cast_id_fields(self, kw, id_fields):
|
||||
'''Cast ids fields in kw's values into a integer'''
|
||||
result = {}
|
||||
for key in id_fields:
|
||||
if key in kw:
|
||||
if kw[key] == '':
|
||||
result[key] = None
|
||||
elif not isinstance(kw[key], int):
|
||||
result[key] = int(kw[key])
|
||||
else:
|
||||
result[key] = kw[key]
|
||||
return result
|
||||
|
||||
def _add_boolean_values(self, values, kw, boolean_fields, prefix=""):
|
||||
for key in boolean_fields:
|
||||
values.update(
|
||||
{
|
||||
key[len(prefix):]: kw.get(key, "off") == "on",
|
||||
}
|
||||
)
|
||||
return values
|
||||
|
||||
def _get_page_saving_bank_account_values(self, kw):
|
||||
bank_account_fields = self._get_bank_account_fields()
|
||||
values = self._transform_res_partner_fields(kw, bank_account_fields)
|
||||
|
@@ -14,7 +14,7 @@ class CustomerPortalBankAccounts(CustomerPortal):
|
||||
def _prepare_home_portal_values(self, counters):
|
||||
values = super()._prepare_home_portal_values(counters)
|
||||
if 'bank_account_count' in counters:
|
||||
bank_account_count = request.env['res.partner.bank'].search_count([])
|
||||
bank_account_count = request.env['res.partner.bank'].search_count([('partner_id', '=', request.env.user.partner_id.id)])
|
||||
values['bank_account_count'] = bank_account_count
|
||||
return values
|
||||
|
||||
@@ -23,8 +23,6 @@ class CustomerPortalBankAccounts(CustomerPortal):
|
||||
res['acc_number'] = {'label': _('IBAN'), 'order': 'acc_number'}
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@http.route(['/my/bank_accounts', '/my/bank_accounts/page/<int:page>'], type='http', auth="user", website=True)
|
||||
def portal_my_bank_accounts(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw):
|
||||
values = self._prepare_my_bank_accounts_values(page, date_begin, date_end, sortby, filterby)
|
||||
@@ -43,7 +41,7 @@ class CustomerPortalBankAccounts(CustomerPortal):
|
||||
return request.render("partner_bank_account_portal.portal_my_bank_accounts", values)
|
||||
|
||||
def _get_bank_accounts_domain(self):
|
||||
return [('active', '=', True)]
|
||||
return [('active', '=', True),('partner_id', '=', request.env.user.partner_id.id)]
|
||||
|
||||
|
||||
def _prepare_my_bank_accounts_values(self, page, date_begin, date_end, sortby, filterby, domain=None, url="/my/bank_accounts"):
|
||||
|
@@ -1,6 +1,5 @@
|
||||
# Copyright 2020 Lokavaluto ()
|
||||
# Copyright 2024 Lokavaluto ()
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
from odoo import http, tools, _
|
||||
from odoo.exceptions import AccessError, MissingError
|
||||
from odoo.http import request
|
||||
@@ -51,31 +50,13 @@ class CustomerPortalMandate(CustomerPortal):
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_main_boolean_mandate_fields(self):
|
||||
'''Provides the fields for which we must check the presence
|
||||
in form's kw to know the value to save in the partner field.
|
||||
All of them MUST start with "main_".'''
|
||||
fields = []
|
||||
return fields
|
||||
|
||||
def _transform_in_res_partner_fields(self, kw, mandate_fields, prefix=""):
|
||||
'''Transforms kw's values in res_partner fields and values'''
|
||||
return {key[len(prefix):]: kw[key] for key in mandate_fields if key in kw}
|
||||
|
||||
def _add_boolean_values(self, values, kw, boolean_fields, prefix=""):
|
||||
for key in boolean_fields:
|
||||
values.update(
|
||||
{
|
||||
key[len(prefix):]: kw.get(key, "off") == "on",
|
||||
}
|
||||
)
|
||||
return values
|
||||
|
||||
def _get_page_saving_mandate_values(self, kw):
|
||||
mandate_fields = self._get_mandate_fields()
|
||||
values = self._transform_in_res_partner_fields(kw, mandate_fields)
|
||||
# boolean_fields = self._get_main_boolean_bank_account_fields()
|
||||
# values = self._add_boolean_values(values, kw, boolean_fields)
|
||||
return values
|
||||
|
||||
def _get_page_opening_values(self):
|
||||
@@ -95,12 +76,8 @@ class CustomerPortalMandate(CustomerPortal):
|
||||
def portal_my_mandate(
|
||||
self,mandate_id=None, access_token=None, redirect=None, **kw
|
||||
):
|
||||
# The following condition is to transform profile_id to an int, as it is sent as a string from the templace "portal_my_profile"
|
||||
# TODO: find a better way to retrieve the profile_id at form submit step
|
||||
if not isinstance(mandate_id, int):
|
||||
mandate_id = int(mandate_id)
|
||||
|
||||
# Check that the user has the right to see this profile
|
||||
try:
|
||||
mandate_sudo = self._document_check_access(
|
||||
"account.banking.mandate", mandate_id, access_token
|
||||
@@ -125,16 +102,8 @@ class CustomerPortalMandate(CustomerPortal):
|
||||
values.update({"error": error, "error_message": error_message})
|
||||
values.update(kw)
|
||||
if not error:
|
||||
# Update main profile
|
||||
new_values = self._get_page_saving_mandate_values(kw)
|
||||
mandate.sudo().write(new_values)
|
||||
# Update public profile
|
||||
# new_values = self._get_page_saving_public_structure_values(kw)
|
||||
# public_profile.sudo().write(new_values)
|
||||
# Update position profile
|
||||
# new_values = self._get_page_saving_position_structure_values(kw)
|
||||
# position_profile.sudo().write(new_values)
|
||||
# End of updates
|
||||
if redirect:
|
||||
return request.redirect(redirect)
|
||||
return request.redirect("/my/mandates")
|
||||
|
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import http, _
|
||||
from odoo import http
|
||||
from odoo.osv import expression
|
||||
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
|
||||
|
||||
|
||||
@@ -14,7 +12,7 @@ class CustomerPortalMandates(CustomerPortal):
|
||||
def _prepare_home_portal_values(self, counters):
|
||||
values = super()._prepare_home_portal_values(counters)
|
||||
if 'mandate_count' in counters:
|
||||
mandate_count = request.env['account.banking.mandate'].search_count([])
|
||||
mandate_count = request.env['account.banking.mandate'].search_count([('partner_id', '=', request.env.user.partner_id.id)])
|
||||
values['mandate_count'] = mandate_count
|
||||
return values
|
||||
|
||||
@@ -36,7 +34,7 @@ class CustomerPortalMandates(CustomerPortal):
|
||||
return request.render("partner_bank_account_portal.portal_my_mandates", values)
|
||||
|
||||
def _get_mandate_domain(self):
|
||||
return []
|
||||
return [('partner_id', '=', request.env.user.partner_id.id)]
|
||||
|
||||
def _prepare_my_mandates_values(self, page, date_begin, date_end, domain=None, url="/my/mandates"):
|
||||
values = self._prepare_portal_layout_values()
|
||||
|
Reference in New Issue
Block a user