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/i18n/fr.po b/fs_product_multi_image/i18n/fr.po index 47c6c3ab93..b4f3f69b41 100644 --- a/fs_product_multi_image/i18n/fr.po +++ b/fs_product_multi_image/i18n/fr.po @@ -54,6 +54,11 @@ msgstr "Créé le" msgid "Display Name" msgstr "Nom Affiché" +#. module: fs_product_multi_image +#: model_terms:ir.ui.view,arch_db:fs_product_multi_image.fs_product_image_form_view +msgid "Download image" +msgstr "" + #. module: fs_product_multi_image #: model:ir.model.fields,field_description:fs_product_multi_image.field_product_product__image_medium #: model:ir.model.fields,field_description:fs_product_multi_image.field_product_template__image_medium diff --git a/fs_product_multi_image/i18n/fs_product_multi_image.pot b/fs_product_multi_image/i18n/fs_product_multi_image.pot index 75be90867e..9ae34a1ea0 100644 --- a/fs_product_multi_image/i18n/fs_product_multi_image.pot +++ b/fs_product_multi_image/i18n/fs_product_multi_image.pot @@ -51,6 +51,11 @@ msgstr "" msgid "Display Name" msgstr "" +#. module: fs_product_multi_image +#: model_terms:ir.ui.view,arch_db:fs_product_multi_image.fs_product_image_form_view +msgid "Download image" +msgstr "" + #. module: fs_product_multi_image #: model:ir.model.fields,field_description:fs_product_multi_image.field_product_product__image_medium #: model:ir.model.fields,field_description:fs_product_multi_image.field_product_template__image_medium diff --git a/fs_product_multi_image/models/fs_product_image.py b/fs_product_multi_image/models/fs_product_image.py index e5584be3a5..de3cc1e148 100644 --- a/fs_product_multi_image/models/fs_product_image.py +++ b/fs_product_multi_image/models/fs_product_image.py @@ -35,6 +35,26 @@ 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: + record.image_url = False + if record.image: + record.image_url = self._get_url() + + def _get_url(self): + product_id = False + if "params" in self.env.context: + id = self.env.context["params"]["id"] + product_id = self.env["product.product"].browse(id) + name = product_id.barcode if product_id else self.product_tmpl_id.name + return f"/web/image/fs.product.image/{self.id}/image?download=true&filename={name}.jpg" + + 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