diff --git a/pms_api_rest/services/manage_url_images.py b/pms_api_rest/pms_api_rest_utils.py similarity index 71% rename from pms_api_rest/services/manage_url_images.py rename to pms_api_rest/pms_api_rest_utils.py index 2032e9b3e7..201d93a170 100644 --- a/pms_api_rest/services/manage_url_images.py +++ b/pms_api_rest/pms_api_rest_utils.py @@ -1,8 +1,8 @@ -from odoo import http +from odoo.http import request -def url_image(context, model, record_id, field): - rt_image_attach = context.env['ir.attachment'].sudo().search([ +def url_image_pms_api_rest(model, record_id, field): + rt_image_attach = request.env['ir.attachment'].sudo().search([ ('res_model', '=', model), ('res_id', '=', record_id), ('res_field', '=', field), @@ -10,7 +10,7 @@ def url_image(context, model, record_id, field): if rt_image_attach and not rt_image_attach.access_token: rt_image_attach.generate_access_token() result = ( - http.request.env['ir.config_parameter'] + request.env['ir.config_parameter'] .sudo().get_param('web.base.url') + '/web/image/%s?access_token=%s' % ( rt_image_attach.id, rt_image_attach.access_token diff --git a/pms_api_rest/services/pms_agency_service.py b/pms_api_rest/services/pms_agency_service.py index 5866b623de..2fecc4709e 100644 --- a/pms_api_rest/services/pms_agency_service.py +++ b/pms_api_rest/services/pms_agency_service.py @@ -1,11 +1,12 @@ from odoo import _ -from odoo.addons.pms_api_rest.services.manage_url_images import url_image from odoo.exceptions import MissingError from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component +from ..pms_api_rest_utils import url_image_pms_api_rest + class PmsAgencyService(Component): _inherit = "base.rest.service" @@ -42,7 +43,7 @@ def get_agencies(self, agencies_search_param): PmsAgencyInfo( id=agency.id, name=agency.name, - imageUrl=url_image(self, 'res.partner', agency.id, 'image_128'), + imageUrl=url_image_pms_api_rest('res.partner', agency.id, 'image_128'), ) ) return result_agencies @@ -71,7 +72,7 @@ def get_agency(self, agency_id): return PmsAgencieInfo( id=agency.id, name=agency.name if agency.name else None, - imageUrl=url_image(self, 'res.partner', agency.id, 'image_128'), + imageUrl=url_image_pms_api_rest('res.partner', agency.id, 'image_128'), ) else: raise MissingError(_("Agency not found")) diff --git a/pms_api_rest/services/pms_folio_service.py b/pms_api_rest/services/pms_folio_service.py index 698d1a9515..b817930f9d 100644 --- a/pms_api_rest/services/pms_folio_service.py +++ b/pms_api_rest/services/pms_folio_service.py @@ -3,7 +3,6 @@ from datetime import datetime, timedelta from odoo import _, fields -from .manage_url_images import url_image from odoo.exceptions import MissingError, ValidationError from odoo.osv import expression from odoo.tools import get_lang @@ -12,6 +11,8 @@ from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component +from ..pms_api_rest_utils import url_image_pms_api_rest + _logger = logging.getLogger(__name__) @@ -1258,7 +1259,7 @@ def get_folio_reservation_messages(self, folio_id): ).decode("utf-8") if message.author_id.image_1024 else None, - authorImageUrl=url_image(self, 'res.partner', message.author_id.id, 'image_1024'), + authorImageUrl=url_image_pms_api_rest('res.partner', message.author_id.id, 'image_1024'), ) ) PmsFolioMessageInfo = self.env.datamodels["pms.folio.message.info"] @@ -1282,7 +1283,7 @@ def get_folio_reservation_messages(self, folio_id): ).decode("utf-8") if folio_message.author_id.image_1024 else None, - authorImageUrl=url_image(self, 'res.partner', folio_message.author_id.id, 'image_1024'), + authorImageUrl=url_image_pms_api_rest('res.partner', folio_message.author_id.id, 'image_1024'), ) ) PmsMessageInfo = self.env.datamodels["pms.message.info"] diff --git a/pms_api_rest/services/pms_login_service.py b/pms_api_rest/services/pms_login_service.py index f7cfb518c8..e6b7c0cfcb 100644 --- a/pms_api_rest/services/pms_login_service.py +++ b/pms_api_rest/services/pms_login_service.py @@ -9,8 +9,7 @@ from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component -from .manage_url_images import url_image - +from ..pms_api_rest_utils import url_image_pms_api_rest class PmsLoginService(Component): _inherit = "base.rest.service" @@ -81,7 +80,7 @@ def login(self, user): userImageBase64=user_record.partner_id.image_1024 if user_record.partner_id.image_1024 else None, - userImageUrl=url_image(self, 'res.partner', user_record.partner_id.id, 'image_1024'), + userImageUrl=url_image_pms_api_rest('res.partner', user_record.partner_id.id, 'image_1024'), isNewInterfaceUser=user_record.is_new_interface_app_user, availabilityRuleFields=avail_rule_names, ) diff --git a/pms_api_rest/services/pms_property_service.py b/pms_api_rest/services/pms_property_service.py index 38e7a61ec6..df9c52731f 100644 --- a/pms_api_rest/services/pms_property_service.py +++ b/pms_api_rest/services/pms_property_service.py @@ -1,7 +1,7 @@ from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component -from odoo.addons.pms_api_rest.services.manage_url_images import url_image +from ..pms_api_rest_utils import url_image_pms_api_rest class PmsPropertyService(Component): @@ -49,7 +49,7 @@ def get_properties(self): simpleInColor=prop.simple_in_color, simpleFutureColor=prop.simple_future_color, language=prop.lang, - hotelImageUrl=url_image(self, 'pms.property', prop.id, 'hotel_image_pms_api_rest'), + hotelImageUrl=url_image_pms_api_rest('pms.property', prop.id, 'hotel_image_pms_api_rest'), ) ) return result_properties diff --git a/pms_api_rest/services/pms_room_type_class_service.py b/pms_api_rest/services/pms_room_type_class_service.py index 87f3e3d66c..2d149623af 100644 --- a/pms_api_rest/services/pms_room_type_class_service.py +++ b/pms_api_rest/services/pms_room_type_class_service.py @@ -1,8 +1,7 @@ from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component -from .manage_url_images import url_image - +from ..pms_api_rest_utils import url_image_pms_api_rest class PmsRoomTypeClassService(Component): _inherit = "base.rest.service" @@ -52,7 +51,7 @@ def get_room_type_class(self, room_type_class_search_param): name=room.name, defaultCode=room.default_code if room.default_code else None, pmsPropertyIds=room.pms_property_ids.mapped("id"), - imageUrl=url_image(self, 'pms.room.type.class', room.id, 'icon_pms_api_rest'), + imageUrl=url_image_pms_api_rest('pms.room.type.class', room.id, 'icon_pms_api_rest'), ) ) return result_room_type_class diff --git a/pms_api_rest/services/pms_sale_channel_service.py b/pms_api_rest/services/pms_sale_channel_service.py index 1c84681572..70fb514ea5 100644 --- a/pms_api_rest/services/pms_sale_channel_service.py +++ b/pms_api_rest/services/pms_sale_channel_service.py @@ -1,11 +1,10 @@ from odoo import _ -from odoo.addons.pms_api_rest.services.manage_url_images import url_image from odoo.exceptions import MissingError from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component - +from ..pms_api_rest_utils import url_image_pms_api_rest class PmsSaleChannelService(Component): _inherit = "base.rest.service" @@ -63,7 +62,7 @@ def get_sale_channels(self, sale_channel_search_param): channelType=sale_channel.channel_type if sale_channel.channel_type else None, - iconUrl=url_image(self, 'pms.sale.channel', sale_channel.id, 'icon'), + iconUrl=url_image_pms_api_rest('pms.sale.channel', sale_channel.id, 'icon'), ) ) return result_sale_channels