Skip to content

Commit 66f3c0d

Browse files
committed
[MIG] account_operating_unit: Migration to 19.0
1 parent 715ef66 commit 66f3c0d

13 files changed

+78
-59
lines changed

account_operating_unit/README.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Accounting with Operating Units
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
24-
:target: https://github.com/OCA/operating-unit/tree/18.0/account_operating_unit
24+
:target: https://github.com/OCA/operating-unit/tree/19.0/account_operating_unit
2525
:alt: OCA/operating-unit
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-account_operating_unit
27+
:target: https://translation.odoo-community.org/projects/operating-unit-19-0/operating-unit-19-0-account_operating_unit
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -111,7 +111,7 @@ Bug Tracker
111111
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
112112
In case of trouble, please check there if your issue has already been reported.
113113
If you spotted it first, help us to smash it by providing a detailed and welcomed
114-
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
114+
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
115115

116116
Do not contact contributors directly about support or help with technical issues.
117117

@@ -143,6 +143,8 @@ Contributors
143143

144144
- Bhavesh Heliconia
145145

146+
- Julien Coux <[email protected]>
147+
146148
Maintainers
147149
-----------
148150

@@ -156,6 +158,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
156158
mission is to support the collaborative development of Odoo features and
157159
promote its widespread use.
158160

159-
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/18.0/account_operating_unit>`_ project on GitHub.
161+
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/19.0/account_operating_unit>`_ project on GitHub.
160162

161163
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_operating_unit/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Accounting with Operating Units",
66
"summary": "Introduces Operating Unit (OU) in invoices and "
77
"Accounting Entries with clearing account",
8-
"version": "18.0.1.0.1",
8+
"version": "19.0.1.0.0",
99
"author": "ForgeFlow, "
1010
"Serpent Consulting Services Pvt. Ltd.,"
1111
"WilldooIT Pty Ltd,"

account_operating_unit/models/account_move.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# © 2019 Serpent Consulting Services Pvt. Ltd.
33
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

5-
from odoo import _, api, fields, models
5+
from odoo import api, fields, models
66
from odoo.exceptions import UserError
7+
from odoo.fields import Command, Domain
78

89

