Skip to content

Commit

Permalink
Merge pull request #534 from OCA/15.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/operating-unit (15.0)
  • Loading branch information
bt-admin authored Jan 11, 2024
2 parents 5524a40 + 955b206 commit 8cdfd33
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ addon | version | maintainers | summary
[mis_builder_operating_unit_access_all](mis_builder_operating_unit_access_all/) | 15.0.1.0.0 | [![ps-tubtim](https://github.com/ps-tubtim.png?size=30px)](https://github.com/ps-tubtim) | Access all OUs' MIS Builder
[mrp_operating_unit](mrp_operating_unit/) | 15.0.1.0.0 | | Operating Unit in MRP
[mrp_operating_unit_access_all](mrp_operating_unit_access_all/) | 15.0.1.0.0 | [![ps-tubtim](https://github.com/ps-tubtim.png?size=30px)](https://github.com/ps-tubtim) | Access all OUs' MRP
[operating_unit](operating_unit/) | 15.0.1.0.6 | | An operating unit (OU) is an organizational entity part of a company
[operating_unit](operating_unit/) | 15.0.1.0.7 | | An operating unit (OU) is an organizational entity part of a company
[operating_unit_access_all](operating_unit_access_all/) | 15.0.1.0.0 | [![kittiu](https://github.com/kittiu.png?size=30px)](https://github.com/kittiu) | Access all Operating Units
[project_operating_unit](project_operating_unit/) | 15.0.1.0.0 | [![max3903](https://github.com/max3903.png?size=30px)](https://github.com/max3903) | This module adds operating unit information to projects and tasks.
[purchase_operating_unit](purchase_operating_unit/) | 15.0.1.1.0 | | Adds the concecpt of operating unit (OU) in purchase order management
Expand Down
2 changes: 1 addition & 1 deletion operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Operating Unit
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d2d952bbb132fcefc967728ae9ecd49b95d9b0abf7fe5da895b396c25be11d81
!! source digest: sha256:808772644168895deaa3fc498818a5fb56e6bc6307fa79df36e2b9bfa5274d3e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Operating Unit",
"summary": "An operating unit (OU) is an organizational entity part of a "
"company",
"version": "15.0.1.0.6",
"version": "15.0.1.0.7",
"author": "ForgeFlow, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
Expand Down
14 changes: 13 additions & 1 deletion operating_unit/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ def operating_unit_default_get(self, uid2=False):
if not uid2:
uid2 = self.env.user.id
user = self.env["res.users"].browse(uid2)
return user.default_operating_unit_id
# check if the company of the default OU is active
if user.default_operating_unit_id.sudo().company_id in self.env.companies:
return user.default_operating_unit_id
else:
# find an OU of the main active company
for ou in user.assigned_operating_unit_ids:
if ou.sudo().company_id in self.env.company:
return ou
# find an OU of any active company
for ou in user.assigned_operating_unit_ids:
if ou.sudo().company_id in self.env.companies:
return ou
return False

@api.model
def _default_operating_unit(self):
Expand Down
3 changes: 1 addition & 2 deletions operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">Operating Unit</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d2d952bbb132fcefc967728ae9ecd49b95d9b0abf7fe5da895b396c25be11d81
!! source digest: sha256:808772644168895deaa3fc498818a5fb56e6bc6307fa79df36e2b9bfa5274d3e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/15.0/operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>An operating unit (OU) is an organizational entity part of a company, with
Expand Down
42 changes: 40 additions & 2 deletions operating_unit/tests/test_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setUp(self):
self.grp_ou_multi = self.env.ref("operating_unit.group_multi_operating_unit")
# Company
self.company = self.env.ref("base.main_company")
self.company_2 = self.env["res.company"].create({"name": "Second company"})
# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
Expand Down Expand Up @@ -50,12 +51,21 @@ def _create_user(self, login, group, company, operating_units, context=None):
)
return user

def _create_operating_unit(self, uid, name, code):
def _create_operating_unit(self, uid, name, code, company_id=None):
"""Create Operating Unit"""
if company_id is None:
company_id = self.company
ou = (
self.env["operating.unit"]
.with_user(uid)
.create({"name": name, "code": code, "partner_id": self.company.id})
.create(
{
"name": name,
"code": code,
"partner_id": company_id.partner_id.id,
"company_id": company_id.id,
}
)
)
return ou

Expand Down Expand Up @@ -138,3 +148,31 @@ def test_02_operating_unit(self):
line.code = "007"
user_form.name = "Test Customer"
user_form.login = "test2"

def test_03_operating_unit(self):
"""
The method operating_unit_default_get should not return
operating units belonging to a company that is not active
"""
self.assertEqual(
self.res_users_model.operating_unit_default_get(uid2=self.user1.id),
self.ou1,
)
self.assertEqual(
self.res_users_model.with_company(
self.company_2
).operating_unit_default_get(uid2=self.user1.id),
False,
)

self.user1.company_ids += self.company_2
ou_company_2 = self._create_operating_unit(
self.user1.id, "Test Company", "TESTC", self.company_2
)
self.user1.assigned_operating_unit_ids += ou_company_2
self.assertEqual(
self.res_users_model.with_company(
self.company_2
).operating_unit_default_get(uid2=self.user1.id),
ou_company_2,
)

0 comments on commit 8cdfd33

Please sign in to comment.