Skip to content

Commit

Permalink
[FIX] stock_request: compute_move_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanSForgeFlow committed Jul 16, 2024
1 parent ac698ec commit 27228d6
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 1 deletion.
13 changes: 12 additions & 1 deletion stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,21 @@ def _get_expected_date():
("name_uniq", "unique(name, company_id)", "Stock Request name must be unique")
]

def _get_all_origin_moves(self, move):
all_moves = move
if move.move_orig_ids:
for orig_move in move.move_orig_ids:
all_moves |= self._get_all_origin_moves(orig_move)
return all_moves

@api.depends("allocation_ids", "allocation_ids.stock_move_id")
def _compute_move_ids(self):
for request in self:
request.move_ids = request.allocation_ids.mapped("stock_move_id")
move_ids = request.allocation_ids.mapped("stock_move_id")
all_moves = self.env["stock.move"]
for move in move_ids:
all_moves |= self._get_all_origin_moves(move)
request.move_ids = all_moves

@api.depends(
"allocation_ids",
Expand Down
140 changes: 140 additions & 0 deletions stock_request/tests/test_stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,3 +1543,143 @@ def test_onchange_route_id_propagation(self):
self.route.id,
"Route ID should update on all stock requests on onchange.",
)


class TestStockRequestOrderChainedTransfers(BaseCommon):
def setUp(self):
super().setUp()
self.env = self.env(
context=dict(
self.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
self.request_order = self.env["stock.request.order"]
self.stock_request = self.env["stock.request"]
self.main_company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0")
self.uom_unit = self.env.ref("uom.product_uom_unit")
self.uom_dozen = self.env.ref("uom.product_uom_dozen")
self.stock_request_user = new_test_user(
self.env,
login="stock_request_user",
groups="stock_request.group_stock_request_user",
company_ids=[(6, 0, [self.main_company.id])],
)
self.stock_request_manager = new_test_user(
self.env,
login="stock_request_manager",
groups="stock_request.group_stock_request_manager",
company_ids=[(6, 0, [self.main_company.id])],
)
self.product_test = self._create_product("PROD", "Product Test")
self.stock_loc = self._create_location(
name="Backstock",
location_id=self.warehouse.view_location_id.id,
company_id=self.main_company.id,
)
self.transit_loc = self._create_location(
name="Transit",
location_id=self.warehouse.view_location_id.id,
company_id=self.main_company.id,
)
self.manufacturing_loc = self._create_location(
name="Manufacturing",
location_id=self.warehouse.view_location_id.id,
company_id=self.main_company.id,
)
self.route = self.env["stock.route"].create(
{
"name": "Backstock to Manufacturing (2 steps)",
"warehouse_selectable": True,
"warehouse_ids": [(6, 0, [self.warehouse.id])],
"rule_ids": [
(
0,
False,
{
"name": "Stock to Transit",
"location_src_id": self.stock_loc.id,
"location_dest_id": self.transit_loc.id,
"action": "pull",
"picking_type_id": self.warehouse.int_type_id.id,
"procure_method": "make_to_stock",
"warehouse_id": self.warehouse.id,
"company_id": self.main_company.id,
},
),
(
0,
False,
{
"name": "Transit to Manufacturing",
"location_src_id": self.transit_loc.id,
"location_dest_id": self.manufacturing_loc.id,
"action": "pull_push",
"picking_type_id": self.warehouse.int_type_id.id,
"procure_method": "make_to_order",
"warehouse_id": self.warehouse.id,
"company_id": self.main_company.id,
},
),
],
}
)
self.product_test.route_ids = [(6, 0, [self.route.id])]
self._create_stock_quant(self.stock_loc, self.product_test, 5)

def _create_product(self, default_code, name, **vals):
return self.env["product.product"].create(
dict(
name=name,
default_code=default_code,
uom_id=self.uom_unit.id,
uom_po_id=self.uom_dozen.id,
type="product",
**vals
)
)

def _create_location(self, **vals):
return self.env["stock.location"].create(dict(usage="internal", **vals))

def _create_stock_quant(self, location_id, product_id, qty):
self.env["stock.quant"].create(
{
"location_id": location_id.id,
"product_id": product_id.id,
"quantity": qty,
}
)

def test_two_pickings_related(self):
"""Test to check that order has two related pickings after confirmation"""
expected_date = fields.Datetime.now()
vals = {
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.manufacturing_loc.id,
"expected_date": expected_date,
"stock_request_ids": [
(
0,
0,
{
"product_id": self.product_test.id,
"product_uom_id": self.product_test.uom_id.id,
"product_uom_qty": 5.0,
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.manufacturing_loc.id,
"expected_date": expected_date,
},
)
],
}
order = self.request_order.with_user(self.stock_request_user).create(vals)
order.with_user(self.stock_request_manager).action_confirm()
self.assertEqual(len(order.mapped("picking_ids")), 2)

0 comments on commit 27228d6

Please sign in to comment.