Files
odoo_source/addons/web_unsplash/models/ir_qweb.py
T
fw-bot a561e4cb56 [FIX] web_unsplash: traceback on saving the product
before this commit:
when creating a product from frontend and editing the product and
delete image, it doesn't get any url thus generating the traceback.

after this commit: if url is not defined then return None from
ir.qweb.field.image field converter

task-2063293

closes odoo/odoo#40866

X-original-commit: 2efad751e66931fd25a41c1b7d46865bccbc774a
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-11-22 09:19:35 +00:00

29 lines
899 B
Python

from werkzeug import urls
from odoo import models, api
class Image(models.AbstractModel):
_inherit = 'ir.qweb.field.image'
@api.model
def from_html(self, model, field, element):
if element.find('.//img') is None:
return False
url = element.find('.//img').get('src')
url_object = urls.url_parse(url)
if url_object.path.startswith('/unsplash/'):
res_id = element.get('data-oe-id')
if res_id:
res_id = int(res_id)
res_model = model._name
attachment = self.env['ir.attachment'].search([
('res_model', '=', res_model),
('res_id', '=', res_id),
('url', '=', url_object.path),
], limit=1)
return attachment.datas
return super(Image, self).from_html(model, field, element)