mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -125,10 +125,21 @@ class StockRequest(models.Model):
|
||||
("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",
|
||||
|
||||
@@ -1562,3 +1562,143 @@ class TestStockRequestOrderState(TestStockRequest):
|
||||
self.route.id,
|
||||
"Route ID should update on all stock requests on onchange.",
|
||||
)
|
||||
|
||||
|
||||
class TestStockRequestOrder(common.TransactionCase):
|
||||
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.location.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_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_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)
|
||||
|
||||
Reference in New Issue
Block a user