mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF] pms-api-rest: pms_api_rest_utils manage images from field to url
This commit is contained in:
committed by
Darío Lodeiros
parent
4ec68398e6
commit
250fd01d0a
@@ -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
|
||||
@@ -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 @@ class PmsAgencyService(Component):
|
||||
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 @@ class PmsAgencyService(Component):
|
||||
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"))
|
||||
|
||||
@@ -3,7 +3,6 @@ import logging
|
||||
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 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
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -1258,7 +1259,7 @@ class PmsFolioService(Component):
|
||||
).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 @@ class PmsFolioService(Component):
|
||||
).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"]
|
||||
|
||||
@@ -9,8 +9,7 @@ from odoo.exceptions import AccessDenied
|
||||
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 @@ class PmsLoginService(Component):
|
||||
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,
|
||||
)
|
||||
|
||||
@@ -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 @@ class PmsPropertyService(Component):
|
||||
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
|
||||
|
||||
@@ -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 @@ class PmsRoomTypeClassService(Component):
|
||||
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
|
||||
|
||||
@@ -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 @@ class PmsSaleChannelService(Component):
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user