diff --git a/base_conditional_image/README.rst b/base_conditional_image/README.rst new file mode 100644 index 00000000000..79eff351d62 --- /dev/null +++ b/base_conditional_image/README.rst @@ -0,0 +1,141 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================== +Conditional Images +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:da372508d2b504d34f4de952097a319aa6dfcd961ae78934ea4e523bc47864ff + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_conditional_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_conditional_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 +conditional images (based on the record attributes) and to manage them +either globally or by company. + +The main goal behind this module is to avoid storing the same image +multiple times. For example, for every partner, there is a related image +(most of the time, it's the default one). With this module properly set +up, it will be stored only one time and you can change it whenever you +want for all partners. + +**WARNING**: this module cannot be used on the same objects using the +module base_multi_image. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +The sole purpose of this module is to add an abstract model to be +inherited. So, you will not notice any changes on install. + +To develop using this module, you have to inherit the abstract model +conditional.image.consumer.mixin to the model that needs the conditional +images: + +:: + + class ResPartner(models.Model): + _inherit = ['res.partner', 'conditional.image.consumer.mixin'] + _name = 'res.partner' + +Then, configure how the images will be selected for each record. + +Usage +===== + +Go to *Technical Settings > Settings > Images* to configure all the +images. You can define images for specific objects, depending on the +attributes and the company of the object. + +The selector should return a boolean expression. All fields of the +object are available to compute the result. + +The system will first try to match an image with a company set up, then +with the ones without a company. If your object does not have a +company_id field, this check will be ignored and only images without a +company will be used. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- `Camptocamp `__: + + - Patrick Tombez + - Denis Leemann + +- `Trobz `__: + + - Son Ho + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +Other credits +------------- + +The migration of this module from 12.0 to 14.0 was financially supported +by Camptocamp + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_conditional_image/__init__.py b/base_conditional_image/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/base_conditional_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_conditional_image/__manifest__.py b/base_conditional_image/__manifest__.py new file mode 100644 index 00000000000..259110babac --- /dev/null +++ b/base_conditional_image/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019-2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "Conditional Images", + "summary": "This module extends the functionality to support conditional images", + "version": "19.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Misc", + "depends": [ + "base", + ], + "website": "https://github.com/OCA/server-tools", + "data": [ + "views/image_view.xml", + "security/ir.model.access.csv", + ], + "installable": True, +} diff --git a/base_conditional_image/i18n/base_conditional_image.pot b/base_conditional_image/i18n/base_conditional_image.pot new file mode 100644 index 00000000000..7f2e2b58eb9 --- /dev/null +++ b/base_conditional_image/i18n/base_conditional_image.pot @@ -0,0 +1,128 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_conditional_image +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__company_id +msgid "Company" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__company_id +msgid "" +"Company related check. If inherited object does not have a `company_id` " +"field, it will be ignored. The check will first take the records with a " +"company then, if no match is found, the ones without a company." +msgstr "" + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Conditional Image" +msgstr "" + +#. module: base_conditional_image +#: model:ir.actions.act_window,name:base_conditional_image.conditional_image_action +#: model:ir.ui.menu,name:base_conditional_image.conditional_image_menu +msgid "Conditional Images" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_uid +msgid "Created by" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_date +msgid "Created on" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__display_name +msgid "Display Name" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__id +msgid "ID" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1920 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1920 +msgid "Image" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1024 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1024 +msgid "Image 1024" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_128 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_128 +msgid "Image 128" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_256 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_256 +msgid "Image 256" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_512 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_512 +msgid "Image 512" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_date +msgid "Last Updated on" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image_consumer_mixin +msgid "Mixin for conditional images consumers" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__model_name +msgid "Model Name" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__name +msgid "Name" +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__selector +msgid "" +"Python expression used as selector when multiple images are usedfor the same" +" object. The variable `object` refers to the actual record on which the " +"expression will be executed. An empty expression will always return `True`." +msgstr "" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__selector +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Selector" +msgstr "" diff --git a/base_conditional_image/i18n/es_AR.po b/base_conditional_image/i18n/es_AR.po new file mode 100644 index 00000000000..5687d3431ba --- /dev/null +++ b/base_conditional_image/i18n/es_AR.po @@ -0,0 +1,144 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_conditional_image +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-10-09 22:36+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__company_id +msgid "Company" +msgstr "Compañía" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__company_id +msgid "" +"Company related check. If inherited object does not have a `company_id` " +"field, it will be ignored. The check will first take the records with a " +"company then, if no match is found, the ones without a company." +msgstr "" +"Verificación de compañía relacionada. Si el objeto heredado no tiene un " +"campo `company_id`, se ignorará. La verificación tomará primero los " +"registros con una compañía y luego, si no se encuentra ninguna coincidencia, " +"los que no tengan una compañía." + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Conditional Image" +msgstr "Imagen Condicional" + +#. module: base_conditional_image +#: model:ir.actions.act_window,name:base_conditional_image.conditional_image_action +#: model:ir.ui.menu,name:base_conditional_image.conditional_image_menu +msgid "Conditional Images" +msgstr "Imágenes Condicionales" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_date +msgid "Created on" +msgstr "Creado en" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__id +msgid "ID" +msgstr "ID" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1920 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1920 +msgid "Image" +msgstr "Imagen" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1024 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1024 +msgid "Image 1024" +msgstr "Imagen 1024" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_128 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_128 +msgid "Image 128" +msgstr "Imagen 128" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_256 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_256 +msgid "Image 256" +msgstr "Imagen 256" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_512 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_512 +msgid "Image 512" +msgstr "Imagen 512" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_uid +msgid "Last Updated by" +msgstr "Última actualización realizada por" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image_consumer_mixin +msgid "Mixin for conditional images consumers" +msgstr "Mixin para consumidores de imágenes condicionales" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__model_name +msgid "Model Name" +msgstr "Nombre del Modelo" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__name +msgid "Name" +msgstr "Nombre" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__selector +msgid "" +"Python expression used as selector when multiple images are usedfor the same " +"object. The variable `object` refers to the actual record on which the " +"expression will be executed. An empty expression will always return `True`." +msgstr "" +"Expresión de Python utilizada como selector cuando se utilizan varias " +"imágenes para el mismo objeto. La variable `objet` se refiere al registro " +"real en el que se ejecutará la expresión. Una expresión vacía siempre " +"devolverá `True`." + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__selector +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Selector" +msgstr "Selector" diff --git a/base_conditional_image/i18n/it.po b/base_conditional_image/i18n/it.po new file mode 100644 index 00000000000..b5db7c3b6d0 --- /dev/null +++ b/base_conditional_image/i18n/it.po @@ -0,0 +1,144 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_conditional_image +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-10-24 09:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__company_id +msgid "Company" +msgstr "Azienda" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__company_id +msgid "" +"Company related check. If inherited object does not have a `company_id` " +"field, it will be ignored. The check will first take the records with a " +"company then, if no match is found, the ones without a company." +msgstr "" +"Controllo correlato all'azienda. Se l'oggetto ereditato non ha un campo " +"`company_id`, verrà ignorato. Il controllo prenderà prima i record con " +"un'azienda, poi, se non viene trovata alcuna corrispondenza, quelli senza " +"azienda." + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Conditional Image" +msgstr "Immagine condizionale" + +#. module: base_conditional_image +#: model:ir.actions.act_window,name:base_conditional_image.conditional_image_action +#: model:ir.ui.menu,name:base_conditional_image.conditional_image_menu +msgid "Conditional Images" +msgstr "Immagini condizionali" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_uid +msgid "Created by" +msgstr "Creato da" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__create_date +msgid "Created on" +msgstr "Creato il" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__id +msgid "ID" +msgstr "ID" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1920 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1920 +msgid "Image" +msgstr "Immagine" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_1024 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_1024 +msgid "Image 1024" +msgstr "Immagine 1024" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_128 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_128 +msgid "Image 128" +msgstr "Immagine 128" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_256 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_256 +msgid "Image 256" +msgstr "Immagine 256" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__image_512 +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image_consumer_mixin__image_512 +msgid "Image 512" +msgstr "Immagine 512" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_uid +msgid "Last Updated by" +msgstr "Ultimo aggiornamento di" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__write_date +msgid "Last Updated on" +msgstr "Ultimo aggiornamento il" + +#. module: base_conditional_image +#: model:ir.model,name:base_conditional_image.model_conditional_image_consumer_mixin +msgid "Mixin for conditional images consumers" +msgstr "Mixin per l'impiego delle immagini condizionale" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__model_name +msgid "Model Name" +msgstr "Nome modello" + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__name +msgid "Name" +msgstr "Nome" + +#. module: base_conditional_image +#: model:ir.model.fields,help:base_conditional_image.field_conditional_image__selector +msgid "" +"Python expression used as selector when multiple images are usedfor the same" +" object. The variable `object` refers to the actual record on which the " +"expression will be executed. An empty expression will always return `True`." +msgstr "" +"Espressione Python usata come selettore quando più immagini vengono usate " +"per lo stesso oggetto. La variabile `object` si riferisce al record " +"effettivo su cui verrà eseguita l'espressione. Un'espressione vuota " +"restituirà sempre `True`." + +#. module: base_conditional_image +#: model:ir.model.fields,field_description:base_conditional_image.field_conditional_image__selector +#: model_terms:ir.ui.view,arch_db:base_conditional_image.view_conditional_image_form +msgid "Selector" +msgstr "Selettore" diff --git a/base_conditional_image/models/__init__.py b/base_conditional_image/models/__init__.py new file mode 100644 index 00000000000..e3eb58ecae5 --- /dev/null +++ b/base_conditional_image/models/__init__.py @@ -0,0 +1,2 @@ +from . import conditional_image_consumer_mixin +from . import conditional_image diff --git a/base_conditional_image/models/conditional_image.py b/base_conditional_image/models/conditional_image.py new file mode 100644 index 00000000000..37ed3bb049e --- /dev/null +++ b/base_conditional_image/models/conditional_image.py @@ -0,0 +1,27 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ConditionalImage(models.Model): + _name = "conditional.image" + _description = "Conditional Image" + _inherit = ["image.mixin"] + + name = fields.Char(required=True) + model_name = fields.Char(required=True) + selector = fields.Text( + help="Python expression used as selector when multiple images are used" + "for the same object. The variable `object` refers " + "to the actual record on which the expression will be executed. " + "An empty expression will always return `True`.", + ) + company_id = fields.Many2one( + "res.company", + "Company", + help="Company related check. If inherited object does not have a " + "`company_id` field, it will be ignored. " + "The check will first take the records with a company then, " + "if no match is found, the ones without a company.", + ) diff --git a/base_conditional_image/models/conditional_image_consumer_mixin.py b/base_conditional_image/models/conditional_image_consumer_mixin.py new file mode 100644 index 00000000000..b07f7bf7fae --- /dev/null +++ b/base_conditional_image/models/conditional_image_consumer_mixin.py @@ -0,0 +1,67 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models +from odoo.tools.safe_eval import safe_eval + + +class ConditionalImageConsumerMixin(models.AbstractModel): + _name = "conditional.image.consumer.mixin" + _description = "Mixin for conditional images consumers" + _inherit = "image.mixin" + + image_1920 = fields.Image(compute="_compute_images", store=False, readonly=True) + image_1024 = fields.Image(compute="_compute_images", store=False, readonly=True) + image_512 = fields.Image(compute="_compute_images", store=False, readonly=True) + image_256 = fields.Image(compute="_compute_images", store=False, readonly=True) + image_128 = fields.Image(compute="_compute_images", store=False, readonly=True) + + def _conditional_image_evaluate_selector(self, conditional_image): + self.ensure_one() + if conditional_image.selector: + if ( + conditional_image.company_id == self.company_id + or self.company_id + and not conditional_image.company_id + ): + return bool( + safe_eval(conditional_image.selector or "True", {"object": self}) + ) + return False + + def _compute_images(self): + if "company_id" in self._fields: + search_clause = [("model_name", "=", self._name)] + else: + # If inherited object doesn't have a `company_id` field, + # remove the items with a company defined and the related checks + search_clause = [ + ("model_name", "=", self._name), + ("company_id", "=", False), + ] + + conditional_images = self.env["conditional.image"].search( + search_clause, order="company_id, selector" + ) + + for record in self: + images_found = conditional_images.filtered( + lambda record, img: record._conditional_image_evaluate_selector(img) + ) + values = { + "image_1920": False, + "image_1024": False, + "image_512": False, + "image_256": False, + "image_128": False, + } + if images_found: + image = images_found[0] + values = { + "image_1920": image.image_1920, + "image_1024": image.image_1024, + "image_512": image.image_512, + "image_256": image.image_256, + "image_128": image.image_128, + } + record.update(values) diff --git a/base_conditional_image/pyproject.toml b/base_conditional_image/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/base_conditional_image/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_conditional_image/readme/CONTRIBUTORS.md b/base_conditional_image/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..b83fffd9fda --- /dev/null +++ b/base_conditional_image/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- [Camptocamp](https://camptocamp.com/): + - Patrick Tombez \ + - Denis Leemann \ + +- [Trobz](https://trobz.com): + - Son Ho \ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/base_conditional_image/readme/CREDITS.md b/base_conditional_image/readme/CREDITS.md new file mode 100644 index 00000000000..6184200e1b7 --- /dev/null +++ b/base_conditional_image/readme/CREDITS.md @@ -0,0 +1,2 @@ +The migration of this module from 12.0 to 14.0 was financially supported +by Camptocamp diff --git a/base_conditional_image/readme/DESCRIPTION.md b/base_conditional_image/readme/DESCRIPTION.md new file mode 100644 index 00000000000..58e05b18746 --- /dev/null +++ b/base_conditional_image/readme/DESCRIPTION.md @@ -0,0 +1,12 @@ +This module extends the functionality of any model to support +conditional images (based on the record attributes) and to manage them +either globally or by company. + +The main goal behind this module is to avoid storing the same image +multiple times. For example, for every partner, there is a related image +(most of the time, it's the default one). With this module properly set +up, it will be stored only one time and you can change it whenever you +want for all partners. + +**WARNING**: this module cannot be used on the same objects using the +module base_multi_image. diff --git a/base_conditional_image/readme/INSTALL.md b/base_conditional_image/readme/INSTALL.md new file mode 100644 index 00000000000..d6697f45708 --- /dev/null +++ b/base_conditional_image/readme/INSTALL.md @@ -0,0 +1,12 @@ +The sole purpose of this module is to add an abstract model to be +inherited. So, you will not notice any changes on install. + +To develop using this module, you have to inherit the abstract model +conditional.image.consumer.mixin to the model that needs the conditional +images: + + class ResPartner(models.Model): + _inherit = ['res.partner', 'conditional.image.consumer.mixin'] + _name = 'res.partner' + +Then, configure how the images will be selected for each record. diff --git a/base_conditional_image/readme/USAGE.md b/base_conditional_image/readme/USAGE.md new file mode 100644 index 00000000000..4072dc1dde0 --- /dev/null +++ b/base_conditional_image/readme/USAGE.md @@ -0,0 +1,11 @@ +Go to *Technical Settings \> Settings \> Images* to configure all the +images. You can define images for specific objects, depending on the +attributes and the company of the object. + +The selector should return a boolean expression. All fields of the +object are available to compute the result. + +The system will first try to match an image with a company set up, then +with the ones without a company. If your object does not have a +company_id field, this check will be ignored and only images without a +company will be used. diff --git a/base_conditional_image/security/ir.model.access.csv b/base_conditional_image/security/ir.model.access.csv new file mode 100644 index 00000000000..0d9ca2bc728 --- /dev/null +++ b/base_conditional_image/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_conditional_image,Conditional Image,base_conditional_image.model_conditional_image,base.group_no_one,1,1,1,1 +access_conditional_image_users,Conditional Image Users,base_conditional_image.model_conditional_image,base.group_user,1,0,0,0 diff --git a/base_conditional_image/static/description/icon.png b/base_conditional_image/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/base_conditional_image/static/description/icon.png differ diff --git a/base_conditional_image/static/description/index.html b/base_conditional_image/static/description/index.html new file mode 100644 index 00000000000..20c38d63ade --- /dev/null +++ b/base_conditional_image/static/description/index.html @@ -0,0 +1,484 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Conditional Images

+ +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This module extends the functionality of any model to support +conditional images (based on the record attributes) and to manage them +either globally or by company.

+

The main goal behind this module is to avoid storing the same image +multiple times. For example, for every partner, there is a related image +(most of the time, it’s the default one). With this module properly set +up, it will be stored only one time and you can change it whenever you +want for all partners.

+

WARNING: this module cannot be used on the same objects using the +module base_multi_image.

+

Table of contents

+ +
+

Installation

+

The sole purpose of this module is to add an abstract model to be +inherited. So, you will not notice any changes on install.

+

To develop using this module, you have to inherit the abstract model +conditional.image.consumer.mixin to the model that needs the conditional +images:

+
+class ResPartner(models.Model):
+    _inherit = ['res.partner', 'conditional.image.consumer.mixin']
+    _name = 'res.partner'
+
+

Then, configure how the images will be selected for each record.

+
+
+

Usage

+

Go to Technical Settings > Settings > Images to configure all the +images. You can define images for specific objects, depending on the +attributes and the company of the object.

+

The selector should return a boolean expression. All fields of the +object are available to compute the result.

+

The system will first try to match an image with a company set up, then +with the ones without a company. If your object does not have a +company_id field, this check will be ignored and only images without a +company will be used.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 12.0 to 14.0 was financially supported +by Camptocamp

+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/base_conditional_image/views/image_view.xml b/base_conditional_image/views/image_view.xml new file mode 100644 index 00000000000..a5daabae26b --- /dev/null +++ b/base_conditional_image/views/image_view.xml @@ -0,0 +1,60 @@ + + + + conditional.image.tree + conditional.image + + + + + + + + + + + + conditional.image.form + conditional.image + +
+ + + + + + + + + + + + + +
+
+
+ + + Conditional Images + conditional.image + list,form + + + + Conditional Images + + + + +