diff --git a/attribute_set_mass_edit/README.rst b/attribute_set_mass_edit/README.rst new file mode 100644 index 000000000..6b3fff36f --- /dev/null +++ b/attribute_set_mass_edit/README.rst @@ -0,0 +1,93 @@ +======================= +Attribute Set Mass Edit +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1a6a409e80c699985fb475121d0001613aa33ca9f38c6cce05cc1cf46f544242 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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%2Fodoo--pim-lightgray.png?logo=github + :target: https://github.com/OCA/odoo-pim/tree/18.0/attribute_set_mass_edit + :alt: OCA/odoo-pim +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/odoo-pim-18-0/odoo-pim-18-0-attribute_set_mass_edit + :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/odoo-pim&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows the user to authorize mass editing on an attribute. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +On the attribute, thick the check box 'Allow Mass Editing' and refresh +your browser. A Mass Editing profile is automatically created per +attribute group. + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Cédric PIGEON + +- Dhara Solanki + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +- [Trobz] (https://trobz.com/): + + - Khoi (Kien Kim) khoikk@trobz.com + +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/odoo-pim `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/attribute_set_mass_edit/__init__.py b/attribute_set_mass_edit/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/attribute_set_mass_edit/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/attribute_set_mass_edit/__manifest__.py b/attribute_set_mass_edit/__manifest__.py new file mode 100644 index 000000000..ec4826eb3 --- /dev/null +++ b/attribute_set_mass_edit/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Attribute Set Mass Edit", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/odoo-pim", + "depends": ["attribute_set", "server_action_mass_edit", "onchange_helper"], + "data": ["views/attribute_attribute.xml"], + "demo": [], + "installable": True, +} diff --git a/attribute_set_mass_edit/i18n/attribute_set_mass_edit.pot b/attribute_set_mass_edit/i18n/attribute_set_mass_edit.pot new file mode 100644 index 000000000..602123b5c --- /dev/null +++ b/attribute_set_mass_edit/i18n/attribute_set_mass_edit.pot @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * attribute_set_mass_edit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_attribute +msgid "Attribute" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_group +msgid "Attribute Group" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server +msgid "Server Action" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server_mass_edit_line +msgid "Server Actions Mass Edit Lines" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_mass_editing_wizard +msgid "Wizard for mass edition" +msgstr "" diff --git a/attribute_set_mass_edit/i18n/de.po b/attribute_set_mass_edit/i18n/de.po new file mode 100644 index 000000000..3dccec6eb --- /dev/null +++ b/attribute_set_mass_edit/i18n/de.po @@ -0,0 +1,43 @@ +msgid "" +msgstr "" +"Project-Id-Version: ametras-xsolutions\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: German\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-Crowdin-Project: ametras-xsolutions\n" +"X-Crowdin-Project-ID: 530964\n" +"X-Crowdin-Language: de\n" +"X-Crowdin-File: /[AmetrasIntelligence.oca-migrated] 16.0/attribute_set_mass_edit/i18n/attribute_set_mass_edit.pot\n" +"X-Crowdin-File-ID: 21360\n" +"Language: de_DE\n" +"PO-Revision-Date: 2024-09-25 12:08\n" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_attribute +msgid "Attribute" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_group +msgid "Attribute Group" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server +msgid "Server Action" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server_mass_edit_line +msgid "Server Actions Mass Edit Lines" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_mass_editing_wizard +msgid "Wizard for mass edition" +msgstr "" + diff --git a/attribute_set_mass_edit/i18n/es.po b/attribute_set_mass_edit/i18n/es.po new file mode 100644 index 000000000..f3b6af184 --- /dev/null +++ b/attribute_set_mass_edit/i18n/es.po @@ -0,0 +1,93 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * attribute_set_mass_edit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-17 23:57+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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.17\n" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_attribute__allow_mass_editing +msgid "Allow Mass Editing" +msgstr "Permitir la Edición Masiva" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_attribute +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_line__attribute_id +msgid "Attribute" +msgstr "Atributo" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_group +msgid "Attribute Group" +msgstr "Grupo de Atributo" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_attribute__display_name +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_group__display_name +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_ir_actions_server__display_name +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_line__display_name +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_wizard__display_name +msgid "Display Name" +msgstr "Nombre para Mostrar" + +#. module: attribute_set_mass_edit +#: code:addons/attribute_set_mass_edit/models/attribute_group.py:0 +#, python-format +msgid "Edit %s fields" +msgstr "Editar campos %s" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_attribute__id +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_group__id +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_ir_actions_server__id +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_line__id +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_wizard__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_attribute____last_update +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_group____last_update +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_ir_actions_server____last_update +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_line____last_update +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_mass_editing_wizard____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_group__mass_edit_action_ids +msgid "Mass Edit Action" +msgstr "Acción de Edición Masiva" + +#. module: attribute_set_mass_edit +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_ir_actions_server__mass_edit_attribute_group_id +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_ir_cron__mass_edit_attribute_group_id +msgid "Mass Edit Attribute Group" +msgstr "Grupo de Atributos de Edición Masiva" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_mass_editing_line +#: model:ir.model.fields,field_description:attribute_set_mass_edit.field_attribute_attribute__mass_editing_line_ids +msgid "Mass Editing Line" +msgstr "Línea de Edición Masiva" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server +msgid "Server Action" +msgstr "Acción de servidor" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_mass_editing_wizard +msgid "Wizard for mass edition" +msgstr "Wizard para edición masiva" diff --git a/attribute_set_mass_edit/i18n/fr.po b/attribute_set_mass_edit/i18n/fr.po new file mode 100644 index 000000000..eff4ea520 --- /dev/null +++ b/attribute_set_mass_edit/i18n/fr.po @@ -0,0 +1,43 @@ +msgid "" +msgstr "" +"Project-Id-Version: ametras-xsolutions\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: French\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-Crowdin-Project: ametras-xsolutions\n" +"X-Crowdin-Project-ID: 530964\n" +"X-Crowdin-Language: fr\n" +"X-Crowdin-File: /[AmetrasIntelligence.oca-migrated] 16.0/attribute_set_mass_edit/i18n/attribute_set_mass_edit.pot\n" +"X-Crowdin-File-ID: 21360\n" +"Language: fr_FR\n" +"PO-Revision-Date: 2024-09-25 12:08\n" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_attribute +msgid "Attribute" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_attribute_group +msgid "Attribute Group" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server +msgid "Server Action" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_ir_actions_server_mass_edit_line +msgid "Server Actions Mass Edit Lines" +msgstr "" + +#. module: attribute_set_mass_edit +#: model:ir.model,name:attribute_set_mass_edit.model_mass_editing_wizard +msgid "Wizard for mass edition" +msgstr "" + diff --git a/attribute_set_mass_edit/models/__init__.py b/attribute_set_mass_edit/models/__init__.py new file mode 100644 index 000000000..a049a8643 --- /dev/null +++ b/attribute_set_mass_edit/models/__init__.py @@ -0,0 +1,4 @@ +from . import ir_actions_server_mass_edit_line +from . import attribute_attribute +from . import ir_actions_server +from . import attribute_group diff --git a/attribute_set_mass_edit/models/attribute_attribute.py b/attribute_set_mass_edit/models/attribute_attribute.py new file mode 100644 index 000000000..c3b3e68a6 --- /dev/null +++ b/attribute_set_mass_edit/models/attribute_attribute.py @@ -0,0 +1,103 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import Command, api, fields, models + + +class AttributeAttribute(models.Model): + _inherit = "attribute.attribute" + + allow_mass_editing = fields.Boolean() + mass_editing_line_ids = fields.One2many( + comodel_name="ir.actions.server.mass.edit.line", inverse_name="attribute_id" + ) + + def _get_mass_editing_ids(self): + return self.mapped("mass_editing_line_ids").mapped("server_action_id") + + def _create_mass_editing(self): + """ + Create Mass Editing if not exists, use create multi + :return: + """ + actions_server_obj = self.env["ir.actions.server"] + attributes_without_mass = self.filtered(lambda a: not a.mass_editing_line_ids) + attribute_groups = self.env["attribute.group"].search( + [("id", "in", attributes_without_mass.mapped("attribute_group_id").ids)] + ) + mass_editings = actions_server_obj + for attribute_group in attribute_groups.filtered( + lambda g: not g.mass_edit_action_ids + ): + vals = attribute_group._prepare_create_mass_editing() + vals = actions_server_obj.play_onchanges(vals, vals.keys()) + mass_editings |= actions_server_obj.create(vals) + + for attribute in self: + for mass_edit in attribute_groups.mapped("mass_edit_action_ids").filtered( + lambda m, attribute=attribute: m.mass_edit_attribute_group_id + == attribute.attribute_group_id + ): + mass_edit.write( + { + "mass_edit_line_ids": [ + Command.create(attribute._prepare_mass_editing_line()) + ] + } + ) + mass_editings.create_action() + return True + + def _remove_attribute_from_mass_editing(self): + """ + If attribute field is in mass_editing, remove it + Then, if no fields are present in mass editing, remove the action + and the mass editing + :return: + """ + mass_editing_to_remove = self.env["ir.actions.server"].browse() + # fetch them before unlinking lines to find them easily + mass_edits = self._get_mass_editing_ids() + self.mapped("mass_editing_line_ids").unlink() + for mass_editing in mass_edits: + if not mass_editing.mass_edit_line_ids: + mass_editing_to_remove |= mass_editing + mass_editing_to_remove.unlink() + + def _prepare_mass_editing_line(self): + return { + "field_id": self.field_id.id, + "attribute_id": self.id, + } + + def _manage_mass_editings(self): + """ + Create mass editing if allowed and if not, remove existing ones + :return: + """ + allowed_attributes = self.filtered("allow_mass_editing") + allowed_attributes._create_mass_editing() + not_allowed_attributes = self - allowed_attributes + if not_allowed_attributes: + not_allowed_attributes._remove_attribute_from_mass_editing() + + def write(self, vals): + """ + Create Mass Editing for attributes that allow it + :param vals: + :return: + """ + res = super().write(vals) + self._manage_mass_editings() + return res + + def unlink(self): + self._remove_attribute_from_mass_editing() + return super().unlink() + + @api.model_create_multi + def create(self, vals_list): + attributes = super().create(vals_list) + for rec in attributes: + rec._manage_mass_editings() + return attributes diff --git a/attribute_set_mass_edit/models/attribute_group.py b/attribute_set_mass_edit/models/attribute_group.py new file mode 100644 index 000000000..02e158e82 --- /dev/null +++ b/attribute_set_mass_edit/models/attribute_group.py @@ -0,0 +1,39 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AttributeGroup(models.Model): + _inherit = "attribute.group" + + mass_edit_action_ids = fields.One2many( + "ir.actions.server", inverse_name="mass_edit_attribute_group_id" + ) + + def write(self, vals): + res = super().write(vals) + if "name" in vals.keys(): + mass_editings = self.env["ir.actions.server"].search( + [("mass_edit_attribute_group_id", "in", self.ids)] + ) + for group in self: + mass_editing = fields.first( + mass_editings.filtered( + lambda o, group=group: o.mass_edit_attribute_group_id == group + ) + ) + if mass_editing: + mass_editing.name = group._prepare_create_mass_editing()["name"] + # mass_editing.disable_mass_operation() + # mass_editing.enable_mass_operation() + return res + + def _prepare_create_mass_editing(self): + self.ensure_one() + return { + "mass_edit_attribute_group_id": self.id, + "model_id": self.model_id.id, + "name": self.env._("Edit %s fields", self.name), + "state": "mass_edit", + } diff --git a/attribute_set_mass_edit/models/ir_actions_server.py b/attribute_set_mass_edit/models/ir_actions_server.py new file mode 100644 index 000000000..43a025fda --- /dev/null +++ b/attribute_set_mass_edit/models/ir_actions_server.py @@ -0,0 +1,13 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MassEditing(models.Model): + _inherit = "ir.actions.server" + + mass_edit_attribute_group_id = fields.Many2one( + "attribute.group", + ondelete="cascade", + ) diff --git a/attribute_set_mass_edit/models/ir_actions_server_mass_edit_line.py b/attribute_set_mass_edit/models/ir_actions_server_mass_edit_line.py new file mode 100644 index 000000000..7213ecf4d --- /dev/null +++ b/attribute_set_mass_edit/models/ir_actions_server_mass_edit_line.py @@ -0,0 +1,14 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Pierrick Brun +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MassEditingLine(models.Model): + _inherit = "ir.actions.server.mass.edit.line" + + attribute_id = fields.Many2one( + "attribute.attribute", + ondelete="cascade", + ) diff --git a/attribute_set_mass_edit/pyproject.toml b/attribute_set_mass_edit/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/attribute_set_mass_edit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/attribute_set_mass_edit/readme/CONTRIBUTORS.md b/attribute_set_mass_edit/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..39e115212 --- /dev/null +++ b/attribute_set_mass_edit/readme/CONTRIBUTORS.md @@ -0,0 +1,10 @@ +- Cédric PIGEON \ + +- Dhara Solanki \ + +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + + > - Bhavesh Heliconia + +- [Trobz] (https://trobz.com/): + - Khoi (Kien Kim) diff --git a/attribute_set_mass_edit/readme/DESCRIPTION.md b/attribute_set_mass_edit/readme/DESCRIPTION.md new file mode 100644 index 000000000..5b369cbdb --- /dev/null +++ b/attribute_set_mass_edit/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows the user to authorize mass editing on an attribute. diff --git a/attribute_set_mass_edit/readme/USAGE.md b/attribute_set_mass_edit/readme/USAGE.md new file mode 100644 index 000000000..c74b12771 --- /dev/null +++ b/attribute_set_mass_edit/readme/USAGE.md @@ -0,0 +1,3 @@ +On the attribute, thick the check box 'Allow Mass Editing' and refresh +your browser. A Mass Editing profile is automatically created per +attribute group. diff --git a/attribute_set_mass_edit/static/description/icon.png b/attribute_set_mass_edit/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/attribute_set_mass_edit/static/description/icon.png differ diff --git a/attribute_set_mass_edit/static/description/index.html b/attribute_set_mass_edit/static/description/index.html new file mode 100644 index 000000000..84ffe20f5 --- /dev/null +++ b/attribute_set_mass_edit/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Attribute Set Mass Edit + + + +
+

