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 7d306cd
Show file tree
Hide file tree
Showing 5 changed files with 25 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
16 changes: 16 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,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:
record.image_url = False
if record.image:
record.image_url = self._get_url()

def _get_url(self):
name = 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 7d306cd

Please sign in to comment.