From 062ff8ced6e855a601739243440ab0e1aab9a8a2 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 13 Nov 2024 09:37:48 +0100 Subject: [PATCH] [ADD] allow to download an image --- fs_product_multi_image/README.rst | 1 + .../models/fs_product_image.py | 16 ++++++++++++++++ fs_product_multi_image/readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 1 + .../views/fs_product_image.xml | 6 ++++++ 5 files changed, 25 insertions(+) diff --git a/fs_product_multi_image/README.rst b/fs_product_multi_image/README.rst index 0e243cc6e2..85793f8b63 100644 --- a/fs_product_multi_image/README.rst +++ b/fs_product_multi_image/README.rst @@ -94,6 +94,7 @@ Contributors * Laurent Mignon * Raphaël Reverdy +* Mathieu Delva * Denis Roussel * Quentin Groulard * `Camptocamp `_ diff --git a/fs_product_multi_image/models/fs_product_image.py b/fs_product_multi_image/models/fs_product_image.py index e5584be3a5..117a063825 100644 --- a/fs_product_multi_image/models/fs_product_image.py +++ b/fs_product_multi_image/models/fs_product_image.py @@ -35,6 +35,22 @@ class FsProductImage(models.Model): domain=[("apply_on", "=", "product")], index=True, ) + image_url = fields.Char(compute="_compute_image_url") + + @api.depends("image") + def _compute_image_url(self): + for record in self: + if record.image: + record.image_url = self._get_url() + else: + record.image_url = False + + def _get_url(self): + return f"/web/image/fs.product.image/{self.id}/image/{self.image}?download=true" + + def download_image_url(self): + base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url") + return f"{base_url}{self._get_url()}" @api.depends("product_tmpl_id.attribute_line_ids.value_ids") def _compute_available_attribute(self): diff --git a/fs_product_multi_image/readme/CONTRIBUTORS.rst b/fs_product_multi_image/readme/CONTRIBUTORS.rst index 33d0863bc0..0f99d680eb 100644 --- a/fs_product_multi_image/readme/CONTRIBUTORS.rst +++ b/fs_product_multi_image/readme/CONTRIBUTORS.rst @@ -1,5 +1,6 @@ * Laurent Mignon * Raphaël Reverdy +* Mathieu Delva * Denis Roussel * Quentin Groulard * `Camptocamp `_ diff --git a/fs_product_multi_image/static/description/index.html b/fs_product_multi_image/static/description/index.html index 092f4a0457..8eae5884a3 100644 --- a/fs_product_multi_image/static/description/index.html +++ b/fs_product_multi_image/static/description/index.html @@ -441,6 +441,7 @@

Contributors