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
19
pms_api_rest/pms_api_rest_utils.py
Normal file
19
pms_api_rest/pms_api_rest_utils.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
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 = (
|
||||
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
|
||||
) if rt_image_attach else False
|
||||
)
|
||||
return result if result else ''
|
||||
Reference in New Issue
Block a user