Skip to content

Commit

Permalink
[MIG] stock_operating_unit: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidderen-nsi committed May 29, 2024
1 parent 27695c8 commit d50283c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 76 deletions.
2 changes: 1 addition & 1 deletion stock_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Stock with Operating Units",
"summary": "Adds the concept of operating unit (OU) in stock management",
"version": "16.0.1.2.1",
"version": "17.0.1.0.0",
"category": "Generic Modules/Sales & Purchases",
"author": "ForgeFlow, "
"Serpent Consulting Services Pvt. Ltd., "
Expand Down
6 changes: 0 additions & 6 deletions stock_operating_unit/model/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ def _check_warehouse_operating_unit(self):
@api.constrains("operating_unit_id")
def _check_required_operating_unit(self):
for rec in self:
if rec.usage not in ("supplier", "customer") and not rec.operating_unit_id:
raise UserError(
_(
"Configuration error. Internal locations should have an operating unit"
)
)
if rec.usage in ("supplier", "customer") and rec.operating_unit_id:
raise UserError(
_(
Expand Down
17 changes: 9 additions & 8 deletions stock_operating_unit/model/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ class StockPicking(models.Model):
operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Requesting Operating Unit",
readonly=True,
states={"draft": [("readonly", False)]},
readonly=False,
compute="_compute_operating_unit_id",
store=True,
)

@api.onchange("picking_type_id", "partner_id")
def _onchange_picking_type(self):
res = super()._onchange_picking_type()
if self.picking_type_id:
self.operating_unit_id = self.picking_type_id.warehouse_id.operating_unit_id
return res
@api.depends("picking_type_id")
def _compute_operating_unit_id(self):
for picking in self:
if picking.picking_type_id:
warehouse = picking.picking_type_id.warehouse_id
picking.operating_unit_id = warehouse.operating_unit_id

@api.constrains("operating_unit_id", "company_id")
def _check_company_operating_unit(self):
Expand Down
20 changes: 10 additions & 10 deletions stock_operating_unit/security/stock_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="model_id" ref="stock.model_stock_warehouse" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
('operating_unit_id', 'in', operating_unit_ids)]
</field>
<field name="name">Warehouses from allowed operating units</field>
<field name="global" eval="True" />
Expand All @@ -22,7 +22,7 @@
('warehouse_id','=',False),
'|',
('warehouse_id.operating_unit_id','=', False),
('warehouse_id.operating_unit_id','in',user.operating_unit_ids.ids)]
('warehouse_id.operating_unit_id','in',operating_unit_ids)]
</field>
<field name="name">Stock Picking Type from allowed operating units</field>
<field name="global" eval="True" />
Expand All @@ -34,7 +34,7 @@
<record id="ir_rule_stock_location_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_location" />
<field name="domain_force">['|',
('operating_unit_id', 'in',user.operating_unit_ids.ids),
('operating_unit_id', 'in',operating_unit_ids),
('operating_unit_id','=',False)]
</field>
<field name="name">Stock locations from allowed operating units</field>
Expand All @@ -48,10 +48,10 @@
<field name="model_id" ref="stock.model_stock_move" />
<field name="domain_force">['|',
('location_id.operating_unit_id','=',False),
('location_id.operating_unit_id','in',user.operating_unit_ids.ids),
('location_id.operating_unit_id','in',operating_unit_ids),
'|',
('location_dest_id.operating_unit_id','=',False),
('location_dest_id.operating_unit_id','in',user.operating_unit_ids.ids)]
('location_dest_id.operating_unit_id','in',operating_unit_ids)]
</field>
<field name="name">Stock moves from allowed operating units</field>
<field name="global" eval="True" />
Expand All @@ -64,10 +64,10 @@
<field name="model_id" ref="stock.model_stock_move_line" />
<field name="domain_force">['|',
('location_id.operating_unit_id','=',False),
('location_id.operating_unit_id','in',user.operating_unit_ids.ids),
('location_id.operating_unit_id','in',operating_unit_ids),
'|',
('location_dest_id.operating_unit_id','=',False),
('location_dest_id.operating_unit_id','in',user.operating_unit_ids.ids)]
('location_dest_id.operating_unit_id','in',operating_unit_ids)]
</field>
<field name="name">Product moves from allowed operating units</field>
<field name="global" eval="True" />
Expand All @@ -80,7 +80,7 @@
<field name="model_id" ref="stock.model_stock_picking" />
<field name="domain_force">['|',
('operating_unit_id','=',False),
('operating_unit_id','in',user.operating_unit_ids.ids)]
('operating_unit_id','in',operating_unit_ids)]
</field>
<field name="name">Stock pickings from allowed operating units</field>
<field name="global" eval="True" />
Expand All @@ -97,7 +97,7 @@
<field name="domain_force">['|','|',
('picking_type_id.warehouse_id','=', False),
('picking_type_id.warehouse_id.operating_unit_id','=',False),
('picking_type_id.warehouse_id.operating_unit_id','in',user.operating_unit_ids.ids)]
('picking_type_id.warehouse_id.operating_unit_id','in',operating_unit_ids)]
</field>
<field name="name">Stock pickings from allowed picking types</field>
<field name="global" eval="True" />
Expand All @@ -110,7 +110,7 @@
<field name="model_id" ref="stock.model_stock_quant" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
('operating_unit_id', 'in', operating_unit_ids)]
</field>
<field name="name">Quants from allowed operating units</field>
<field name="global" eval="True" />
Expand Down
99 changes: 51 additions & 48 deletions stock_operating_unit/tests/test_stock_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,69 @@


