Skip to content

Commit 379c656

Browse files
committed
[MIG] stock_account_operating_unit: Migration to 18.0
1 parent afe37b0 commit 379c656

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

stock_account_operating_unit/__manifest__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
"name": "Stock account moves with Operating Unit",
88
"summary": "Create journal entries in moves between internal locations "
99
"with different operating units.",
10-
"version": "15.0.1.0.0",
10+
"version": "18.0.1.0.0",
1111
"category": "Generic Modules/Sales & Purchases",
1212
"author": "Eficent Business and IT Consulting Services S.L., "
1313
"Serpent Consulting Services Pvt. Ltd.,"
1414
"Odoo Community Association (OCA)",
1515
"license": "LGPL-3",
1616
"website": "https://github.com/OCA/operating-unit",
17-
"depends": ["stock_operating_unit", "account_operating_unit", "stock_account"],
17+
"depends": [
18+
"stock_operating_unit",
19+
"account_operating_unit",
20+
"stock_account",
21+
],
1822
"installable": True,
1923
}

stock_account_operating_unit/model/stock_move.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# - Jordi Ballester Alomar
33
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
44
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
5-
from odoo import _, exceptions, models
5+
from odoo import exceptions, models
66

77

88
class StockMove(models.Model):
@@ -36,36 +36,41 @@ def _generate_valuation_lines_data(
3636
self.operating_unit_id
3737
and self.operating_unit_dest_id
3838
and self.operating_unit_id != self.operating_unit_dest_id
39-
and debit_line_vals["account_id"] != credit_line_vals["account_id"]
39+
and debit_line_vals["account_id"]
40+
!= credit_line_vals["account_id"]
4041
):
4142
raise exceptions.UserError(
42-
_(
43+
self.env._(
4344
"You cannot create stock moves involving separate source"
4445
" and destination accounts related to different "
4546
"operating units."
4647
)
4748
)
4849

4950
if not self.operating_unit_dest_id and not self.operating_unit_id:
50-
ou_id = (
51-
self.picking_id.picking_type_id.warehouse_id.operating_unit_id.id
52-
)
51+
ou_id = self.picking_id.picking_type_id.warehouse_id.operating_unit_id.id
5352
else:
5453
ou_id = False
5554

5655
debit_line_vals["operating_unit_id"] = (
57-
ou_id or self.operating_unit_dest_id.id or self.operating_unit_id.id
56+
ou_id
57+
or self.operating_unit_dest_id.id
58+
or self.operating_unit_id.id
5859
)
5960
credit_line_vals["operating_unit_id"] = (
60-
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
61+
ou_id
62+
or self.operating_unit_id.id
63+
or self.operating_unit_dest_id.id
6164
)
6265
rslt = {
6366
"credit_line_vals": credit_line_vals,
6467
"debit_line_vals": debit_line_vals,
6568
}
6669
if price_diff_line_vals:
6770
price_diff_line_vals["operating_unit_id"] = (
68-
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
71+
ou_id
72+
or self.operating_unit_id.id
73+
or self.operating_unit_dest_id.id
6974
)
7075
rslt["price_diff_line_vals"] = price_diff_line_vals
7176
return rslt
@@ -86,7 +91,8 @@ def _action_done(self, cancel_backorder=False):
8691
# from/to non-internal location
8792
if (
8893
move.location_id.company_id
89-
and move.location_id.company_id == move.location_dest_id.company_id
94+
and move.location_id.company_id
95+
== move.location_dest_id.company_id
9096
and move.operating_unit_id != move.operating_unit_dest_id
9197
):
9298
(
@@ -101,7 +107,8 @@ def _action_done(self, cancel_backorder=False):
101107
move.product_id.standard_price,
102108
acc_valuation,
103109
acc_valuation,
104-
_("%s - OU Move") % move.product_id.display_name,
110+
self.env._("%s - OU Move")
111+
% move.product_id.display_name,
105112
)
106113
am = (
107114
self.env["account.move"]
@@ -113,7 +120,8 @@ def _action_done(self, cancel_backorder=False):
113120
"journal_id": journal_id,
114121
"line_ids": move_lines,
115122
"company_id": move.company_id.id,
116-
"ref": move.picking_id and move.picking_id.name,
123+
"ref": move.picking_id
124+
and move.picking_id.name,
117125
"stock_move_id": move.id,
118126
}
119127
)

stock_account_operating_unit/tests/test_stock_account_operating_unit.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
class TestStockAccountOperatingUnit(TestStockCommon):
11-
def setUp(self):
12-
super().setUp()
11+
def setUpClass(self):
12+
super().setUpClass()
1313
self.res_groups = self.env["res.groups"]
1414
self.res_users_model = self.env["res.users"]
1515
self.aml_model = self.env["account.move.line"]
@@ -56,12 +56,16 @@ def setUp(self):
5656
name = "Goods Received Not Invoiced"
5757
code = "grni"
5858
acc_type = self.env.ref("account.data_account_type_equity")
59-
self.account_grni = self._create_account(acc_type, name, code, self.company)
59+
self.account_grni = self._create_account(
60+
acc_type, name, code, self.company
61+
)
6062
# Create account for Cost of Goods Sold
6163
name = "Cost of Goods Sold"
6264
code = "cogs"
6365
acc_type = self.env.ref("account.data_account_type_expenses")
64-
self.account_cogs_id = self._create_account(acc_type, name, code, self.company)
66+
self.account_cogs_id = self._create_account(
67+
acc_type, name, code, self.company
68+
)
6569
# Create account for Inventory
6670
name = "Inventory"
6771
code = "inventory"
@@ -146,7 +150,9 @@ def _create_product(self):
146150
)
147151
return product
148152

149-
def _create_picking(self, user, ou_id, picking_type, src_loc_id, dest_loc_id):
153+
def _create_picking(
154+
self, user, ou_id, picking_type, src_loc_id, dest_loc_id
155+
):
150156
"""Create a Picking."""
151157
picking = self.picking_model.with_user(user.id).create(
152158
{
@@ -204,7 +210,8 @@ def _check_account_balance(
204210
self.assertEqual(
205211
balance,
206212
expected_balance,
207-
"Balance is not %s for all Operating Units." % str(expected_balance),
213+
"Balance is not %s for all Operating Units."
214+
% str(expected_balance),
208215
)
209216

210217
def _get_balance(self, domain):
@@ -258,7 +265,9 @@ def test_pickings(self):
258265
# irrespective of the OU
259266
expected_balance = -1.0
260267
self._check_account_balance(
261-
self.account_grni.id, operating_unit=None, expected_balance=expected_balance
268+
self.account_grni.id,
269+
operating_unit=None,
270+
expected_balance=expected_balance,
262271
)
263272
# GL account ‘Goods Received Not Invoiced’ has balance -1 on Main OU
264273
expected_balance = -1.0
@@ -312,7 +321,9 @@ def test_pickings(self):
312321
# irrespective of the OU
313322
expected_balance = -2.0
314323
self._check_account_balance(
315-
self.account_grni.id, operating_unit=None, expected_balance=expected_balance
324+
self.account_grni.id,
325+
operating_unit=None,
326+
expected_balance=expected_balance,
316327
)
317328
# GL account ‘Goods Received Not Invoiced’ has balance -1 on Main OU
318329
expected_balance = -1.0

0 commit comments

Comments
 (0)