Attribute Set Mass Edit

+ + +

Beta License: AGPL-3 OCA/odoo-pim Translate me on Weblate Try me on Runboat

+

This module allows the user to authorize mass editing on an attribute.

+

Table of contents

+ +
+

Usage

+

On the attribute, thick the check box ‘Allow Mass Editing’ and refresh +your browser. A Mass Editing profile is automatically created per +attribute group.

+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

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

+

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

+
+
+
+ + diff --git a/attribute_set_mass_edit/tests/__init__.py b/attribute_set_mass_edit/tests/__init__.py new file mode 100644 index 000000000..32c64f381 --- /dev/null +++ b/attribute_set_mass_edit/tests/__init__.py @@ -0,0 +1 @@ +from . import test_attribute_set_mass_edit diff --git a/attribute_set_mass_edit/tests/test_attribute_set_mass_edit.py b/attribute_set_mass_edit/tests/test_attribute_set_mass_edit.py new file mode 100644 index 000000000..86eaf2bd0 --- /dev/null +++ b/attribute_set_mass_edit/tests/test_attribute_set_mass_edit.py @@ -0,0 +1,99 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestAttributeSetMassEdit(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.model_id = cls.env.ref("base.model_res_partner").id + cls.group = cls.env["attribute.group"].create( + {"name": "My Group", "model_id": cls.model_id} + ) + cls.attr = cls.env["attribute.attribute"].create( + cls._prepare_attr_vals("x_test", "Attribute test 1") + ) + cls.attr2 = cls.env["attribute.attribute"].create( + cls._prepare_attr_vals("x_test2", "Attribute test 2") + ) + + @classmethod + def _prepare_attr_vals(cls, name, field_description): + return { + "nature": "custom", + "model_id": cls.model_id, + "attribute_type": "char", + "field_description": field_description, + "name": name, + "attribute_group_id": cls.group.id, + } + + def _get_mass_object(self): + action_server_obj = self.env["ir.actions.server"] + return action_server_obj.search( + [("mass_edit_attribute_group_id", "=", self.attr.attribute_group_id.id)] + ) + + def test_attr_mass_edit(self): + mass_object = self._get_mass_object() + self.assertFalse(mass_object) + self.attr.allow_mass_editing = True + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + self.assertEqual( + mass_object.name, f"Edit {self.attr.attribute_group_id.name} fields" + ) + self.assertIn( + self.attr.field_id.id, mass_object.mapped("mass_edit_line_ids.field_id").ids + ) + self.attr.allow_mass_editing = False + mass_object = self._get_mass_object() + self.assertFalse(mass_object) + + def test_attr_unlink(self): + mass_object = self._get_mass_object() + self.assertFalse(mass_object) + self.attr.allow_mass_editing = True + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + self.attr.unlink() + self.assertFalse(mass_object.exists()) + + def test_group_rename(self): + self.attr.allow_mass_editing = True + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + new_name = "New Group Name" + self.group.name = new_name + self.assertEqual(mass_object.name, f"Edit {new_name} fields") + + def test_group_unlink(self): + self.attr.allow_mass_editing = True + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + self.group.unlink() + self.assertFalse(mass_object.exists()) + + def test_several_attr_in_same_group(self): + self.attr.allow_mass_editing = True + self.attr2.allow_mass_editing = True + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + self.assertEqual( + mass_object.name, f"Edit {self.attr.attribute_group_id.name} fields" + ) + self.assertIn( + self.attr.field_id.id, mass_object.mapped("mass_edit_line_ids.field_id").ids + ) + self.assertIn( + self.attr2.field_id.id, + mass_object.mapped("mass_edit_line_ids.field_id").ids, + ) + self.attr.allow_mass_editing = False + mass_object = self._get_mass_object() + self.assertTrue(mass_object) + self.attr2.allow_mass_editing = False + mass_object = self._get_mass_object() + self.assertFalse(mass_object) diff --git a/attribute_set_mass_edit/views/attribute_attribute.xml b/attribute_set_mass_edit/views/attribute_attribute.xml new file mode 100644 index 000000000..78b4fd90b --- /dev/null +++ b/attribute_set_mass_edit/views/attribute_attribute.xml @@ -0,0 +1,15 @@ + + + + + attribute.attribute.form (in attribut_set_searchable) + attribute.attribute + + + + + + + + diff --git a/attribute_set_mass_edit/wizards/__init__.py b/attribute_set_mass_edit/wizards/__init__.py new file mode 100644 index 000000000..01affac4b --- /dev/null +++ b/attribute_set_mass_edit/wizards/__init__.py @@ -0,0 +1 @@ +from . import mass_editing_wizard diff --git a/attribute_set_mass_edit/wizards/mass_editing_wizard.py b/attribute_set_mass_edit/wizards/mass_editing_wizard.py new file mode 100644 index 000000000..2344fd3f8 --- /dev/null +++ b/attribute_set_mass_edit/wizards/mass_editing_wizard.py @@ -0,0 +1,25 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, models +from odoo.fields import first + + +class MassEditingWizard(models.TransientModel): + _inherit = "mass.editing.wizard" + + @api.model + def _get_field_options(self, field): + res = super()._get_field_options(field) + if field.ttype in ("many2one", "many2many"): + attributes = self.env["attribute.attribute"].search( + [("field_id", "=", field.id)] + ) + attribute = first( + attributes.filtered( + lambda a: a.attribute_type in ("select", "multiselect") + ) + ) + if attribute: + res.update({"domain": f"[('attribute_id', '=', {attribute.id})]"}) + + return res