diff --git a/addons/purchase_stock/tests/test_purchase_delete_order.py b/addons/purchase_stock/tests/test_purchase_delete_order.py index 0687e76d187..2ae15f0d6ce 100644 --- a/addons/purchase_stock/tests/test_purchase_delete_order.py +++ b/addons/purchase_stock/tests/test_purchase_delete_order.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.exceptions import UserError +from odoo.fields import Command from .common import PurchaseTestCommon @@ -40,3 +41,43 @@ class TestDeleteOrder(PurchaseTestCommon): purchase_order_3.button_cancel() self.assertEqual(purchase_order_3.state, 'cancel', 'PO is cancelled!') purchase_order_3.unlink() + + def test_01_delete_propagation(self): + ''' Testcase for deleting purchase order with linked move and propagate cancel off''' + + partner = self.env['res.partner'].create({'name': 'My Partner'}) + + stock_location = self.env.ref('stock.warehouse0').out_type_id.default_location_src_id + cust_location = self.env.ref('stock.stock_location_customers') + picking_type_out = self.ref('stock.picking_type_out') + move = self.env['stock.move'].create({ + 'name': self.product_2.name, + 'product_id': self.product_2.id, + 'product_uom_qty': 1, + 'product_uom': self.product_2.uom_id.id, + 'location_id': stock_location.id, + 'location_dest_id': cust_location.id, + 'picking_type_id': picking_type_out, + }) + move._action_confirm() + self.assertEqual(move.state, 'confirmed', 'Move should be confirmed as there is no quantity in stock') + + purchase_order = self.env['purchase.order'].create({ + 'partner_id': partner.id, + 'order_line': [ + Command.create({ + 'product_id': self.product_2.id, + 'product_qty': 1.0, + 'product_uom': self.product_2.uom_id.id, + 'propagate_cancel': False, + })], + }) + purchase_order.button_confirm() + + self.env['report.stock.report_reception'].action_assign(move.ids, [1], purchase_order.order_line.move_ids.ids) + self.assertEqual(move.state, 'waiting', 'Move should be waiting for the linked purchase') + purchase_order.button_cancel() + # Check purchase order and related move are canceled while linked move state is not + self.assertEqual(purchase_order.state, 'cancel', 'Purchase Order should be canceled') + self.assertEqual(purchase_order.order_line.move_ids.state, 'cancel', 'Purchase order move should be canceled') + self.assertEqual(move.state, 'confirmed', 'Move state should be recomputed to confimed') diff --git a/addons/purchase_stock/views/purchase_views.xml b/addons/purchase_stock/views/purchase_views.xml index 4878d4ccd7c..9509508ef79 100644 --- a/addons/purchase_stock/views/purchase_views.xml +++ b/addons/purchase_stock/views/purchase_views.xml @@ -58,6 +58,9 @@ + + + parent.state not in ('purchase', 'done') product_type in ('consu', 'product')