Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][mig] default_multi_user: Migration to 16.0 #619

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bfa7f25
[11.0][ADD] default_multi_user
LoisRForgeFlow Jul 16, 2020
d541b0c
[UPD] Update default_multi_user.pot
oca-travis Jul 21, 2020
fcd2845
[12.0][MIG] default_multi_user
LoisRForgeFlow Jul 21, 2020
a0ad4cb
[UPD] Update default_multi_user.pot
oca-travis Jul 22, 2020
0a76c4e
[IMP] default_multi_user: black, isort, prettier
LoisRForgeFlow Jul 22, 2020
f31273b
[13.0][MIG] default_multi_user
LoisRForgeFlow Jul 22, 2020
2700c99
[UPD] Update default_multi_user.pot
oca-travis Sep 23, 2020
bf48746
[UPD] README.rst
OCA-git-bot Sep 23, 2020
d9a2375
[13.0][FIX] default_multi_user: multi company issue
LoisRForgeFlow Oct 23, 2020
cad2f4f
default_multi_user 13.0.1.0.1
OCA-git-bot Oct 27, 2020
30a968b
[IMP] default_multi_user: black, isort, prettier
schhatbar-initos Mar 1, 2021
099856e
[14.0][MIG]default_multi_user
schhatbar-initos Mar 1, 2021
4184ce5
[UPD] Update default_multi_user.pot
oca-travis Mar 5, 2021
edcb417
[UPD] README.rst
OCA-git-bot Mar 5, 2021
47485c8
Added translation using Weblate (Spanish)
anasuarez1 Mar 16, 2021
d3d3aad
Translated using Weblate (Spanish)
anasuarez1 Mar 16, 2021
86e5de4
Added translation using Weblate (Portuguese)
pedrocs-exo Jul 2, 2021
38548d7
Translated using Weblate (Portuguese)
pedrocs-exo Jul 2, 2021
88e05da
[MIG] default_multi_user: Migration to 15.0
mariadforgeflow Dec 9, 2021
61a68c7
[UPD] Update default_multi_user.pot
Dec 13, 2021
b506a29
[UPD] README.rst
OCA-git-bot Dec 13, 2021
0b2f8e9
[IMP] default_multi_user: pre-commit stuff
dsolanki-initos Mar 20, 2023
d46fd94
[MIG] default_multi_user: Migration to 16.0
dsolanki-initos Mar 20, 2023
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
92 changes: 92 additions & 0 deletions default_multi_user/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
==================
Default Multi User
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/16.0/default_multi_user
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-15-0/server-ux-15-0-default_multi_user
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/250/15.0
:alt: Try me on Runbot

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

Allows to share user-defined defaults among several users.

**Table of contents**

.. contents::
:local:

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

To share a default among several users you need to:

#. Go to *Settings > Technical > Actions > User-defined Defaults*.
#. Edit a default and fill the field *Available for users* and *Available for
Groups* with the desired users and/or groups.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20default_multi_user%0Aversion:%2015.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
~~~~~~~

* ForgeFlow

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

* Lois Rilo <lois.rilo@forgeflow.com>
* Sunanda Chhatbar <sunanda.chhatbar@initos.com>
* Dhara Solanki <dhara.solanki@initos.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.

.. |maintainer-LoisRForgeFlow| image:: https://github.com/LoisRForgeFlow.png?size=40px
:target: https://github.com/LoisRForgeFlow
:alt: LoisRForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-LoisRForgeFlow|

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/16.0/default_multi_user>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions default_multi_user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_load_hook
17 changes: 17 additions & 0 deletions default_multi_user/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Default Multi User",
"summary": "Allows to share user-defined defaults among several users.",
"version": "16.0.1.0.0",
"development_status": "Beta",
"maintainers": ["LoisRForgeFlow"],
"category": "Tools",
"website": "https://github.com/OCA/server-ux",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["base"],
"data": ["views/ir_default_view.xml"],
"post_load": "post_load_hook",
}
32 changes: 32 additions & 0 deletions default_multi_user/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import json

from odoo import api, tools

from odoo.addons.base.models.ir_default import IrDefault


def post_load_hook():
@api.model
@tools.ormcache("self.env.uid", "model_name", "condition")
def new_get_model_defaults(self, model_name, condition=False):
if not hasattr(self, "_get_model_defaults_query_and_params"):
return self.get_model_defaults_original(model_name, condition=condition)

Check warning on line 16 in default_multi_user/hooks.py

View check run for this annotation

Codecov / codecov/patch

default_multi_user/hooks.py#L16

Added line #L16 was not covered by tests
cr = self.env.cr
# START OF CHANGES
query, params = self._get_model_defaults_query_and_params(model_name, condition)
# END OF CHANGES
cr.execute(query, params)
result = {}
for row in cr.fetchall():
# keep the highest priority default for each field
if row[0] not in result:
result[row[0]] = json.loads(row[1])
return result

if not hasattr(IrDefault, "get_model_defaults_original"):
IrDefault.get_model_defaults_original = IrDefault.get_model_defaults

