remove modules in v12
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import portal_my_structures
|
||||
from . import portal_structure_profile
|
||||
from . import portal_my_positions
|
||||
from . import portal_position_profile
|
||||
from . import portal_my_account
|
@@ -1,169 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
from odoo import tools
|
||||
from odoo.http import request, route
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
||||
|
||||
class CustomerPortalMyProfile(CustomerPortal):
|
||||
|
||||
def _get_mandatory_main_fields(self):
|
||||
return ["main_name", "main_email"]
|
||||
|
||||
def _get_optional_main_fields(self):
|
||||
return ["main_street", "main_street2", "main_city", "main_country_id", "main_phone", "main_mobile", "main_zip", "main_state_id", "main_website"]
|
||||
|
||||
def _get_mandatory_public_fields(self):
|
||||
return ["public_name"]
|
||||
|
||||
def _get_optional_public_fields(self):
|
||||
return ["public_email", "public_street", "public_street2", "public_city", "public_phone", "public_mobile", "public_zip", "public_website"]
|
||||
|
||||
def _get_special_fields(self):
|
||||
return ["main_logo"]
|
||||
|
||||
def _get_main_boolean_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 _get_public_boolean_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 "public_".'''
|
||||
fields = []
|
||||
return fields
|
||||
|
||||
def _transform_in_partner_fields(self, kw, profile_fields, prefix=""):
|
||||
'''Transforms kw's values in res_partner fields and values'''
|
||||
return {key[len(prefix):]: kw[key] for key in profile_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 _retrieve_main_values(self, data):
|
||||
main_fields = self._get_mandatory_main_fields() + self._get_optional_main_fields()
|
||||
values = self._transform_in_partner_fields(data, main_fields, "main_")
|
||||
boolean_fields = self._get_main_boolean_account_fields()
|
||||
values = self._add_boolean_values(values, data, boolean_fields, "main_")
|
||||
if 'main_logo' in data:
|
||||
image = data.get('main_logo')
|
||||
if image:
|
||||
image = image.read()
|
||||
image = base64.b64encode(image)
|
||||
values.update({
|
||||
'image': image
|
||||
})
|
||||
return values
|
||||
|
||||
def _retrieve_public_values(self, data):
|
||||
public_fields = self._get_mandatory_public_fields() + self._get_optional_public_fields()
|
||||
values = self._transform_in_partner_fields(data, public_fields, "public_")
|
||||
boolean_fields = self._get_public_boolean_account_fields()
|
||||
values = self._add_boolean_values(values, data, boolean_fields, "public_")
|
||||
return values
|
||||
|
||||
def _get_page_opening_values(self):
|
||||
# Just retrieve the values to display for Selection fields
|
||||
countries = request.env["res.country"].sudo().search([])
|
||||
states = request.env['res.country.state'].sudo().search([])
|
||||
values = {
|
||||
"countries": countries,
|
||||
'states': states,
|
||||
}
|
||||
return values
|
||||
|
||||
@route(["/my/account"], type="http", auth="user", website=True)
|
||||
def account(self, redirect=None, **post):
|
||||
values = self._prepare_portal_layout_values()
|
||||
user = request.env.user
|
||||
partner = user.partner_id
|
||||
public_partner = partner.public_profile_id
|
||||
values.update({
|
||||
'error': {},
|
||||
'error_message': [],
|
||||
})
|
||||
|
||||
if post and request.httprequest.method == 'POST':
|
||||
error, error_message = self.details_form_validate(post)
|
||||
values.update({'error': error, 'error_message': error_message})
|
||||
values.update(post)
|
||||
if not error:
|
||||
# Save main profile values
|
||||
values = self._retrieve_main_values(post)
|
||||
partner.sudo().write(values)
|
||||
# Save public profile values
|
||||
public_values = self._retrieve_public_values(post)
|
||||
if len(public_values) > 0:
|
||||
public_partner.sudo().write(public_values)
|
||||
# Email change generates a change of user's login
|
||||
if post.get("main_email", user.login) != user.login:
|
||||
user.login = post["main_email"]
|
||||
return request.redirect("/web/session/logout")
|
||||
if redirect:
|
||||
return request.redirect(redirect)
|
||||
return request.redirect('/my/home')
|
||||
|
||||
values.update(self._get_page_opening_values())
|
||||
values.update({
|
||||
'partner': partner,
|
||||
'public_partner': public_partner,
|
||||
'has_check_vat': hasattr(request.env['res.partner'], 'check_vat'),
|
||||
'redirect': "/my/account?success=True",
|
||||
'page_name': 'my_details',
|
||||
})
|
||||
|
||||
response = request.render("portal.portal_my_details", values)
|
||||
response.headers['X-Frame-Options'] = 'DENY'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
def details_form_validate(self, data):
|
||||
error = dict()
|
||||
error_message = []
|
||||
|
||||
# Validation
|
||||
for field_name in self._get_mandatory_main_fields() + self._get_mandatory_public_fields():
|
||||
if not data.get(field_name):
|
||||
error[field_name] = 'missing'
|
||||
|
||||
# email validation
|
||||
if data.get('main_email') and not tools.single_email_re.match(data.get('main_email')):
|
||||
error["main_email"] = 'error'
|
||||
error_message.append(_('Invalid Email! Please enter a valid email address.'))
|
||||
if data.get('public_email') and not tools.single_email_re.match(data.get('public_email')):
|
||||
error["public_email"] = 'error'
|
||||
error_message.append(_('Invalid Public Email! Please enter a valid public email address.'))
|
||||
|
||||
# public name uniqueness
|
||||
if data.get("public_name") and request.env["res.partner"].sudo().search(
|
||||
[
|
||||
("name", "=", data.get("public_name")),
|
||||
("is_public_profile", "=", True),
|
||||
("contact_id", "!=", request.env.user.partner_id.id),
|
||||
]
|
||||
):
|
||||
error["public_name"] = "error"
|
||||
error_message.append(
|
||||
_("This public name is already used, please find an other idea.")
|
||||
)
|
||||
|
||||
# error message for empty required fields
|
||||
if [err for err in error.values() if err == 'missing']:
|
||||
error_message.append('Some required fields are empty.')
|
||||
|
||||
unknown = [k for k in data if k not in self._get_mandatory_main_fields() + self._get_optional_main_fields() + self._get_mandatory_public_fields() + self._get_optional_public_fields() + self._get_special_fields()]
|
||||
if unknown:
|
||||
error['common'] = 'Unknown field'
|
||||
error_message.append("Unknown field '%s'" % ','.join(unknown))
|
||||
|
||||
return error, error_message
|
@@ -1,80 +0,0 @@
|
||||
# Copyright 2020 Lokavaluto ()
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import http, _
|
||||
from odoo.http import request
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
||||
|
||||
|
||||
class CustomerPortalMyPositions(CustomerPortal):
|
||||
|
||||
def _get_domain_my_positions(self, user):
|
||||
if user.partner_id.structure_position_ids:
|
||||
return [("id", "in", user.partner_id.structure_position_ids.ids),
|
||||
("is_company", "=", False),
|
||||
("is_position_profile", "=", True),
|
||||
]
|
||||
else:
|
||||
return None
|
||||
|
||||
def _prepare_portal_layout_values(self):
|
||||
values = super(CustomerPortalMyPositions, self)._prepare_portal_layout_values()
|
||||
domain = self._get_domain_my_structures(request.env.user)
|
||||
values["structure_count"] = request.env["res.partner"].search_count(domain) if domain else 0
|
||||
return values
|
||||
|
||||
@http.route(
|
||||
["/my/positions", "/my/positions/page/<int:page>"],
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_positions(
|
||||
self, page=1, date_begin=None, date_end=None, sortby=None, **kw
|
||||
):
|
||||
values = self._prepare_portal_layout_values()
|
||||
position = request.env["res.partner"]
|
||||
domain = self._get_domain_my_positions(request.env.user)
|
||||
|
||||
searchbar_sortings = {
|
||||
"name": {"label": _("Name"), "order": "name"},
|
||||
"parent_id": {"label": _("Company"), "order": "parent_id"},
|
||||
}
|
||||
if not sortby:
|
||||
sortby = "name"
|
||||
order = searchbar_sortings[sortby]["order"]
|
||||
|
||||
# archive groups - Default Group By 'create_date'
|
||||
archive_groups = self._get_archive_groups("res.partner", domain)
|
||||
|
||||
# structures count
|
||||
position_count = position.search_count(domain) if domain else 0
|
||||
# pager
|
||||
pager = portal_pager(
|
||||
url="/my/positions",
|
||||
url_args={"sortby": sortby},
|
||||
total=position_count,
|
||||
page=page,
|
||||
step=self._items_per_page,
|
||||
)
|
||||
|
||||
# content according to pager and archive selected
|
||||
positions = position.search(
|
||||
domain,
|
||||
order=order,
|
||||
limit=self._items_per_page,
|
||||
offset=pager["offset"],
|
||||
) if domain else None
|
||||
request.session["my_positions_history"] = positions.ids[:100] if positions else None
|
||||
|
||||
values.update(
|
||||
{
|
||||
"positions": positions,
|
||||
"page_name": "position",
|
||||
"archive_groups": archive_groups,
|
||||
"default_url": "/my/positions",
|
||||
"pager": pager,
|
||||
"searchbar_sortings": searchbar_sortings,
|
||||
"sortby": sortby,
|
||||
}
|
||||
)
|
||||
return request.render("partner_profiles_portal.portal_my_positions", values)
|
@@ -1,80 +0,0 @@
|
||||
# Copyright 2020 Lokavaluto ()
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import http, _
|
||||
from odoo.http import request
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
||||
|
||||
|
||||
class CustomerPortalMyStructures(CustomerPortal):
|
||||
|
||||
def _get_domain_my_structures(self, user):
|
||||
if user.partner_id.other_contact_ids:
|
||||
main_structure_ids = user.partner_id.other_contact_ids.mapped("parent_id")
|
||||
return [("id", "in", main_structure_ids.ids),
|
||||
("is_company", "=", True)
|
||||
]
|
||||
else:
|
||||
return None
|
||||
|
||||
def _prepare_portal_layout_values(self):
|
||||
values = super(CustomerPortalMyStructures, self)._prepare_portal_layout_values()
|
||||
domain = self._get_domain_my_structures(request.env.user)
|
||||
values["structure_count"] = request.env["res.partner"].search_count(domain) if domain else 0
|
||||
return values
|
||||
|
||||
@http.route(
|
||||
["/my/structures", "/my/structures/page/<int:page>"],
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_structures(
|
||||
self, page=1, date_begin=None, date_end=None, sortby=None, **kw
|
||||
):
|
||||
values = self._prepare_portal_layout_values()
|
||||
structure = request.env["res.partner"]
|
||||
domain = self._get_domain_my_structures(request.env.user)
|
||||
|
||||
searchbar_sortings = {
|
||||
"name": {"label": _("Name"), "order": "name"},
|
||||
"parent_id": {"label": _("Company"), "order": "parent_id"},
|
||||
}
|
||||
if not sortby:
|
||||
sortby = "name"
|
||||
order = searchbar_sortings[sortby]["order"]
|
||||
|
||||
# archive groups - Default Group By 'create_date'
|
||||
archive_groups = self._get_archive_groups("res.partner", domain)
|
||||
|
||||
# structures count
|
||||
structure_count = structure.search_count(domain) if domain else 0
|
||||
# pager
|
||||
pager = portal_pager(
|
||||
url="/my/structures",
|
||||
url_args={"sortby": sortby},
|
||||
total=structure_count,
|
||||
page=page,
|
||||
step=self._items_per_page,
|
||||
)
|
||||
|
||||
# content according to pager and archive selected
|
||||
structures = structure.search(
|
||||
domain,
|
||||
order=order,
|
||||
limit=self._items_per_page,
|
||||
offset=pager["offset"],
|
||||
) if domain else None
|
||||
request.session["my_structures_history"] = structures.ids[:100] if structures else None
|
||||
|
||||
values.update(
|
||||
{
|
||||
"structures": structures,
|
||||
"page_name": "structure",
|
||||
"archive_groups": archive_groups,
|
||||
"default_url": "/my/structures",
|
||||
"pager": pager,
|
||||
"searchbar_sortings": searchbar_sortings,
|
||||
"sortby": sortby,
|
||||
}
|
||||
)
|
||||
return request.render("partner_profiles_portal.portal_my_structures", values)
|
@@ -1,120 +0,0 @@
|
||||
# Copyright 2020 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
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
||||
|
||||
|
||||
class CustomerPortalPositionProfile(CustomerPortal):
|
||||
|
||||
def _position_get_page_view_values(self, position, access_token, **kwargs):
|
||||
values = {
|
||||
"page_name": "position",
|
||||
"position": position,
|
||||
}
|
||||
return self._get_page_view_values(
|
||||
position, access_token, values, "my_positions_history", False, **kwargs
|
||||
)
|
||||
|
||||
def _details_position_form_validate(self, data, position_id):
|
||||
error = dict()
|
||||
error_message = []
|
||||
# email validation
|
||||
if data.get("email") and not tools.single_email_re.match(data.get("email")):
|
||||
error["email"] = "error"
|
||||
error_message.append(
|
||||
_("Invalid Email! Please enter a valid email address.")
|
||||
)
|
||||
return error, error_message
|
||||
|
||||
def _get_position_profile_fields(self):
|
||||
'''Provides all the fields that must fill the structure's position profile of the user.
|
||||
All of them MUST start with "position_".'''
|
||||
fields = [
|
||||
"function",
|
||||
"phone",
|
||||
"email",
|
||||
"edit_structure_profiles",
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_position_boolean_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.'''
|
||||
fields = ["edit_structure_profiles"]
|
||||
return fields
|
||||
|
||||
def _transform_fields(self, kw, profile_fields):
|
||||
'''Transforms kw's values in res_partner fields and values'''
|
||||
return {key: kw[key] for key in profile_fields if key in kw}
|
||||
|
||||
def _get_page_saving_position_values(self, kw):
|
||||
profile_fields = self._get_position_profile_fields()
|
||||
values = self._transform_fields(kw, profile_fields)
|
||||
# Boolean fields are not returned in "kw" if their value in the form is False.
|
||||
# Then we have to check their presence to determine which value to save in the partner.
|
||||
boolean_fields = self._get_position_boolean_fields()
|
||||
for key in boolean_fields:
|
||||
values.update(
|
||||
{
|
||||
key: kw.get(key, "off") == "on"
|
||||
}
|
||||
)
|
||||
return values
|
||||
|
||||
@http.route(
|
||||
["/my/position/<int:position_id>", "/my/position/save"],
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_position(
|
||||
self,position_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(position_id, int):
|
||||
position_id = int(position_id)
|
||||
|
||||
# Check that the user has the right to see this profile
|
||||
try:
|
||||
position_sudo = self._document_check_access(
|
||||
"res.partner", position_id, access_token
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my/positions")
|
||||
|
||||
position_profile = request.env["res.partner"].browse(position_id)
|
||||
|
||||
values = self._position_get_page_view_values(position_sudo, access_token, **kw)
|
||||
values.update(
|
||||
{
|
||||
"error": {},
|
||||
"error_message": [],
|
||||
}
|
||||
)
|
||||
if kw and request.httprequest.method == "POST":
|
||||
# the user has clicked in the Save button to save new data
|
||||
error, error_message = self._details_position_form_validate(kw, position_id)
|
||||
values.update({"error": error, "error_message": error_message})
|
||||
values.update(kw)
|
||||
if not error:
|
||||
# Update position profile
|
||||
new_values = self._get_page_saving_position_values(kw)
|
||||
position_profile.sudo().write(new_values)
|
||||
# End of updates
|
||||
if redirect:
|
||||
return request.redirect(redirect)
|
||||
return request.redirect("/my/positions")
|
||||
|
||||
# This is just the form page opening. We send all the data needed for the form fields
|
||||
values.update(
|
||||
{
|
||||
"position_id": position_id, # Sent in order to retrieve it at submit time
|
||||
"position": position_profile,
|
||||
"redirect": "/my/position/" + str(position_id) + "?success=True"
|
||||
}
|
||||
)
|
||||
return request.render("partner_profiles_portal.portal_position", values)
|
@@ -1,234 +0,0 @@
|
||||
# Copyright 2020 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
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
||||
|
||||
|
||||
class CustomerPortalStructureProfile(CustomerPortal):
|
||||
|
||||
def _structure_get_page_view_values(self, structure, access_token, **kwargs):
|
||||
values = {
|
||||
"page_name": "structure",
|
||||
"structure": structure,
|
||||
}
|
||||
return self._get_page_view_values(
|
||||
structure, access_token, values, "my_structures_history", False, **kwargs
|
||||
)
|
||||
|
||||
def _details_structure_form_validate(self, data, structure_id):
|
||||
error = dict()
|
||||
error_message = []
|
||||
# public name uniqueness
|
||||
if data.get("public_name") and request.env["res.partner"].sudo().search(
|
||||
[
|
||||
("name", "=", data.get("public_name")),
|
||||
("is_public_profile", "=", True),
|
||||
("contact_id", "!=", structure_id),
|
||||
]
|
||||
):
|
||||
error["public_name"] = "error"
|
||||
error_message.append(
|
||||
_("This public name is already used, please find an other idea.")
|
||||
)
|
||||
|
||||
# email validation
|
||||
if data.get("email") and not tools.single_email_re.match(data.get("email")):
|
||||
error["email"] = "error"
|
||||
error_message.append(
|
||||
_("Invalid Email! Please enter a valid email address.")
|
||||
)
|
||||
return error, error_message
|
||||
|
||||
def _get_main_profile_fields(self):
|
||||
'''Provides all the fields that must fill the structure's main profile.
|
||||
All of them MUST start with "main_".'''
|
||||
fields = [
|
||||
"main_name",
|
||||
"main_street",
|
||||
"main_street2",
|
||||
"main_zip",
|
||||
"main_city",
|
||||
"main_country_id",
|
||||
"main_phone",
|
||||
"main_mobile",
|
||||
"main_email",
|
||||
"main_website",
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_main_boolean_structure_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 _get_public_profile_fields(self):
|
||||
'''Provides all the fields that must fill the structure's public profile.
|
||||
All of them MUST start with "public_".'''
|
||||
fields = [
|
||||
"public_name",
|
||||
"public_street2",
|
||||
"public_street",
|
||||
"public_zip",
|
||||
"public_city",
|
||||
"public_phone",
|
||||
"public_mobile",
|
||||
"public_email",
|
||||
"public_website",
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_public_boolean_structure_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 "public_".'''
|
||||
fields = []
|
||||
return fields
|
||||
|
||||
def _get_position_profile_fields(self):
|
||||
'''Provides all the fields that must fill the structure's position profile of the user.
|
||||
All of them MUST start with "position_".'''
|
||||
fields = [
|
||||
"position_function",
|
||||
"position_phone",
|
||||
"position_email",
|
||||
]
|
||||
return fields
|
||||
|
||||
def _get_position_boolean_structure_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 "position_".'''
|
||||
fields = []
|
||||
return fields
|
||||
|
||||
def _transform_in_res_partner_fields(self, kw, profile_fields, prefix=""):
|
||||
'''Transforms kw's values in res_partner fields and values'''
|
||||
return {key[len(prefix):]: kw[key] for key in profile_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_main_structure_values(self, kw):
|
||||
profile_fields = self._get_main_profile_fields()
|
||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "main_")
|
||||
boolean_fields = self._get_main_boolean_structure_fields()
|
||||
values = self._add_boolean_values(values, kw, boolean_fields, "main_")
|
||||
if 'logo' in kw:
|
||||
image = kw.get('logo')
|
||||
if image:
|
||||
image = image.read()
|
||||
image = base64.b64encode(image)
|
||||
values.update({
|
||||
'image': image
|
||||
})
|
||||
return values
|
||||
|
||||
def _get_page_saving_public_structure_values(self, kw):
|
||||
profile_fields = self._get_public_profile_fields()
|
||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "public_")
|
||||
boolean_fields = self._get_public_boolean_structure_fields()
|
||||
values = self._add_boolean_values(values, kw, boolean_fields, "public_")
|
||||
return values
|
||||
|
||||
def _get_page_saving_position_structure_values(self, kw):
|
||||
profile_fields = self._get_position_profile_fields()
|
||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "position_")
|
||||
boolean_fields = self._get_position_boolean_structure_fields()
|
||||
values = self._add_boolean_values(values, kw, boolean_fields, "position_")
|
||||
return values
|
||||
|
||||
def _get_page_opening_values(self):
|
||||
# Just retrieve the values to display for Selection fields
|
||||
countries = request.env["res.country"].sudo().search([])
|
||||
values = {
|
||||
"countries": countries,
|
||||
}
|
||||
return values
|
||||
|
||||
@http.route(
|
||||
["/my/structure/<int:structure_id>", "/my/structure/save"],
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_structure(
|
||||
self,structure_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(structure_id, int):
|
||||
structure_id = int(structure_id)
|
||||
|
||||
# Check that the user has the right to see this profile
|
||||
try:
|
||||
structure_sudo = self._document_check_access(
|
||||
"res.partner", structure_id, access_token
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my/structures")
|
||||
|
||||
Partner = request.env["res.partner"]
|
||||
partner_id = request.env.user.partner_id
|
||||
main_profile = Partner.browse(structure_id)
|
||||
public_profile = Partner.browse(main_profile.public_profile_id.id)
|
||||
position_profile = Partner.search(
|
||||
[
|
||||
("parent_id", "=", structure_id),
|
||||
("contact_id", "=", partner_id.id),
|
||||
("is_position_profile", "=", True),
|
||||
("active", "=", True)
|
||||
],
|
||||
limit=1
|
||||
)[0]
|
||||
|
||||
values = self._structure_get_page_view_values(structure_sudo, access_token, **kw)
|
||||
values.update(
|
||||
{
|
||||
"error": {},
|
||||
"error_message": [],
|
||||
}
|
||||
)
|
||||
if kw and request.httprequest.method == "POST":
|
||||
# the user has clicked in the Save button to save new data
|
||||
error, error_message = self._details_structure_form_validate(kw, structure_id)
|
||||
values.update({"error": error, "error_message": error_message})
|
||||
values.update(kw)
|
||||
if not error:
|
||||
# Update main profile
|
||||
new_values = self._get_page_saving_main_structure_values(kw)
|
||||
main_profile.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/structures")
|
||||
|
||||
# This is just the form page opening. We send all the data needed for the form fields
|
||||
can_edit_structure = partner_id in main_profile.can_edit_structure_profiles_ids
|
||||
values.update(self._get_page_opening_values())
|
||||
values.update(
|
||||
{
|
||||
"structure_id": structure_id, # Sent in order to retrieve it at submit time
|
||||
"public_profile": public_profile,
|
||||
"position_profile": position_profile,
|
||||
"can_edit_structure": can_edit_structure,
|
||||
"redirect": "/my/structure/" + str(structure_id) + "?success=True"
|
||||
}
|
||||
)
|
||||
return request.render("partner_profiles_portal.portal_structure", values)
|
Reference in New Issue
Block a user