Skip to content

Commit

Permalink
Merge PR #178 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Nov 15, 2024
2 parents 040d613 + 3f16aa4 commit e3fe734
Show file tree
Hide file tree
Showing 16 changed files with 701 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/web_select_only_child_company/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
94 changes: 94 additions & 0 deletions web_select_only_child_company/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
=======================
Companies - Only Childs
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c2242a93fd226bb64ee5d53346547d2491df28560f206b885f5df0c95804ad2b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/res_company_select_only_childs
: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-res_company_select_only_childs
: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|

This module is usefull in a multi-company context with hierarchy.
(with parent and child companies)

Once installed, if a user select a company in the UI,
it will select all the child companies, and remove all the companies
that doesn't belong to the selected one.

this module is usefull when you have a structure of companies
with parent and childs, and if it makes no sense to display parent information
without childs information. In that case, the users will save a lot of time
to select companies.

**Table of contents**

.. contents::
:local:

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:%20res_company_select_only_childs%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
~~~~~~~

* GRAP

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

* Sylvain LE GAL <https://twitter.com/legalsylvain>

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-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px
:target: https://github.com/legalsylvain
:alt: legalsylvain

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

|maintainer-legalsylvain|

This module is part of the `OCA/multi-company <https://github.com/OCA/multi-company/tree/16.0/res_company_select_only_childs>`_ 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 web_select_only_child_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions web_select_only_child_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Companies - Only Childs",
"summary": "When selecting a company,"
" automatically select all the child companies.",
"version": "16.0.1.0.0",
"category": "Tools",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/grap/grap-odoo-incubator",
"license": "AGPL-3",
"depends": ["web"],
"assets": {
"web.assets_backend": [
"web_select_only_child_company/static/src/xml/switch_company_menu.xml",
"web_select_only_child_company/static/src/js/switch_company_menu.esm.js",
],
},
"demo": ["demo/res_company.xml"],
"installable": True,
}
29 changes: 29 additions & 0 deletions web_select_only_child_company/demo/res_company.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="company_parent" model="res.company">
<field name="name">Parent Company (Demo data Only Child)</field>
<field
name="user_ids"
eval="[
(4, ref('base.user_admin')),
(4, ref('base.user_demo')),
]"
/>
</record>
<record id="company_child" model="res.company">
<field name="name">Child Company (Demo data Only Child)</field>
<field name="parent_id" ref="company_parent" />
<field
name="user_ids"
eval="[
(4, ref('base.user_admin')),
(4, ref('base.user_demo')),
]"
/>
</record>
</odoo>
Empty file.
2 changes: 2 additions & 0 deletions web_select_only_child_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_http
from . import res_company
18 changes: 18 additions & 0 deletions web_select_only_child_company/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


class Http(models.AbstractModel):
_inherit = "ir.http"

def session_info(self):
result = super().session_info()
if self.env.user.has_group("base.group_user"):
for company in self.env.user.company_ids:
result["user_companies"]["allowed_companies"][company.id][
"all_child_ids"
] = company.all_child_ids.ids
return result
20 changes: 20 additions & 0 deletions web_select_only_child_company/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class ResCompany(models.Model):
_inherit = "res.company"

all_child_ids = fields.One2many(
comodel_name="res.company", compute="_compute_all_child_ids", recursive=True
)

@api.depends("child_ids.all_child_ids")
def _compute_all_child_ids(self):
for company in self:
company.all_child_ids = company.mapped("child_ids") | company.mapped(
"child_ids.all_child_ids"
)
1 change: 1 addition & 0 deletions web_select_only_child_company/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
11 changes: 11 additions & 0 deletions web_select_only_child_company/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module is usefull in a multi-company context with hierarchy.
(with parent and child companies)

Once installed, if a user select a company in the UI,
it will select all the child companies, and remove all the companies
that doesn't belong to the selected one.

this module is usefull when you have a structure of companies
with parent and childs, and if it makes no sense to display parent information
without childs information. In that case, the users will save a lot of time
to select companies.
3 changes: 3 additions & 0 deletions web_select_only_child_company/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module requires a patch in the core of odoo, available here.

https://github.com/odoo/odoo/pull/186621
Loading

0 comments on commit e3fe734

Please sign in to comment.