Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][FWP][FIX] stock_request: compute_move_ids #37

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,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 @@ -1568,3 +1568,143 @@ def test_onchange_route_id_propagation(self):
self.route.id,
"Route ID should update on all stock requests on onchange.",
)


class TestStockRequestOrderChainedTransfers(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.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)
Loading