IrDefault._patch_method("get_model_defaults", new_get_model_defaults)
40 changes: 40 additions & 0 deletions default_multi_user/i18n/default_multi_user.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * default_multi_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__group_ids
msgid "Available for Groups"
msgstr ""

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__manual_user_ids
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_tree
msgid "Available for Users"
msgstr ""

#. module: default_multi_user
#: model:ir.model,name:default_multi_user.model_ir_default
msgid "Default Values"
msgstr ""

#. module: default_multi_user
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_form
msgid "Owner"
msgstr ""

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__user_ids
msgid "Users"
msgstr ""
58 changes: 58 additions & 0 deletions default_multi_user/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * default_multi_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-03-16 11:46+0000\n"
"Last-Translator: Ana Suárez <ana.suarez@qubiq.es>\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.3.2\n"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__group_ids
msgid "Available for Groups"
msgstr "Disponible para Grupos"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__manual_user_ids
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_tree
msgid "Available for Users"
msgstr "Disponible para Usuarios"

#. module: default_multi_user
#: model:ir.model,name:default_multi_user.model_ir_default
msgid "Default Values"
msgstr "Valores por defecto"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__display_name
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__id
msgid "ID"
msgstr "ID"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default____last_update
msgid "Last Modified on"
msgstr "Última modificación el"

#. module: default_multi_user
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_form
msgid "Owner"
msgstr "Propietario"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__user_ids
msgid "Users"
msgstr "Usuarios"
58 changes: 58 additions & 0 deletions default_multi_user/i18n/pt.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * default_multi_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-07-02 22:51+0000\n"
"Last-Translator: Pedro Castro Silva <pedrocs@exo.pt>\n"
"Language-Team: none\n"
"Language: pt\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: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__group_ids
msgid "Available for Groups"
msgstr "Disponível para Grupos"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__manual_user_ids
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_tree
msgid "Available for Users"
msgstr "Disponível para Utilizadores"

#. module: default_multi_user
#: model:ir.model,name:default_multi_user.model_ir_default
msgid "Default Values"
msgstr "Valore Pré-definidos"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__display_name
msgid "Display Name"
msgstr "Nome a Exibir"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__id
msgid "ID"
msgstr "ID"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default____last_update
msgid "Last Modified on"
msgstr "Última Modificação em"

#. module: default_multi_user
#: model_terms:ir.ui.view,arch_db:default_multi_user.ir_default_view_form
msgid "Owner"
msgstr "Proprietário"

#. module: default_multi_user
#: model:ir.model.fields,field_description:default_multi_user.field_ir_default__user_ids
msgid "Users"
msgstr "Utilizadores"
1 change: 1 addition & 0 deletions default_multi_user/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_default
55 changes: 55 additions & 0 deletions default_multi_user/models/ir_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class IrDefaultgard(models.Model):
_inherit = "ir.default"

user_ids = fields.Many2many(
comodel_name="res.users",
string="Users",
relation="ir_default_res_users_rel",
column1="ir_default_id",
column2="res_users_id",
compute="_compute_user_ids",
store=True,
)
manual_user_ids = fields.Many2many(
comodel_name="res.users",
string="Available for Users",
relation="ir_default_res_users_manual_rel",
)
group_ids = fields.Many2many(
comodel_name="res.groups",
string="Available for Groups",
)

@api.constrains("manual_user_ids", "group_ids")
def _compute_user_ids(self):
for rec in self:
rec.user_ids = rec.manual_user_ids + rec.group_ids.users

@api.model
def _get_model_defaults_query_and_params(self, model_name, condition):
query = """
SELECT f.name, d.json_value FROM ir_default d
JOIN ir_model_fields f ON d.field_id=f.id
JOIN res_users u ON u.id=%s
LEFT JOIN ir_default_res_users_rel m
ON m.ir_default_id = d.id
WHERE f.model=%s
AND ((d.user_id IS NULL AND m.res_users_id IS NULL)
OR d.user_id=u.id OR m.res_users_id = u.id)
AND (d.company_id IS NULL OR d.company_id=%s)
AND {}
ORDER BY d.user_id, m.res_users_id, d.company_id, d.id
"""
params = [self.env.uid, model_name, self.env.company.id or None]
if condition:
query = query.format("d.condition=%s")
params.append(condition)

Check warning on line 52 in default_multi_user/models/ir_default.py

View check run for this annotation

Codecov / codecov/patch

default_multi_user/models/ir_default.py#L51-L52

Added lines #L51 - L52 were not covered by tests
else:
query = query.format("d.condition IS NULL")
return query, params
5 changes: 5 additions & 0 deletions default_multi_user/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To share a default among several users you need to:

#. Go to *Settings > Technical > Actions > User-defined Defaults*.
#. Edit a default and fill the field *Available for users* and *Available for
Groups* with the desired users and/or groups.
3 changes: 3 additions & 0 deletions default_multi_user/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Lois Rilo <lois.rilo@forgeflow.com>
* Sunanda Chhatbar <sunanda.chhatbar@initos.com>
* Dhara Solanki <dhara.solanki@initos.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As fare as I know are migrations without any code change not enough to put you on the contributor list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please @dsolanki-initos could you review this PR?

1 change: 1 addition & 0 deletions default_multi_user/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows to share user-defined defaults among several users.
Binary file added default_multi_user/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading