Skip to content

Commit

Permalink
[17.0][MIG] base_multi_image: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
psugne committed Oct 9, 2024
1 parent a85061b commit 1ec17dc
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 204 deletions.
145 changes: 77 additions & 68 deletions base_multi_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ Multiple images base
: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/16.0/base_multi_image
:target: https://github.com/OCA/server-tools/tree/17.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-16-0/server-tools-16-0-base_multi_image
:target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-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=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.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.
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**

Expand All @@ -39,96 +39,104 @@ This module extends the functionality of any model to support multiple images
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.
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*.
- 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.
- 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"]

* You have to inherit model ``base_multi_image.owner`` to the model that needs
the gallery::
# 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_1920", store=False)

class MyOwner(models.Model):
_name = "my.model.name"
_inherit = ["my.model.name", "base_multi_image.owner"]
- Somewhere in the owner view, add:

# 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_1920", 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"/>

<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.post_init_hook_for_submodules
and ~.hooks.uninstall_hook_for_submodules, like the
``product_multi_image`` module does:

* 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.post_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 (
uninstall_hook_for_submodules,
)
except ImportError:
pass
try:
from odoo.addons.base_multi_image.hooks import (
uninstall_hook_for_submodules,
)
except ImportError:
pass


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")
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|

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: 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.
- *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:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_multi_image%0Aversion:%2017.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
Expand All @@ -138,28 +146,29 @@ Authors
* OpenFire

Contributors
~~~~~~~~~~~~

* Pedro M. Baeza <[email protected]>
* Rafael Blasco <[email protected]>
* Jairo Llopis <[email protected]>
* Sodexis <[email protected]>
* Dave Lasley <[email protected]>
* Shepilov Vladislav <[email protected]>
* `Greenice <https://www.greenice.com>`_:

* Fernando La Chica <[email protected]>
------------

- Pedro M. Baeza <[email protected]>
- Rafael Blasco <[email protected]>
- Jairo Llopis <[email protected]>
- Sodexis <[email protected]>
- Dave Lasley <[email protected]>
- Shepilov Vladislav <[email protected]>
- `Greenice <https://www.greenice.com>`__:
- Fernando La Chica <[email protected]>
- Ugne Sinkeviciene <[email protected]>

Other credits
~~~~~~~~~~~~~
-------------

Original implementation
-----------------------
This module is inspired in previous module *product_images* from OpenLabs
and Akretion.
~~~~~~~~~~~~~~~~~~~~~~~

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

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -171,6 +180,6 @@ 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/16.0/base_multi_image>`_ project on GitHub.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/base_multi_image>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Multiple images base",
"summary": "Allow multiple images for database objects",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Tecnativa, "
"Antiun Ingeniería, S.L., Sodexis, "
"LasLabs, OpenFire, "
Expand Down
17 changes: 6 additions & 11 deletions base_multi_image/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def post_init_hook_for_submodules(cr, model, field):
with cr.savepoint():
column_exists = table_has_column(cr, table, field)
if column_exists:
cr.execute(
"SELECT id FROM %(table)s WHERE %(field)s IS NOT NULL"
) # pylint: disable=sql-injection
cr.execute("SELECT id FROM %(table)s WHERE %(field)s IS NOT NULL") # pylint: disable=sql-injection
else:
cr.execute(
"""
Expand All @@ -52,7 +50,7 @@ def post_init_hook_for_submodules(cr, model, field):
{
"owner_id": record.id,
"owner_model": model,
"owner_ref_id": "%s,%s" % (model, record.id),
"owner_ref_id": f"{model},{record.id}",
"image_1920": record[field],
},
)
Expand Down Expand Up @@ -111,13 +109,10 @@ def save_directly_to_table(cr, Model, field, Field, main_images):
if field and not Field.attachment:
fields.append(field + " = " + "%(image)s")
query = """
UPDATE %(table)s
SET %(fields)s
WHERE id = %%(id)s
""" % {
"table": Model._table,
"fields": ", ".join(fields),
}
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:
Expand Down
6 changes: 3 additions & 3 deletions base_multi_image/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-01-06 02:24+0000\n"
"PO-Revision-Date: 2024-09-09 10:06+0000\n"
"PO-Revision-Date: 2024-09-11 09:06+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"Language: it\n"
Expand Down Expand Up @@ -150,12 +150,12 @@ msgstr "Ultima modifica il"
#. module: base_multi_image
#: model:ir.model.fields,field_description:base_multi_image.field_base_multi_image_image__write_uid
msgid "Last Updated by"
msgstr "Last Updated by"
msgstr "Ultimo aggiornamento di"

#. module: base_multi_image
#: model:ir.model.fields,field_description:base_multi_image.field_base_multi_image_image__write_date
msgid "Last Updated on"
msgstr "Last Updated on"
msgstr "Ultimo aggiornamento il"

#. module: base_multi_image
#: model:ir.model.fields,field_description:base_multi_image.field_base_multi_image_image__load_from
Expand Down
2 changes: 1 addition & 1 deletion base_multi_image/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _compute_owner_ref_id(self):
"""Get a reference field based on the split model and id fields."""
for s in self:
if s.owner_model:
s.owner_ref_id = "{0.owner_model},{0.owner_id}".format(s)
s.owner_ref_id = f"{s.owner_model},{s.owner_id}"

Check warning on line 72 in base_multi_image/models/image.py

View check run for this annotation

Codecov / codecov/patch

base_multi_image/models/image.py#L72

Added line #L72 was not covered by tests

@api.depends("owner_id", "owner_model")
def _compute_show_technical(self):
Expand Down
3 changes: 3 additions & 0 deletions base_multi_image/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
55 changes: 55 additions & 0 deletions base_multi_image/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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_1920", 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.post_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 (
uninstall_hook_for_submodules,
)
except ImportError:
pass


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](https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas)](https://runbot.odoo-community.org/runbot/149/10.0)
Loading

0 comments on commit 1ec17dc

Please sign in to comment.