Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
5cd33f2
Split model in abstract & concrete.
yajo Nov 6, 2015
f38a7a3
Extend model example.
yajo Mar 3, 2016
3073b4e
Tenames and typos.
yajo Mar 3, 2016
3cc86d3
No default value for storage.
yajo Mar 3, 2016
3511ee5
Do not require a name.
yajo Mar 3, 2016
8c499f2
Add sequence to images.
yajo Mar 3, 2016
d97c72e
Reduce methods.
yajo Mar 3, 2016
6393688
Cache images' URL.
yajo Mar 3, 2016
557722a
Remove wrong copyright.
yajo Mar 3, 2016
be9d4fe
Add known issues section.
yajo Mar 9, 2016
0bcc9f7
Fix bug that made previous images to disappear.
yajo Mar 11, 2016
259b313
[MIG][9.0] base_multi_image
atchuthan Mar 30, 2016
b50b16b
[FIX] base_multi_image - New storage backend 'Filestore' to link an e…
sebalix Jun 29, 2016
e73468b
[IMP] base_multi_image - Select only images as attachments
sebalix Jun 29, 2016
95ef0fe
[FIX] base_multi_image - Clean up + updated comments
sebalix Jun 30, 2016
277cb22
[FIX] base_multi_image - Make validation error messages translatable
sebalix Jun 30, 2016
1b4d60b
[FIX] base_multi_image - Fix method name
sebalix Jun 30, 2016
ddc4fc5
Use v9 ormcache.
yajo Jul 20, 2016
c18ffed
Add a reference field to get to the owner with 1 click.
yajo Jul 20, 2016
85b8c99
Add uninstall hook to avoid garbage images hanging around after submo…
yajo Jul 20, 2016
81f5ca7
Raise version.
yajo Jul 20, 2016
b9e71bc
Add ondelete attribute, required for Many2one fields in v9.
yajo Jul 21, 2016
a942746
[FIX] base_multi_image: Correct README instructions
pedrobaeza Jul 29, 2016
9d9069d
[FIX] remove en.po that was erroneously created by transbot
sbidoul Aug 15, 2016
74f1a0b
[FIX] adapt to changes in binary attachment branch
hbrunn Sep 15, 2016
baa2cd7
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
7b5c29e
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
20a2d78
base_multi_image: Fix hook example * Add uninstall hook import to Rea…
lasley Nov 4, 2016
94d8189
[MIG] base_multi_image: Upgrade to v10
lasley Nov 10, 2016
53f7194
[FIX] base_multi_image: Adhere to image delete bypass
lasley Nov 30, 2016
7981e9d
[FIX] base_multi_image: Use env in uninstall_hook (#677)
lasley Jan 16, 2017
b468da8
[10.0][FIX] base_multi_image: Uninstall hook (#709)
lasley Jan 23, 2017
814273b
[10.0] [IMP] base_multi_image: improve uninstall hook (#1286)
FFernandez-PlanetaTIC Jun 22, 2018
b91cb12
[MIG] base_multi_image: Migration to 12.0
Nov 8, 2019
c3f57f9
[FIX]base_multi_image: Fix image url in locales with thousand separator.
MPoch-PlanetaTIC Jun 11, 2020
9f9176b
[MIG][13.0]base_multi_image: Migrated to v13
javierjcf Sep 9, 2020
d91e63c
[IMP] base_multi_image: black, isort, prettier
hailangvn May 16, 2021
bff51c4
[MIG] base_multi_image: Migration to 14.0
hailangvn May 21, 2021
9abf6ac
Translated using Weblate (Spanish (Argentina))
ibuioli Mar 19, 2022
cca124b
[15.0][MIG] base_multi_image
flachica May 6, 2022
2de9f68
Translated using Weblate (Italian)
mymage Mar 23, 2023
c6e007b
Translated using Weblate (Slovenian)
sysadminmatmoz Mar 31, 2023
61be633
Translated using Weblate (Italian)
mymage Apr 10, 2023
f64ec32
Translated using Weblate (Italian)
mymage Apr 17, 2023
9a372f0
Translated using Weblate (Spanish)
Ivorra78 Oct 10, 2023
4ba6c4c
Translated using Weblate (Spanish (Argentina))
ibuioli Oct 27, 2023
4e62af0
Translated using Weblate (Italian)
mymage Dec 29, 2023
325a567
[MIG] base_multi_image: Migration to 16.0
IJOL Aug 9, 2024
a85b356
[UPD] base_multi_image removed unused params, revamped post_init_hook…
IJOL Aug 9, 2024
c4af3c3
Translated using Weblate (Italian)
mymage Sep 9, 2024
7dad91c
Translated using Weblate (Italian)
mymage Sep 11, 2024
60f2fd3
[FIX] base_multi_image: Attribute Error
GabbasovDinar Jan 17, 2025
3e0c55d
[IMP] base_multi_image: pre-commit auto fixes
BhaveshHeliconia Feb 24, 2025
8006590
[MIG] base_multi_image: Migration to 18.0
BhaveshHeliconia Feb 24, 2025
9be2df6
Translated using Weblate (Italian)
mymage Mar 10, 2026
3438a97
Translated using Weblate (Dutch)
bosd May 14, 2026
7280221
[IMP] base_multi_image: pre-commit auto fixes
dnplkndll May 30, 2026
bd47002
[MIG] base_multi_image: Migration to 19.0
dnplkndll May 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions base_multi_image/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

====================
Multiple images base
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:afa2c09044322e805124250387d1f8721538f65cb2667e33cdc3a939df257ae2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/19.0/base_multi_image
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_multi_image
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of any model to support multiple
images (a gallery) attached to it and allow you to manage them.

**Table of contents**

.. contents::
:local:

Installation
============

This module adds abstract models to work on. Its sole purpose is to
serve as base for other modules that implement galleries, so if you
install this one manually you will notice no change. You should install
any other module based on this one and this will get installed
automatically.

Configuration
=============

To manage all stored images, you need to:

- Go to *Settings > Technical > Multi images*.

... but you probably prefer to manage them from the forms supplied by
submodules that inherit this behavior.

Development
-----------

To develop a module based on this one:

- See module ``product_multi_image`` as an example.

- You have to inherit model ``base_multi_image.owner`` to the model that
needs the gallery:

::

class MyOwner(models.Model):
_name = "my.model.name"
_inherit = ["my.model.name", "base_multi_image.owner"]

# If you need this, you will need ``pre_init_hook_for_submodules`` and
``uninstall_hook_for_submodules`` as detailed below.
old_image_field = fields.Binary(related="image_main", store=False)

- Somewhere in the owner view, add:

::

<field
name="image_ids"
nolabel="1"
context="{
'default_owner_model': 'my.model.name',
'default_owner_id': id,
}"
mode="kanban"/>

- If the model you are extending already had an image field, and you
want to trick Odoo to make those images to multi-image mode, you will
need to make use of the provided ~.hooks.pre_init_hook_for_submodules
and ~.hooks.uninstall_hook_for_submodules, like the
``product_multi_image`` module does:

::

try:
from odoo.addons.base_multi_image.hooks import (
pre_init_hook_for_submodules,
uninstall_hook_for_submodules,
)
except ImportError:
pass


def pre_init_hook(cr):
"""Transform single into multi images."""
pre_init_hook_for_submodules(cr, "product.template", "image")
pre_init_hook_for_submodules(cr, "product.product", "image_variant")


def uninstall_hook(cr, registry):
"""Remove multi images for models that no longer use them."""
uninstall_hook_for_submodules(cr, registry, "product.template")
uninstall_hook_for_submodules(cr, registry, "product.product")

|Try me on Runbot|

.. |Try me on Runbot| image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:target: https://runbot.odoo-community.org/runbot/149/10.0

Known issues / Roadmap
======================

- *OS file* storage mode for images is meant to provide a path where
Odoo has read access and the image is already found, **not for making
the module store images there**. It would be nice to add that feature
though.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_multi_image%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Tecnativa
* Antiun Ingeniería
* S.L.
* Sodexis
* LasLabs
* Omal Bastin (O4ODOO)

Contributors
------------

- Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
- Rafael Blasco <rafabn@antiun.com>
- Jairo Llopis <yajo.sk8@gmail.com>
- Sodexis <dev@sodexis.com>
- Dave Lasley <dave@laslabs.com>
- Shepilov Vladislav <shepilov.v@protonmail.com>
- `Greenice <https://www.greenice.com>`__:

- Fernando La Chica <fernandolachica@gmail.com>

- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

Other credits
-------------

Original implementation
~~~~~~~~~~~~~~~~~~~~~~~

This module is inspired in previous module *product_images* from
OpenLabs and Akretion.

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/base_multi_image>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 6 additions & 0 deletions base_multi_image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
30 changes: 30 additions & 0 deletions base_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis
# © 2016 Sodexis
# © 2024 Omal bastin <omalbastin@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Multiple images base",
"summary": "Allow multiple images for database objects",
"version": "19.0.1.0.0",
"author": "Tecnativa, "
"Antiun Ingeniería, S.L., Sodexis, "
"LasLabs, "
"Omal Bastin (O4ODOO), "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-tools",
"category": "Tools",
"depends": ["base"],
"installable": True,
"data": [
"security/ir.model.access.csv",
"views/image_view.xml",
],
"images": [
"images/form.png",
"images/kanban.png",
],
}
127 changes: 127 additions & 0 deletions base_multi_image/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

_logger = logging.getLogger(__name__)


def pre_init_hook_for_submodules(env, model, field):
"""Moves images from single to multi mode.

Feel free to use this as a ``pre_init_hook`` for submodules.

:param str model:
Model name, like ``product.template``.

:param str field:
Binary field that had the images in that :param:`model`, like
``image``.
"""
cr = env.cr
with cr.savepoint():
table = env[model]._table
column_exists = table_has_column(cr, table, field)
# fields.Binary(), extract the binary content directly from the table
if column_exists:
extract_query = f"""
SELECT id, '{model}', '{model},' || id, 'db', {field}
FROM {table}
WHERE {field} IS NOT NULL
"""
image_field = "file_db_store"
# fields.Binary(attachment=True), get the ir_attachment record ID
else:
extract_query = f"""
SELECT
res_id,
res_model,
CONCAT_WS(',', res_model, res_id),
'attachment',
id
FROM ir_attachment
WHERE res_field='{field}' AND res_model='{model}'
"""
image_field = "attachment_id"
cr.execute( # pylint: disable=sql-injection
f"""
INSERT INTO base_multi_image_image (
owner_id,
owner_model,
owner_ref_id,
storage,
{image_field}
)
{extract_query}
"""
)


def uninstall_hook_for_submodules(env, model, field=None):
"""Moves images from multi to single mode and remove multi-images for a
given model.

:param str model:
Model technical name, like "res.partner". All multi-images for that
model will be deleted

:param str field:
Binary field that had the images in that :param:`model`, like
``image``.

"""
cr = env.cr
with cr.savepoint():
Image = env["base_multi_image.image"]
images = Image.search([("owner_model", "=", model)], order="sequence, id")
if images and field:
main_images = {}
for image in images:
if image.owner_id not in main_images:
main_images[image.owner_id] = image
main_images = main_images.values()
Model = env[model]
Field = Model._fields[field]

# fields.Binary(), save the binary content directly to the table
if not Field.attachment:
save_directly_to_table(
cr,
Model,
field,
Field,
main_images,
)
# fields.Binary(attachment=True), save the ir_attachment record ID
if Field.attachment:
for main_image in main_images:
owner = Model.browse(main_image.owner_id)
Field.write(owner, main_image.image_1920)
images.unlink()


def save_directly_to_table(cr, Model, field, Field, main_images):
fields = []
if field and not Field.attachment:
fields.append(field + " = " + "%(image)s")

query = """
UPDATE {table}
SET {fields}
WHERE id = %%(id)s
""".format(table=Model._table, fields=", ".join(fields))
for main_image in main_images:
params = {"id": main_image.owner_id}
if field and not Field.attachment:
params["image"] = main_image.image_1920
cr.execute(query, params) # pylint: disable=sql-injection


def table_has_column(cr, table, field):
query = """
SELECT %(field)s
FROM information_schema.columns
WHERE table_name=%(table)s and column_name=%(field)s;
"""
cr.execute(query, {"table": table, "field": field})
return bool(cr.fetchall())
Loading
Loading