ERP

How to Load the Images from URL in Odoo 16?

A business platform should incorporate media like voice, videos, or photographs for easy client communication. Odoo is aware of this and encourages the use of all media on its platform. Add images in Odoo, is what we are going to talk about in this article. In some situations, no images are saved as attachments, using media without linking to attachments is only possible with Odoo.

In the database, Odoo stores photos using binary fields. The ability to load or Import images from URL in Odoo is not possible, only the existing images can be uploaded to the system. In Odoo, an image field has the following fundamental definition:

img_customer will be created as a binary field in the "res. partner" model as a result. Due to the false value of the attachment attribute, the image will not be saved as an attachment. Any company may occasionally need to load a picture from an image URL thanks to Odoo because Odoo get image URL. That is not possible under the existing setup. But it is possible by doing the things listed below. We should develop a new model that stores the corresponding image in a binary field and accepts the image's URL as a character field.

A procedure that determines the image's binary value using the URL as input is required.

However, under these circumstances, writing a computing method for each model where we require this functionality is not a smart practice. To utilize the same method across all models, creating a new mixin class would be a wonderful idea. The same mixin class can define a method to compute images from URLs. By inheriting mixin, all methods can access this method.

The method get_image_fromurl() of this “ImageFromURLMixin” Mixin accepts the URL function as a parameter and returns a string with the appropriate format to be saved in the database.

We must create the model by inheriting from the model class and mixin class in order to utilize this method in our custom model. It is then necessary to rewrite the model definition as follows.

A computing method is defined to calculate the binary value of an image. The get image from URL () function is called by passing the URL stored in the image URL field.

Check it by creating a new record in odoo16. It will calculate and store the corresponding image in the form.

< Blogs>

More Blogs

Empowering Thoughts & Engaging Discussions
ERP

What is Knowledge Module in Odoo 16?

ERP

Why is Odoo an Ideal ERP for Food Manufacturers?

Odoo Partners

Why is Debugging Important in Odoo 15?