From 7e6fd2111b742d6e737209c6745f7f59ecd45dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Wed, 8 Apr 2026 15:12:11 -0300 Subject: [PATCH] [FIX] res_partner_operating_unit: performance due to missing indexes --- res_partner_operating_unit/README.rst | 38 ++++++++++--------- res_partner_operating_unit/__init__.py | 1 - res_partner_operating_unit/__manifest__.py | 3 +- res_partner_operating_unit/hooks.py | 23 ----------- .../migrations/17.0.1.2.0/post-migrate.py | 20 ++++++++++ .../models/res_partner.py | 1 - .../static/description/index.html | 28 ++++++++------ 7 files changed, 59 insertions(+), 55 deletions(-) delete mode 100644 res_partner_operating_unit/hooks.py create mode 100644 res_partner_operating_unit/migrations/17.0.1.2.0/post-migrate.py diff --git a/res_partner_operating_unit/README.rst b/res_partner_operating_unit/README.rst index 64acca1b95..862b368712 100644 --- a/res_partner_operating_unit/README.rst +++ b/res_partner_operating_unit/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + =========================== Partner with Operating Unit =========================== @@ -13,7 +17,7 @@ Partner with Operating Unit .. |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-LGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github @@ -30,11 +34,11 @@ Partner with Operating Unit This module introduces the following features: -- Adds the Operating Unit (OU) to res partner. -- The user’s default Operating Unit (OU) is proposed at the time of - creating Partner. -- Security rules are defined to ensure that users can only see Partner - of that Operating Units in which they are allowed access to. +- Adds the Operating Unit (OU) to res partner. +- The user’s default Operating Unit (OU) is proposed at the time of + creating Partner. +- Security rules are defined to ensure that users can only see Partner + of that Operating Units in which they are allowed access to. **Table of contents** @@ -44,9 +48,9 @@ This module introduces the following features: Usage ===== -- Go to customer -- You only see the customer of your operating units -- Create an customer. It is assigned to your default operating unit. +- Go to customer +- You only see the customer of your operating units +- Create an customer. It is assigned to your default operating unit. Bug Tracker =========== @@ -71,18 +75,18 @@ Authors Contributors ------------ -- Edi Santoso -- Maxime Chambreuil -- Hiren Dangar -- Ammar Officewala -- Freni Patel +- Edi Santoso +- Maxime Chambreuil +- Hiren Dangar +- Ammar Officewala +- Freni Patel Other credits ------------- -- Niaga Solution -- Open Source Integrators -- Serpent Consulting Services Pvt. Ltd. +- Niaga Solution +- Open Source Integrators +- Serpent Consulting Services Pvt. Ltd. Maintainers ----------- diff --git a/res_partner_operating_unit/__init__.py b/res_partner_operating_unit/__init__.py index 6d58305f5d..0650744f6b 100644 --- a/res_partner_operating_unit/__init__.py +++ b/res_partner_operating_unit/__init__.py @@ -1,2 +1 @@ from . import models -from .hooks import pre_init_hook diff --git a/res_partner_operating_unit/__manifest__.py b/res_partner_operating_unit/__manifest__.py index 85692a1232..6bbd3f7246 100644 --- a/res_partner_operating_unit/__manifest__.py +++ b/res_partner_operating_unit/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Partner with Operating Unit", "summary": "Introduces Operating Unit fields in Partner", - "version": "17.0.1.1.0", + "version": "17.0.1.2.0", "author": "Edi Santoso, " "Niaga Solution, " "Serpent Consulting Services Pvt. Ltd., " @@ -15,5 +15,4 @@ "license": "LGPL-3", "data": ["security/res_partner_security.xml", "views/res_partner_view.xml"], "installable": True, - "pre_init_hook": "pre_init_hook", } diff --git a/res_partner_operating_unit/hooks.py b/res_partner_operating_unit/hooks.py deleted file mode 100644 index b4f0d6fe43..0000000000 --- a/res_partner_operating_unit/hooks.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (C) 2020 Open Source Integrators -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - - -def pre_init_hook(env): - # Add new table and columns to hold values - env.cr.execute( - """ - CREATE TABLE operating_unit_partner_rel ( - partner_id INTEGER NOT NULL - REFERENCES res_partner(id) ON DELETE CASCADE, - operating_unit_id INTEGER NOT NULL - REFERENCES operating_unit(id) ON DELETE CASCADE); - """ - ) - # Add the values - env.cr.execute( - """ - INSERT INTO operating_unit_partner_rel - (partner_id, operating_unit_id) - SELECT id, 1 FROM res_partner; - """ - ) diff --git a/res_partner_operating_unit/migrations/17.0.1.2.0/post-migrate.py b/res_partner_operating_unit/migrations/17.0.1.2.0/post-migrate.py new file mode 100644 index 0000000000..543a464874 --- /dev/null +++ b/res_partner_operating_unit/migrations/17.0.1.2.0/post-migrate.py @@ -0,0 +1,20 @@ +# Copyright 2026 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +def migrate(cr, version): + if not version: + return + # Add missing index in operating_unit_partner_rel + # Prior to this version, the pre_init_hook manually created the relation table, + # bypassing the ORM's automatic creation, and so causing the indexes to be missing. + # See: https://github.com/odoo/odoo/blob/7d146774c/odoo/fields.py#L4804-L4817 + # + # The pre_init_hook is now removed, but we still need to create the index manually. + cr.execute( + """ + CREATE INDEX IF NOT EXISTS + operating_unit_partner_rel_partner_id_operating_unit_id_idx + ON operating_unit_partner_rel (partner_id, operating_unit_id) + """ + ) diff --git a/res_partner_operating_unit/models/res_partner.py b/res_partner_operating_unit/models/res_partner.py index b63570a680..bc887643ce 100644 --- a/res_partner_operating_unit/models/res_partner.py +++ b/res_partner_operating_unit/models/res_partner.py @@ -19,6 +19,5 @@ def _default_operating_unit(self): "partner_id", "operating_unit_id", "Operating Units", - required=True, default=lambda self: self._default_operating_unit(), ) diff --git a/res_partner_operating_unit/static/description/index.html b/res_partner_operating_unit/static/description/index.html index 7ade1935d9..516b743824 100644 --- a/res_partner_operating_unit/static/description/index.html +++ b/res_partner_operating_unit/static/description/index.html @@ -3,7 +3,7 @@ -Partner with Operating Unit +README.rst -
-

Partner with Operating Unit

+
+ + +Odoo Community Association + +
+

Partner with Operating Unit

-

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

+

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

This module introduces the following features:

  • Adds the Operating Unit (OU) to res partner.
  • @@ -393,7 +398,7 @@

    Partner with Operating Unit

-

Usage

+

Usage

  • Go to customer
  • You only see the customer of your operating units
  • @@ -401,7 +406,7 @@

    Usage

-

Bug Tracker

+

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 @@ -409,9 +414,9 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Edi Santoso
  • Niaga Solution
  • @@ -419,7 +424,7 @@

    Authors

-

Contributors

+

Contributors

-

Other credits

+

Other credits

  • Niaga Solution
  • Open Source Integrators
  • @@ -437,7 +442,7 @@

    Other credits

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -450,5 +455,6 @@

Maintainers

+