Skip to content

Commit

Permalink
[ADD] allow to download an image
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudelva committed Nov 13, 2024
1 parent c59b523 commit 002fe9f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions fs_product_multi_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Contributors

* Laurent Mignon <[email protected]>
* Raphaël Reverdy <[email protected]>
* Mathieu Delva <[email protected]>
* Denis Roussel <[email protected]>
* Quentin Groulard <[email protected]>
* `Camptocamp <https://www.camptocamp.com>`_
Expand Down
5 changes: 5 additions & 0 deletions fs_product_multi_image/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions fs_product_multi_image/i18n/fs_product_multi_image.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions fs_product_multi_image/models/fs_product_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions fs_product_multi_image/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Laurent Mignon <[email protected]>
* Raphaël Reverdy <[email protected]>
* Mathieu Delva <[email protected]>
* Denis Roussel <[email protected]>
* Quentin Groulard <[email protected]>
* `Camptocamp <https://www.camptocamp.com>`_
Expand Down
1 change: 1 addition & 0 deletions fs_product_multi_image/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Raphaël Reverdy &lt;<a class="reference external" href="mailto:raphael.reverdy&#64;akretion.com">raphael.reverdy&#64;akretion.com</a>&gt;</li>
<li>Mathieu Delva &lt;<a class="reference external" href="mailto:mathieu.delva&#64;akretion.com">mathieu.delva&#64;akretion.com</a>&gt;</li>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li>Quentin Groulard &lt;<a class="reference external" href="mailto:quentin.groulard&#64;acsone.eu">quentin.groulard&#64;acsone.eu</a>&gt;</li>
<li><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a><ul>
Expand Down
6 changes: 6 additions & 0 deletions fs_product_multi_image/views/fs_product_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
domain="[('id', 'in', available_attribute_value_ids)]"
attrs="{'invisible': [('available_attribute_value_ids', '=', [])]}"
/>
<field
name="image_url"
text="Download image"
widget="url"
nolabel="1"
/>
</group>
</field>
</record>
Expand Down

0 comments on commit 002fe9f

Please sign in to comment.