Skip to content

Commit

Permalink
[MIG] contract_operating_unit: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn authored and OCA-git-bot committed Jul 30, 2024
1 parent f9a66ff commit 3f83de6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 71 deletions.
10 changes: 5 additions & 5 deletions contract_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Contract Operating Unit
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/15.0/contract_operating_unit
:target: https://github.com/OCA/operating-unit/tree/16.0/contract_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-contract_operating_unit
:target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-contract_operating_unit
: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/operating-unit&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -50,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/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/operating-unit/issues/new?body=module:%20contract_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20contract_operating_unit%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.

Expand Down Expand Up @@ -82,6 +82,6 @@ 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/operating-unit <https://github.com/OCA/operating-unit/tree/15.0/contract_operating_unit>`_ project on GitHub.
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/contract_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion contract_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Contract Operating Unit",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
Expand Down
10 changes: 3 additions & 7 deletions contract_operating_unit/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ class ContractContract(models.Model):
operating_unit_id = fields.Many2one(
"operating.unit",
"Operating Unit",
default=lambda self: self.env["res.users"].operating_unit_default_get(
self._uid
),
default=lambda self: self.env["res.users"].operating_unit_default_get(),
)

def _prepare_invoice(self, date_invoice, journal=None):
(invoice_vals, move_form) = super()._prepare_invoice(
date_invoice, journal=journal
)
invoice_vals = super()._prepare_invoice(date_invoice, journal=journal)
if self.operating_unit_id:
invoice_vals["operating_unit_id"] = self.operating_unit_id.id
return (invoice_vals, move_form)
return invoice_vals
6 changes: 3 additions & 3 deletions contract_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Contract Operating Unit</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1bf7413f738eb06d7f40c5ea6903fd1ffcb6abe7994c8dfd04afa916149458b7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/15.0/contract_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-contract_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><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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/16.0/contract_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-contract_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>
<ul class="simple">
<li>Adds the Operating Unit (OU) to Contracts.</li>
Expand Down Expand Up @@ -396,7 +396,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20contract_operating_unit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20contract_operating_unit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -422,7 +422,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/contract_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/16.0/contract_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
105 changes: 50 additions & 55 deletions contract_operating_unit/tests/test_contract_operating_unit.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,47 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.tests import common
from odoo.addons.contract.tests.test_contract import TestContractBase


class TestContractOperatingUnit(common.TransactionCase):
def setUp(self):
super(TestContractOperatingUnit, self).setUp()
class TestContractOperatingUnit(TestContractBase):
@classmethod
def setUpClass(cls):
super().setUpClass()

self.res_users_model = self.env["res.users"]
self.contract_model = self.env["contract.contract"]
cls.res_users_model = cls.env["res.users"]

self.company = self.env.ref("base.main_company")
self.grp_contract_manager = self.env.ref("account.group_account_manager")
self.group_user = self.env.ref("base.group_user")
cls.company = cls.env.ref("base.main_company")
cls.grp_contract_manager = cls.env.ref("account.group_account_manager")
cls.contract_model = cls.env["contract.contract"]
cls.group_user = cls.env.ref("base.group_user")

# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
cls.ou1 = cls.env.ref("operating_unit.main_operating_unit")
# B2C Operating Unit
self.b2c = self.env.ref("operating_unit.b2c_operating_unit")
cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit")

# Create Users
self.user1 = self._create_user(
cls.user1 = cls._create_user(
"User_1",
[self.grp_contract_manager, self.group_user],
self.company,
[self.ou1, self.b2c],
[cls.grp_contract_manager, cls.group_user],
cls.company,
[cls.ou1, cls.b2c],
)
self.user2 = self._create_user(
cls.user2 = cls._create_user(
"User_2",
[self.grp_contract_manager, self.group_user],
self.company,
[self.b2c],
[cls.grp_contract_manager, cls.group_user],
cls.company,
[cls.b2c],
)
cls.contract.operating_unit_id = cls.ou1
cls.contract2.operating_unit_id = cls.b2c

self.partner = self.env["res.partner"].create(
{
"name": "Test contract partner",
}
)

self.contract1 = (
self.env["contract.contract"]
.with_user(self.user1.id)
.create(
{
"name": "Maintenance of Servers",
"partner_id": self.partner.id,
"operating_unit_id": self.ou1.id,
}
)
)
self.contract2 = (
self.env["contract.contract"]
.with_user(self.user2.id)
.create(
{
"name": "Maintenance of Servers",
"partner_id": self.partner.id,
"operating_unit_id": self.b2c.id,
}
)
)

def _create_user(self, login, groups, company, operating_units, context=None):
@classmethod
def _create_user(cls, login, groups, company, operating_units, context=None):
"""Creates a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create(
user = cls.res_users_model.create(
{
"name": "Test Contract User",
"login": login,
Expand All @@ -86,12 +61,32 @@ def test_contract_ou(self):
# Access Contract records of Main Operating Unit.
record = self.contract_model.with_user(self.user2.id).search(
[
("id", "=", self.contract1.id),
("id", "=", self.contract.id),
("operating_unit_id", "=", self.ou1.id),
]
)
self.assertEqual(
record.ids,
[],
"User 2 should not have access to " "OU %s" % self.ou1.name,
self.assertFalse(
record,
"User 2 should not have access to OU %s" % self.ou1.name,
)

def test_default(self):
"""Test that the user's OU is used when creating a contract"""
contract = (
self.env["contract.contract"]
.with_user(self.user1)
.create(
{
"name": "A contract",
"partner_id": self.env["res.partner"]
.search([], order="customer_rank desc", limit=1)
.id,
}
)
)
self.assertEqual(contract.operating_unit_id, self.ou1)

def test_contract_invoice(self):
"""Test that invoices from contracts get the contract's OU assigned"""
invoice = self.contract2._recurring_create_invoice()
self.assertEqual(invoice.operating_unit_id, self.b2c)
6 changes: 6 additions & 0 deletions setup/contract_operating_unit/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,
)

0 comments on commit 3f83de6

Please sign in to comment.