class TestStockOperatingUnit(common.TestStockCommon):
def setUp(self):
super(TestStockOperatingUnit, self).setUp()
self.ResUsers = self.env["res.users"]
self.WarehouseObj = self.env["stock.warehouse"]
self.LocationObj = self.env["stock.location"]
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ResUsers = cls.env["res.users"]
cls.WarehouseObj = cls.env["stock.warehouse"]
cls.LocationObj = cls.env["stock.location"]
# company
self.company1 = self.env.ref("base.main_company")
cls.company1 = cls.env.ref("base.main_company")
# groups
self.group_stock_manager = self.env.ref("stock.group_stock_manager")
cls.group_stock_manager = cls.env.ref("stock.group_stock_manager")
# 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")
# Products
self.product1 = self.env.ref("product.product_product_7")
self.product2 = self.env.ref("product.product_product_9")
self.product3 = self.env.ref("product.product_product_11")
cls.product1 = cls.env.ref("product.product_product_7")
cls.product2 = cls.env.ref("product.product_product_9")
cls.product3 = cls.env.ref("product.product_product_11")
# Locations
b2c_wh = self.env.ref("stock_operating_unit.stock_warehouse_b2c")
b2c_wh.lot_stock_id.write({"operating_unit_id": self.b2c.id})
self.location_b2c_id = b2c_wh.lot_stock_id.id
self.b2c_type_in_id = b2c_wh.in_type_id.id
self.b2c_type_int_id = b2c_wh.int_type_id.id
b2c_wh = cls.env.ref("stock_operating_unit.stock_warehouse_b2c")
b2c_wh.lot_stock_id.write({"operating_unit_id": cls.b2c.id})
cls.location_b2c_id = b2c_wh.lot_stock_id.id
cls.b2c_type_in_id = b2c_wh.in_type_id.id
cls.b2c_type_int_id = b2c_wh.int_type_id.id
# Create users
self.user1_id = self._create_user(
cls.user1_id = cls._create_user(
"stock_user_1",
[self.group_stock_manager],
self.company1,
[self.ou1, self.b2c],
[cls.group_stock_manager],
cls.company1,
[cls.ou1, cls.b2c],
)
self.user2_id = self._create_user(
"stock_user_2", [self.group_stock_manager], self.company1, [self.b2c]
cls.user2_id = cls._create_user(
"stock_user_2", [cls.group_stock_manager], cls.company1, [cls.b2c]
)
# Create Incoming Shipments
self.picking_in1 = self._create_picking(
self.user1_id,
self.b2c.id,
self.b2c_type_in_id,
self.supplier_location,
self.stock_location,
cls.picking_in1 = cls._create_picking(
cls.user1_id,
cls.b2c.id,
cls.b2c_type_in_id,
cls.supplier_location,
cls.stock_location,
)
self.picking_in2 = self._create_picking(
self.user2_id,
self.b2c.id,
self.b2c_type_in_id,
self.supplier_location,
self.location_b2c_id,
cls.picking_in2 = cls._create_picking(
cls.user2_id,
cls.b2c.id,
cls.b2c_type_in_id,
cls.supplier_location,
cls.location_b2c_id,
)
# Create Internal Shipment
self.picking_int = self._create_picking(
self.user1_id,
self.b2c.id,
self.b2c_type_int_id,
self.stock_location,
self.location_b2c_id,
cls.picking_int = cls._create_picking(
cls.user1_id,
cls.b2c.id,
cls.b2c_type_int_id,
cls.stock_location,
cls.location_b2c_id,
)

def _create_user(self, login, groups, company, operating_units):
@classmethod
def _create_user(cls, login, groups, company, operating_units):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.ResUsers.with_context(**{"no_reset_password": True}).create(
user = cls.ResUsers.with_context(**{"no_reset_password": True}).create(
{
"name": "Stock User",
"login": login,
Expand All @@ -79,22 +81,23 @@ def _create_user(self, login, groups, company, operating_units):
)
return user.id

def _create_picking(self, user_id, ou_id, picking_type, src_loc_id, dest_loc_id):
@classmethod
def _create_picking(cls, user_id, ou_id, picking_type, src_loc_id, dest_loc_id):
"""Create a Picking."""
picking = self.PickingObj.with_user(user_id).create(
picking = cls.PickingObj.with_user(user_id).create(
{
"picking_type_id": picking_type,
"location_id": src_loc_id,
"location_dest_id": dest_loc_id,
"operating_unit_id": ou_id,
}
)
self.MoveObj.with_user(user_id).create(
cls.MoveObj.with_user(user_id).create(
{
"name": "a move",
"product_id": self.productA.id,
"product_id": cls.productA.id,
"product_uom_qty": 3.0,
"product_uom": self.productA.uom_id.id,
"product_uom": cls.productA.uom_id.id,
"picking_id": picking.id,
"location_id": src_loc_id,
"location_dest_id": dest_loc_id,
Expand Down
4 changes: 1 addition & 3 deletions stock_operating_unit/view/stock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<field
name="operating_unit_id"
options="{'no_create': True}"
domain="[('company_id','=', company_id)]"
groups="operating_unit.group_multi_operating_unit"
/>
</field>
Expand Down Expand Up @@ -43,7 +42,6 @@
<field
name="operating_unit_id"
options="{'no_create': True}"
domain="[('company_id','=', company_id)]"
groups="operating_unit.group_multi_operating_unit"
/>
</xpath>
Expand Down Expand Up @@ -100,8 +98,8 @@
<field
name="operating_unit_id"
options="{'no_create': True}"
domain="[('company_id','=', company_id)]"
groups="operating_unit.group_multi_operating_unit"
readonly="state == 'draft'"
/>
</xpath>
</field>
Expand Down

0 comments on commit d50283c

Please sign in to comment.