Skip to content

Commit

Permalink
Merge PR #706 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Feb 20, 2025
2 parents 936a4ae + 33445c2 commit ad3ffa1
Show file tree
Hide file tree
Showing 17 changed files with 748 additions and 0 deletions.
86 changes: 86 additions & 0 deletions ir_actions_report_multi_company/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
===============================
Ir Actions Report Multi Company
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6c602285e506c9e77fc87eb04bbc57a32d9cb1a46e416c44bed8993d41fdbd6f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fmulti--company-lightgray.png?logo=github
:target: https://github.com/OCA/multi-company/tree/16.0/ir_actions_report_multi_company
:alt: OCA/multi-company
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/multi-company-16-0/multi-company-16-0-ir_actions_report_multi_company
: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/multi-company&target_branch=16.0
:alt: Try me on Runboat

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

Make Report Actions multi-company Aware.

**Table of contents**

.. contents::
:local:

Usage
=====

The usual multi-company record rule is installed automatically.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/multi-company/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/multi-company/issues/new?body=module:%20ir_actions_report_multi_company%0Aversion:%2016.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
~~~~~~~

* ACSONE SA/NV

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

* Jonathan Nemry <[email protected]>
* Andrea Stirpe <[email protected]>
* `XCG Consulting <https://xcg-consulting.fr/>`_:

* Étienne Ferrière
* Vincent Hatakeyama

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/multi-company <https://github.com/OCA/multi-company/tree/16.0/ir_actions_report_multi_company>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions ir_actions_report_multi_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models # noqa: F401
13 changes: 13 additions & 0 deletions ir_actions_report_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2016 ACSONE SA/NV, Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Ir Actions Report Multi Company",
"summary": "Make Report Actions multi-company aware",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"depends": ["base"],
"data": ["views/ir_actions_report_view.xml", "security/multi_company.xml"],
}
36 changes: 36 additions & 0 deletions ir_actions_report_multi_company/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * ir_actions_report_multi_company
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-14 08:32+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: Vincent Hatakeyama <[email protected]>\n"
"Language-Team: \n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 2.4.2\n"

#. module: ir_actions_report_multi_company
#: model:ir.model,name:ir_actions_report_multi_company.model_ir_actions_actions
msgid "Actions"
msgstr "Actions"

#. module: ir_actions_report_multi_company
#: model:ir.model.fields,field_description:ir_actions_report_multi_company.field_ir_actions_report__company_id
msgid "Company"
msgstr "Société"

#. module: ir_actions_report_multi_company
#: model:ir.model,name:ir_actions_report_multi_company.model_ir_actions_report
msgid "Report Action"
msgstr "Action de rapport"

#~ msgid "ir.actions.report"
#~ msgstr "ir.actions.report"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * ir_actions_report_multi_company
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-14 08:32+0000\n"
"PO-Revision-Date: 2022-06-14 08:32+0000\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: ir_actions_report_multi_company
#: model:ir.model,name:ir_actions_report_multi_company.model_ir_actions_actions
msgid "Actions"
msgstr ""

#. module: ir_actions_report_multi_company
#: model:ir.model.fields,field_description:ir_actions_report_multi_company.field_ir_actions_report__company_id
msgid "Company"
msgstr ""

#. module: ir_actions_report_multi_company
#: model:ir.model,name:ir_actions_report_multi_company.model_ir_actions_report
msgid "Report Action"
msgstr ""
2 changes: 2 additions & 0 deletions ir_actions_report_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_actions_actions # noqa: F401
from . import ir_actions_report # noqa: F401
95 changes: 95 additions & 0 deletions ir_actions_report_multi_company/models/ir_actions_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright 2022 XCG Consulting
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, tools
from odoo.tools import frozendict


class IrActionsActions(models.Model):
_inherit = "ir.actions.actions"

# Add companies to the cache of this method that is used in
# models.BaseModels.fields_view_get to get the toolbar actions that are now
# company dependant.
@tools.ormcache(
"frozenset(self.env.user.groups_id.ids)",
"frozenset(self.env.companies.ids)",
"model_name",
"self.env.lang",
)
def _get_bindings(self, model_name):
"""Retrieve the list of actions bound to the given model.
:return: a dict mapping binding types to a list of dict describing
actions, where the latter is given by calling the method
``read`` on the action record.
"""
# get company related reports
reports = self._get_report_bindings(model_name)

# Using __wrapped__ is necessary to bypass the cache put by Odoo on the
# super method.
result = super()._get_bindings.__wrapped__(self, model_name)

# update bindings result
if reports:
result = dict(result)
result["report"] = reports
result = frozendict(result)

return result

def _get_report_bindings(self, model_name):
"""
Get report bindings for current company
"""
cr = self.env.cr
self.env.flush_all()

query = """
SELECT report.id, report.type
FROM ir_act_report_xml report
JOIN ir_model m ON report.binding_model_id = m.id
WHERE m.model = %s
AND (report.company_id = ANY(%s) OR report.company_id IS NULL)
AND report.binding_type = 'report'
"""
cr.execute(query, (model_name, self.env.companies.ids))

report_ids = [report_id for report_id, report_type_ in cr.fetchall()]
result = []

if report_ids:
reports = (
self.env["ir.actions.report"]
.sudo()
.search_read(
[("id", "in", report_ids)],
["name", "binding_view_types", "groups_id", "model"],
order="id",
)
)

groups_obj = self.env["res.groups"]
model_access_obj = self.env["ir.model.access"]

for report in reports:
group_ids = report.pop("groups_id", None)
if group_ids:
groups = groups_obj.browse(group_ids)
xml_ids = ",".join(
ext_id for ext_id in groups._ensure_xml_id().values()
)
if groups and not self.user_has_groups(xml_ids):
# the user may not perform this action
continue

model = report.pop("model", None)
if model and not model_access_obj.check(
model, mode="read", raise_exception=False
):
# the user won't be able to read records
continue

result.append(frozendict(report))

return result
11 changes: 11 additions & 0 deletions ir_actions_report_multi_company/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class IrActionsReport(models.Model):

_inherit = "ir.actions.report"

company_id = fields.Many2one("res.company")
6 changes: 6 additions & 0 deletions ir_actions_report_multi_company/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Jonathan Nemry <[email protected]>
* Andrea Stirpe <[email protected]>
* `XCG Consulting <https://xcg-consulting.fr/>`_:

* Étienne Ferrière
* Vincent Hatakeyama
1 change: 1 addition & 0 deletions ir_actions_report_multi_company/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make Report Actions multi-company Aware.
1 change: 1 addition & 0 deletions ir_actions_report_multi_company/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The usual multi-company record rule is installed automatically.
14 changes: 14 additions & 0 deletions ir_actions_report_multi_company/security/multi_company.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="ir_actions_report_rule" model="ir.rule">
<field name="name">Ir Actions Report XML multi-company</field>
<field name="model_id" ref="base.model_ir_actions_report" />
<field name="global" eval="True" />
<field
name="domain_force"
> ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
<field name="active" eval="True" />
</record>

</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ad3ffa1

Please sign in to comment.