[FIX] partner_profiles_portal: fix portal boolean fields handling
This commit is contained in:
committed by
Stéphan Sainléger
parent
29af98aac3
commit
072cdf8978
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "partner_profiles_portal",
|
"name": "partner_profiles_portal",
|
||||||
"version": "12.0.2.4.0",
|
"version": "12.0.2.4.1",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://elabore.coop",
|
"website": "https://elabore.coop",
|
||||||
"maintainer": "Stéphan Sainléger",
|
"maintainer": "Stéphan Sainléger",
|
||||||
|
@@ -21,13 +21,38 @@ class CustomerPortalMyProfile(CustomerPortal):
|
|||||||
def _get_special_fields(self):
|
def _get_special_fields(self):
|
||||||
return ["main_logo"]
|
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=""):
|
def _transform_in_partner_fields(self, kw, profile_fields, prefix=""):
|
||||||
'''Transforms kw's values in res_partner fields and values'''
|
'''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}
|
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):
|
def _retrieve_main_values(self, data):
|
||||||
main_fields = self._get_mandatory_main_fields() + self._get_optional_main_fields()
|
main_fields = self._get_mandatory_main_fields() + self._get_optional_main_fields()
|
||||||
values = self._transform_in_partner_fields(data, main_fields, "main_")
|
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:
|
if 'main_logo' in data:
|
||||||
image = data.get('main_logo')
|
image = data.get('main_logo')
|
||||||
if image:
|
if image:
|
||||||
@@ -41,6 +66,8 @@ class CustomerPortalMyProfile(CustomerPortal):
|
|||||||
def _retrieve_public_values(self, data):
|
def _retrieve_public_values(self, data):
|
||||||
public_fields = self._get_mandatory_public_fields() + self._get_optional_public_fields()
|
public_fields = self._get_mandatory_public_fields() + self._get_optional_public_fields()
|
||||||
values = self._transform_in_partner_fields(data, public_fields, "public_")
|
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
|
return values
|
||||||
|
|
||||||
def _get_page_opening_values(self):
|
def _get_page_opening_values(self):
|
||||||
|
@@ -59,6 +59,13 @@ class CustomerPortalStructureProfile(CustomerPortal):
|
|||||||
]
|
]
|
||||||
return fields
|
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):
|
def _get_public_profile_fields(self):
|
||||||
'''Provides all the fields that must fill the structure's public profile.
|
'''Provides all the fields that must fill the structure's public profile.
|
||||||
All of them MUST start with "public_".'''
|
All of them MUST start with "public_".'''
|
||||||
@@ -75,6 +82,13 @@ class CustomerPortalStructureProfile(CustomerPortal):
|
|||||||
]
|
]
|
||||||
return fields
|
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):
|
def _get_position_profile_fields(self):
|
||||||
'''Provides all the fields that must fill the structure's position profile of the user.
|
'''Provides all the fields that must fill the structure's position profile of the user.
|
||||||
All of them MUST start with "position_".'''
|
All of them MUST start with "position_".'''
|
||||||
@@ -85,13 +99,31 @@ class CustomerPortalStructureProfile(CustomerPortal):
|
|||||||
]
|
]
|
||||||
return fields
|
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=""):
|
def _transform_in_res_partner_fields(self, kw, profile_fields, prefix=""):
|
||||||
'''Transforms kw's values in res_partner fields and values'''
|
'''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}
|
return {key[len(prefix):]: kw[key] for key in profile_fields if key in kw}
|
||||||
|
|
||||||
def _get_page_saving_main_values(self, 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()
|
profile_fields = self._get_main_profile_fields()
|
||||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "main_")
|
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:
|
if 'logo' in kw:
|
||||||
image = kw.get('logo')
|
image = kw.get('logo')
|
||||||
if image:
|
if image:
|
||||||
@@ -102,14 +134,18 @@ class CustomerPortalStructureProfile(CustomerPortal):
|
|||||||
})
|
})
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def _get_page_saving_public_values(self, kw):
|
def _get_page_saving_public_structure_values(self, kw):
|
||||||
profile_fields = self._get_public_profile_fields()
|
profile_fields = self._get_public_profile_fields()
|
||||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "public_")
|
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
|
return values
|
||||||
|
|
||||||
def _get_page_saving_position_values(self, kw):
|
def _get_page_saving_position_structure_values(self, kw):
|
||||||
profile_fields = self._get_position_profile_fields()
|
profile_fields = self._get_position_profile_fields()
|
||||||
values = self._transform_in_res_partner_fields(kw, profile_fields, "position_")
|
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
|
return values
|
||||||
|
|
||||||
def _get_page_opening_values(self):
|
def _get_page_opening_values(self):
|
||||||
@@ -170,13 +206,13 @@ class CustomerPortalStructureProfile(CustomerPortal):
|
|||||||
values.update(kw)
|
values.update(kw)
|
||||||
if not error:
|
if not error:
|
||||||
# Update main profile
|
# Update main profile
|
||||||
new_values = self._get_page_saving_main_values(kw)
|
new_values = self._get_page_saving_main_structure_values(kw)
|
||||||
main_profile.sudo().write(new_values)
|
main_profile.sudo().write(new_values)
|
||||||
# Update public profile
|
# Update public profile
|
||||||
new_values = self._get_page_saving_public_values(kw)
|
new_values = self._get_page_saving_public_structure_values(kw)
|
||||||
public_profile.sudo().write(new_values)
|
public_profile.sudo().write(new_values)
|
||||||
# Update position profile
|
# Update position profile
|
||||||
new_values = self._get_page_saving_position_values(kw)
|
new_values = self._get_page_saving_position_structure_values(kw)
|
||||||
position_profile.sudo().write(new_values)
|
position_profile.sudo().write(new_values)
|
||||||
# End of updates
|
# End of updates
|
||||||
if redirect:
|
if redirect:
|
||||||
|
Reference in New Issue
Block a user