Skip to content

Commit

Permalink
[18.0][MIG] mrp_operating_unit: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BT-dlagin committed Dec 10, 2024
1 parent 2a1337e commit 7d87b10
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mrp_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Operating Unit in MRP",
"version": "15.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"license": "LGPL-3",
Expand Down
3 changes: 1 addition & 2 deletions mrp_operating_unit/models/mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class MrpProduction(models.Model):
"operating.unit",
"Operating Unit",
readonly=True,
states={"confirmed": [("readonly", False)], "draft": [("readonly", False)]},
default=lambda self: self.env["res.users"].operating_unit_default_get(
default=lambda self: self.env["res.users"]._get_default_operating_unit(
self._uid
),
)
Expand Down
1 change: 1 addition & 0 deletions mrp_operating_unit/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- Nicola Studer \<<[email protected]>\>
- Rujia Liu \<<[email protected]>\>
- Juany Davila \<<[email protected]>\>
- Daniel Lagin \<<[email protected]>\>
30 changes: 16 additions & 14 deletions mrp_operating_unit/tests/test_mrp_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from datetime import datetime

from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo.tests.common import Form
from odoo.tests import common, Form


class TestMrpOperatingUnit(common.TransactionCase):
Expand All @@ -18,34 +17,37 @@ def setUp(self):

# Products
self.product1 = self.env.ref("product.product_product_4c")
# Stock Location
self.stock_location = self.env.ref("stock.stock_location_shop0")

# Main Operating Unit
self.ou1 = self.env.ref("operating_unit.main_operating_unit")
# B2B Operating Unit
self.b2b = self.env.ref("operating_unit.b2b_operating_unit")
# Chicago Operating Unit
self.chicago = self.env.ref("stock_operating_unit.operating_unit_shop0")
# B2C Operating Unit
self.b2c = self.env.ref("operating_unit.b2c_operating_unit")
# Groups
self.grp_mrp_saleman = self.env.ref("sales_team.group_sale_salesman")
self.grp_mrp_manager = self.env.ref("mrp.group_mrp_manager")

# Stock Location
self.b2c_wh = self.env.ref("stock_operating_unit.stock_warehouse_b2c")
self.b2c_location = self.b2c_wh.lot_stock_id
self.b2c_location.operating_unit_id = self.b2c.id

# Users
self.user1 = self._create_user(
"user_1", [self.grp_mrp_saleman], self.company, [self.ou1, self.chicago]
"user_1", [self.grp_mrp_saleman], self.company, [self.ou1, self.b2c]
)
self.user2 = self._create_user(
"user_2",
[self.grp_mrp_saleman, self.grp_mrp_manager],
self.company,
[self.chicago],
[self.b2c],
)

# Manufacturing Orders
self.mrp_record1 = self._create_mrp("Manufacturing Order 1", self.ou1)
self.mrp_record2 = self._create_mrp(
"Manufacturing Order 2", self.chicago, self.stock_location
"Manufacturing Order 2", self.b2c, self.b2c_location
)

def _create_user(self, login, groups, company, operating_units, context=None):
Expand Down Expand Up @@ -94,7 +96,7 @@ def _create_mrp(self, name, operating_unit, stock_location=False):

def test_check_location_operating_unit(self):
with self.assertRaises(ValidationError):
self.mrp_record1.location_src_id = self.stock_location.id
self.mrp_record1.location_src_id = self.b2c_location.id

with self.assertRaises(ValidationError):
self.mrp_record2.operating_unit_id = False
Expand Down Expand Up @@ -127,11 +129,11 @@ def test_onchange_operating_unit_id(self):
[
("company_id", "=", self.mrp_record1.company_id.id),
("code", "=", "mrp_operation"),
("warehouse_id.operating_unit_id", "=", self.b2b.id),
("warehouse_id.operating_unit_id", "=", self.b2c.id),
]
)
with Form(self.mrp_record1) as mrp_form:
mrp_form.operating_unit_id = self.b2b
mrp_form.operating_unit_id = self.b2c
self.assertEqual(new_picking_type_id, mrp_form.picking_type_id)

def test_mrp_ou(self):
Expand All @@ -145,7 +147,7 @@ def test_mrp_ou(self):
with self.assertRaises(ValidationError):
self.mrp_record1.operating_unit_id = False
with self.assertRaises(ValidationError):
self.mrp_record1.write({"operating_unit_id": self.chicago.id})
self.mrp_record1.write({"operating_unit_id": self.b2c.id})

def test_prepare_mo_vals(self):
self.assertIn(
Expand All @@ -154,7 +156,7 @@ def test_prepare_mo_vals(self):
self.env.ref("product.product_product_4"),
0,
self.env.ref("uom.product_uom_unit"),
self.env.ref("stock.stock_location_shop0"),
self.b2c_location,
"test",
False,
self.env.company,
Expand Down
1 change: 1 addition & 0 deletions mrp_operating_unit/views/mrp_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
domain="[('user_ids', 'in', uid)]"
groups="operating_unit.group_multi_operating_unit"
options="{'no_create': True}"
readonly="state not in ['draft', 'confirmed']"
/>
</xpath>
</field>
Expand Down

0 comments on commit 7d87b10

Please sign in to comment.