Skip to content

Commit

Permalink
[MIG][15.0] stock_request_cancel_confirm:Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Sep 27, 2024
1 parent 2bd66ef commit f31780d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stock_request_cancel_confirm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Stock Request Cancel Confirm",
"version": "14.0.1.0.1",
"version": "15.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"category": "Usability",
"license": "AGPL-3",
Expand Down
1 change: 1 addition & 0 deletions stock_request_cancel_confirm/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_request
117 changes: 117 additions & 0 deletions stock_request_cancel_confirm/tests/test_stock_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from odoo.tests.common import TransactionCase


class TestStockRequest(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestStockRequest, cls).setUpClass()
# Create a Unit of Measure (UoM) for the product
cls.unit_of_measure = cls.env.ref("uom.product_uom_unit").id

# Create a test product with UoM fields
cls.test_product = cls.env["product.product"].create(
{
"name": "Test Product",
"type": "product",
"uom_id": cls.unit_of_measure,
"uom_po_id": cls.unit_of_measure,
}
)

# Define stock request and stock request order models for easier access
cls.StockRequest = cls.env["stock.request"]

# Create a stock request with required fields
cls.stock_request = cls.StockRequest.create(
{
"name": "Test Stock Request 1",
"product_id": cls.test_product.id,
"product_uom_id": cls.unit_of_measure,
"product_uom_qty": 10,
}
)

# Create a stock request order.
cls.stock_request_order = cls.env["stock.request.order"].create(
{
"name": "Test Stock Request Order",
"stock_request_ids": [0, 0, cls.stock_request.id],
}
)

def test_01_stock_request_cancel_request_with_and_without_confirmation(self):
"""
Test cancelling stock requests with and without the confirmation wizard.
"""
# Test cancel with confirmation enabled
self.stock_request_order.cancel_confirm = True
stock_request_cancel = self.stock_request.action_cancel()

self.assertEqual(
stock_request_cancel,
True,
"Stock request should be cancelled directly when confirmation is enabled.",
)
self.assertEqual(
self.stock_request.state,
"cancel",
"Stock request state should be 'cancel' when cancellation is confirmed.",
)

# Reset to draft and test cancel without confirmation
self.stock_request.action_draft()
self.stock_request_order.cancel_confirm = False
stock_request_draft = self.stock_request.action_cancel()

self.assertEqual(
stock_request_draft.get("res_model"),
"cancel.confirm",
"Cancel confirmation wizard should be shown when confirmation is disabled.",
)
self.assertEqual(
self.stock_request.state,
"draft",
"Stock request state should remain 'draft' when cancellation is pending "
"confirmation.",
)

def test_02_stock_request_order_cancel_request_with_and_without_confirmation(self):
"""
Test resetting stock request and stock request order to draft, and ensure
the cancel confirmation flag is respected.
"""

# Test draft with confirmation enabled
self.stock_request_order.cancel_confirm = True
stock_request_cancel = self.stock_request_order.action_cancel()

self.assertEqual(
stock_request_cancel,
True,
"Stock request order should be cancelled directly when confirmation "
"is enabled.",
)
self.assertEqual(
self.stock_request_order.state,
"cancel",
"Stock request order state should be 'draft' after cancellation with "
"confirmation.",
)

# Reset to draft and test cancel without confirmation
self.stock_request_order.action_draft()
self.stock_request_order.cancel_confirm = False
stock_request_draft = self.stock_request_order.action_cancel()

self.assertEqual(
stock_request_draft.get("res_model"),
"cancel.confirm",
"Cancel confirmation wizard should appear when confirmation is disabled "
"for stock request order.",
)
self.assertEqual(
self.stock_request_order.state,
"draft",
"Stock request order state should remain 'draft' when cancellation is "
"pending confirmation.",
)

0 comments on commit f31780d

Please sign in to comment.