Go on the website, create a new product from there Click on the image to change it, select an unsplash image Save your product. Beforer this commit, the image wasn't saved because the qweb field image did not know what to do with /unsplash/ urls After this commit, the image is saved on the product (or any object...) OPW 1936191 closes odoo/odoo#31328
27 lines
828 B
Python
27 lines
828 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):
|
|
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)
|