From 8cbf44ff0a90e8b276d7835c3c820a0caab659d8 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Thu, 21 Mar 2024 14:32:21 +0100 Subject: [PATCH] [FIX] purchase_stock: 'propagate_cancel' check not visible Activate "Reception Report" feature Create a SO for a storable product, confirm. Create a PO for the same product. Confirm the PO and check the delivery, open the "Allocation" report Assign the Product to the delivery of the SO. Go back to the PO and cancel the order, delivery of the SO will be cancelled. Issue: Currently the user cannot modify this behavior as the `propagate_cancel` checkbox is unaccessible opw-3733512 closes odoo/odoo#159940 X-original-commit: c2059c8d2f9d8f6648a577f2dd44360d699f03cf Signed-off-by: Quentin Wolfs (quwo) Signed-off-by: Andrea Grazioso (agr) --- .../tests/test_purchase_delete_order.py | 41 +++++++++++++++++++ .../purchase_stock/views/purchase_views.xml | 3 ++ 2 files changed, 44 insertions(+) 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')