Skip to content

Commit

Permalink
[REF] pms-api-rest: pms_api_rest_utils manage images from field to url
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin authored and DarioLodeiros committed Oct 9, 2023
1 parent 38743b7 commit 53fdeae
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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),
])
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
Expand Down
7 changes: 4 additions & 3 deletions pms_api_rest/services/pms_agency_service.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
7 changes: 4 additions & 3 deletions pms_api_rest/services/pms_folio_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)


Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
5 changes: 2 additions & 3 deletions pms_api_rest/services/pms_login_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
4 changes: 2 additions & 2 deletions pms_api_rest/services/pms_property_service.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pms_api_rest/services/pms_room_type_class_service.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions pms_api_rest/services/pms_sale_channel_service.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 53fdeae

Please sign in to comment.