Skip to content

Commit

Permalink
Merge pull request #535 from OCA/16.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/operating-unit (16.0)
  • Loading branch information
bt-admin authored Jan 11, 2024
2 parents 6d9bc39 + 093c072 commit c7390d2
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[analytic_operating_unit](analytic_operating_unit/) | 16.0.1.0.0 | | Analytic Operating Unit
[operating_unit](operating_unit/) | 16.0.1.0.1 | | An operating unit (OU) is an organizational entity part of a company
[product_operating_unit](product_operating_unit/) | 16.0.1.0.0 | | Adds the concept of operating unit (OU) in products
[operating_unit](operating_unit/) | 16.0.1.0.2 | | An operating unit (OU) is an organizational entity part of a company
[product_operating_unit](product_operating_unit/) | 16.0.1.0.1 | | Adds the concept of operating unit (OU) in products
[project_operating_unit](project_operating_unit/) | 16.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.
[sales_team_operating_unit](sales_team_operating_unit/) | 16.0.1.0.0 | | Sales Team Operating Unit
[stock_operating_unit](stock_operating_unit/) | 16.0.1.2.1 | | Adds the concept of operating unit (OU) in stock 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:617e0f9f664d1eff2a67912f943e07359e22b121fb01a906651d0e3741217ab9
!! source digest: sha256:00f612d7de01fe0f9ee18121c1840b65fef8e073af69a0bec3c4fadcb97e3f3d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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": "16.0.1.0.1",
"version": "16.0.1.0.2",
"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

Check warning on line 28 in operating_unit/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

operating_unit/models/res_users.py#L28

Added line #L28 was not covered by tests
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:617e0f9f664d1eff2a67912f943e07359e22b121fb01a906651d0e3741217ab9
!! source digest: sha256:00f612d7de01fe0f9ee18121c1840b65fef8e073af69a0bec3c4fadcb97e3f3d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/16.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-16-0/operating-unit-16-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=16.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 @@ -19,6 +19,7 @@ def setUpClass(cls):
cls.grp_ou_multi = cls.env.ref("operating_unit.group_multi_operating_unit")
# Company
cls.company = cls.env.ref("base.main_company")
cls.company_2 = cls.env["res.company"].create({"name": "Second company"})
# Main Operating Unit
cls.ou1 = cls.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
Expand Down Expand Up @@ -48,12 +49,21 @@ def _create_user(cls, 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 @@ -144,6 +154,34 @@ def test_find_operating_unit_by_name_or_code(self):
self.assertEqual(ou.name_search("cod"), expected_result)
self.assertEqual(ou.name_search("dummy"), [])

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,
)

def test_create_multi_operating_unit(self):
res = (
self.env["operating.unit"]
Expand Down
2 changes: 1 addition & 1 deletion product_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Operating Unit in Products
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cf1414fbd22bae056b66da6e9bc95b3d410edd452f4af192e18938e6da182cd1
!! source digest: sha256:8cdd7804890d72bfcd56f38bfd06a59fb49f68e5ef3820aaebb4cb731419338a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion product_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Operating Unit in Products",
"summary": "Adds the concept of operating unit (OU) in products",
"version": "16.0.1.0.0",
"version": "16.0.1.0.1",
"author": "brain-tec AG, "
"Open Source Integrators, "
"Serpent Consulting Services Pvt. Ltd.,"
Expand Down
5 changes: 3 additions & 2 deletions product_operating_unit/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class ProductTemplate(models.Model):
def _default_operating_unit_ids(self):
if self.categ_id and self.categ_id.operating_unit_ids:
return [(6, 0, self.categ_id.operating_unit_ids.ids)]
if self.env.user.default_operating_unit_id:
default_ou = self.env["res.users"].operating_unit_default_get(self.env.uid)
if default_ou:
return [
(
6,
0,
[self.env["res.users"].operating_unit_default_get(self.env.uid).id],
default_ou.ids,
)
]

Expand Down
3 changes: 1 addition & 2 deletions product_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 in Products</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cf1414fbd22bae056b66da6e9bc95b3d410edd452f4af192e18938e6da182cd1
!! source digest: sha256:8cdd7804890d72bfcd56f38bfd06a59fb49f68e5ef3820aaebb4cb731419338a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/16.0/product_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-16-0/operating-unit-16-0-product_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=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module introduces the following features:</p>
Expand Down

0 comments on commit c7390d2

Please sign in to comment.