910
class AccountMoveLine(models.Model):
@@ -33,7 +34,7 @@ def _check_move_operating_unit(self):
3334
and rec.move_id.operating_unit_id != rec.operating_unit_id
3435
):
3536
raise UserError(
36-
_(
37+
self.env._(
3738
"Configuration error. The Operating Unit in"
3839
" the Move Line and in the Move must be the"
3940
" same."
@@ -86,7 +87,7 @@ def reconcile(self):
8687
amls = self.with_context(check_move_validity=False).create(line_datas)
8788
if amls:
8889
move.with_context(check_move_validity=True).write(
89-
{"line_ids": [(4, aml.id) for aml in amls]}
90+
{"line_ids": [Command.link(aml.id) for aml in amls]}
9091
)
9192
move.with_context(inter_ou_balance_entry=True).action_post()
9293
return super().reconcile()
@@ -117,8 +118,8 @@ class AccountMove(models.Model):
117118
@api.model
118119
def _default_operating_unit_id(self):
119120
if (
120-
self._context.get("default_move_type", False)
121-
and self._context.get("default_move_type") != "entry"
121+
self.env.context.get("default_move_type", False)
122+
and self.env.context.get("default_move_type") != "entry"
122123
):
123124
return self.env["res.users"]._get_default_operating_unit()
124125
return False
@@ -130,7 +131,7 @@ def _onchange_operating_unit(self):
130131
or self.journal_id.operating_unit_id != self.operating_unit_id
131132
):
132133
journal = self.env["account.journal"].search(
133-
[("type", "=", self.journal_id.type)]
134+
Domain("type", "=", self.journal_id.type)
134135
)
135136
jf = journal.filtered(
136137
lambda aj: aj.operating_unit_id == self.operating_unit_id
@@ -153,15 +154,15 @@ def _compute_operating_unit(self):
153154
def _prepare_inter_ou_balancing_move_line(self, move, ou_id, ou_balances):
154155
if not move.company_id.inter_ou_clearing_account_id:
155156
raise UserError(
156-
_(
157+
self.env._(
157158
"Configuration error. You need to define an"
158159
"inter-operating unit clearing account in the "
159160
"company settings"
160161
)
161162
)
162163

163164
res = {
164-
"name": _("OU-Balancing"),
165+
"name": self.env._("OU-Balancing"),
165166
"move_id": move.id,
166167
"journal_id": move.journal_id.id,
167168
"date": move.date,
@@ -216,7 +217,7 @@ def _post(self, soft=True):
216217
amls = ml_obj.with_context(check_move_validity=False).create(line_datas)
217218
if amls:
218219
move.with_context(check_move_validity=True).write(
219-
{"line_ids": [(4, aml.id) for aml in amls]}
220+
{"line_ids": [Command.link(aml.id) for aml in amls]}
220221
)
221222

222223
return super()._post(soft)
@@ -229,7 +230,7 @@ def _check_ou(self):
229230
for line in move.line_ids:
230231
if not line.operating_unit_id:
231232
raise UserError(
232-
_(
233+
self.env._(
233234
"Configuration error. The operating unit is "
234235
"mandatory for each line as the operating unit "
235236
"has been defined as self-balanced at company "
@@ -246,6 +247,6 @@ def _check_journal_operating_unit(self):
246247
and move.operating_unit_id != move.journal_id.operating_unit_id
247248
):
248249
raise UserError(
249-
_("The OU in the Move and in Journal must be the same.")
250+
self.env._("The OU in the Move and in Journal must be the same.")
250251
)
251252
return True

account_operating_unit/models/account_payment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def _prepare_move_line_default_vals(
2828
)
2929
for line in lines:
3030
line["operating_unit_id"] = self.operating_unit_id.id
31-
active_model = self._context.get("active_model", False)
31+
active_model = self.env.context.get("active_model", False)
3232
if not active_model or active_model != "account.move":
3333
return lines
34-
invoices = self.env[self._context.get("active_model")].browse(
35-
self._context.get("active_ids")
34+
invoices = self.env[self.env.context.get("active_model")].browse(
35+
self.env.context.get("active_ids")
3636
)
3737
invoices_ou = invoices.operating_unit_id
3838
if invoices and len(invoices_ou) == 1 and invoices_ou != self.operating_unit_id:

account_operating_unit/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
- Hieu, Vo Minh Bao \<<[email protected]>\>
1212
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
1313
- Bhavesh Heliconia
14+
- Julien Coux \<<[email protected]>\>

account_operating_unit/static/description/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Accounting with Operating Units</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:0eb4a10dd13a9c7cd234be254acda3395c49bbf3b03de94f05155aa85ce1c1e6
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/18.0/account_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-18-0/operating-unit-18-0-account_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=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<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/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/operating-unit/tree/19.0/account_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-19-0/operating-unit-19-0-account_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=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module allows a company to manage the accounting based on Operating
379379
Units (OU’s).</p>
380380
<ul class="simple">
@@ -465,7 +465,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
465465
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/operating-unit/issues">GitHub Issues</a>.
466466
In case of trouble, please check there if your issue has already been reported.
467467
If you spotted it first, help us to smash it by providing a detailed and welcomed
468-
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
468+
<a class="reference external" href="https://github.com/OCA/operating-unit/issues/new?body=module:%20account_operating_unit%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
469469
<p>Do not contact contributors directly about support or help with technical issues.</p>
470470
</div>
471471
<div class="section" id="credits">
@@ -496,6 +496,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
496496
<li>Bhavesh Heliconia</li>
497497
</ul>
498498
</li>
499+
<li>Julien Coux &lt;<a class="reference external" href="mailto:julien.coux&#64;camptocamp.com">julien.coux&#64;camptocamp.com</a>&gt;</li>
499500
</ul>
500501
</div>
501502
<div class="section" id="maintainers">
@@ -507,7 +508,7 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
507508
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
508509
mission is to support the collaborative development of Odoo features and
509510
promote its widespread use.</p>
510-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/18.0/account_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
511+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/operating-unit/tree/19.0/account_operating_unit">OCA/operating-unit</a> project on GitHub.</p>
511512
<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>
512513
</div>
513514
</div>

account_operating_unit/tests/test_account_operating_unit.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# © 2019 Serpent Consulting Services Pvt. Ltd.
33
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

5-
from odoo.models import Command
5+
from odoo.fields import Command, Domain
66
from odoo.tests import tagged
77

88
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@@ -40,7 +40,7 @@ def setUpClass(cls):
4040
# Add Operating Unit Manager group to env.user
4141
cls.env.user.write(
4242
{
43-
"groups_id": [(4, cls.ou_manager_group.id)],
43+
"group_ids": [Command.link(cls.ou_manager_group.id)],
4444
"company_ids": [Command.link(cls.company.id)],
4545
"company_id": cls.company.id,
4646
}
@@ -58,7 +58,7 @@ def setUpClass(cls):
5858
# Setup user1 with all required groups
5959
cls.user1.write(
6060
{
61-
"groups_id": [
61+
"group_ids": [
6262
Command.link(cls.grp_acc_manager.id),
6363
Command.link(cls.grp_acc_config.id),
6464
Command.link(cls.ou_manager_group.id),
@@ -96,7 +96,7 @@ def setUpClass(cls):
9696
# Setup user2 with all required groups
9797
cls.user2.write(
9898
{
99-
"groups_id": [
99+
"group_ids": [
100100
Command.link(cls.grp_acc_manager.id),
101101
Command.link(cls.grp_acc_config.id),
102102
Command.link(cls.ou_manager_group.id),
@@ -162,17 +162,19 @@ def _prepare_invoice(self, operating_unit_id, name="Test Supplier Invoice"):
162162
"price_unit": 50,
163163
"account_id": self.env["account.account"]
164164
.search(
165-
[
166-
("account_type", "=", "expense"),
167-
("company_ids", "in", self.company.ids),
168-
],
165+
Domain.AND(
166+
[
167+
Domain("account_type", "=", "expense"),
168+
Domain("company_ids", "in", self.company.ids),
169+
]
170+
),
169171
limit=1,
170172
)
171173
.id,
172174
# Adding this line so the taxes are explicitly excluded from the lines
173175
"tax_ids": [],
174176
}
175-
lines.append((0, 0, line_values))
177+
lines.append(Command.create(line_values))
176178
inv_vals = {
177179
"partner_id": self.partner1.id,
178180
"operating_unit_id": operating_unit_id,

account_operating_unit/tests/test_account_reconcile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from odoo.addons.base.tests.common import BaseCommon, Command
1+
from odoo.fields import Command
2+
3+
from odoo.addons.base.tests.common import BaseCommon
24

35

46
class TestAccountBankStatementLine(BaseCommon):

account_operating_unit/tests/test_cross_ou_journal_entry.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

55
from odoo.exceptions import UserError
6+
from odoo.fields import Command, Domain
67
from odoo.tests import Form, tagged
78

89
from . import test_account_operating_unit as test_ou
@@ -12,24 +13,28 @@
1213
class TestCrossOuJournalEntry(test_ou.TestAccountOperatingUnit):
1314
def _check_balance(self, account_id, acc_type="clearing"):
1415
# Check balance for all operating units
15-
domain = [("account_id", "=", account_id)]
16+
domain = Domain("account_id", "=", account_id)
1617
balance = self._get_balance(domain)
1718
self.assertEqual(balance, 0.0, "Balance is 0 for all Operating Units.")
1819
# Check balance for operating B2B units
19-
domain = [
20-
("account_id", "=", account_id),
21-
("operating_unit_id", "=", self.b2b.id),
22-
]
20+
domain = Domain.AND(
21+
[
22+
Domain("account_id", "=", account_id),
23+
Domain("operating_unit_id", "=", self.b2b.id),
24+
]
25+
)
2326
balance = self._get_balance(domain)
2427
if acc_type == "other":
2528
self.assertEqual(balance, -100, "Balance is -100 for Operating Unit B2B.")
2629
else:
2730
self.assertEqual(balance, 100, "Balance is 100 for Operating Unit B2B.")
2831
# Check balance for operating B2C units
29-
domain = [
30-
("account_id", "=", account_id),
31-
("operating_unit_id", "=", self.b2c.id),
32-
]
32+
domain = Domain.AND(
33+
[
34+
Domain("account_id", "=", account_id),
35+
Domain("operating_unit_id", "=", self.b2c.id),
36+
]
37+
)
3338
balance = self._get_balance(domain)
3439
if acc_type == "other":
3540
self.assertEqual(balance, 100.0, "Balance is 100 for Operating Unit B2C.")
@@ -38,7 +43,7 @@ def _check_balance(self, account_id, acc_type="clearing"):
3843

3944
def _get_balance(self, domain):
4045
"""
41-
Call read_group method and return the balance of particular account.
46+
Call _read_group method and return the balance of particular account.
4247
"""
4348
aml_rec = self.aml_model.with_user(self.user1.id)._read_group(
4449
domain, ["account_id"], ["debit:sum", "credit:sum"]
@@ -58,14 +63,18 @@ def test_cross_ou_journal_entry(self):
5863
)
5964
# Create Journal Entries
6065
journal_ids = self.journal_model.search(
61-
[("code", "=", "MISC"), ("company_id", "=", self.company.id)], limit=1
66+
Domain.AND(
67+
[
68+
Domain("code", "=", "MISC"),
69+
Domain("company_id", "=", self.company.id),
70+
]
71+
),
72+
limit=1,
6273
)
6374
# get default values of account move
6475
move_vals = self.move_model.default_get([])
6576
lines = [
66-
(
67-
0,
68-
0,
77+
Command.create(
6978
{
7079
"name": "Test",
7180
"account_id": self.current_asset_account_id.id,
@@ -74,9 +83,7 @@ def test_cross_ou_journal_entry(self):
7483
"operating_unit_id": self.b2b.id,
7584
},
7685
),
77-
(
78-
0,
79-
0,
86+
Command.create(
8087
{
8188
"name": "Test",
8289
"account_id": self.current_asset_account_id.id,

account_operating_unit/tests/test_invoice_operating_unit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

55
from odoo.exceptions import UserError
6+
from odoo.fields import Command, Domain
67
from odoo.tests import Form, tagged
78

89
from . import test_account_operating_unit as test_ou
@@ -42,8 +43,8 @@ def test_create_invoice_validate(self):
4243
with self.assertRaises(UserError):
4344
self.invoice.line_ids[0].company_id = new_company.id
4445
# Check report invoice
45-
self.env["account.invoice.report"].sudo().read_group(
46-
[], ["operating_unit_id"], ["operating_unit_id"]
46+
self.env["account.invoice.report"].sudo()._read_group(
47+
Domain.TRUE, ["operating_unit_id"], ["operating_unit_id"]
4748
)
4849

4950
def test_form(self):
@@ -59,7 +60,7 @@ def test_form(self):
5960
)
6061

6162
# Ensure user has the correct operating unit
62-
self.user1.write({"operating_unit_ids": [(4, self.ou1.id)]})
63+
self.user1.write({"operating_unit_ids": [Command.link(self.ou1.id)]})
6364

6465
# Open the form with default operating unit context
6566
with Form(

0 commit comments

Comments
 (0)