From 686723f78d1082881e5ed01861b8fb01a8a6f144 Mon Sep 17 00:00:00 2001 From: duongtq Date: Wed, 25 Oct 2023 11:43:38 +0700 Subject: [PATCH] [IMP] sale_order_import: add confirm_order flag to wizard When the flag is enabled, the order will be automatically confirmed. Mostly used when the wizard is used as a tool to import orders. --- sale_order_import/tests/test_order_import.py | 27 +++++++++++++++++++ sale_order_import/wizard/sale_order_import.py | 5 ++++ 2 files changed, 32 insertions(+) diff --git a/sale_order_import/tests/test_order_import.py b/sale_order_import/tests/test_order_import.py index 30ae34156e..f95b53264f 100644 --- a/sale_order_import/tests/test_order_import.py +++ b/sale_order_import/tests/test_order_import.py @@ -145,3 +145,30 @@ def test_with_order_buttons(self): self.assertEqual(len(so.order_line), 2) self.assertEqual(so.order_line[0].product_uom_qty, 3) + + def test_confirm_order(self): + # Prepare test data + order_file_data = base64.b64encode( + b"baz" + ) + order_filename = "test_order.xml" + mock_parse_order = mock.patch.object(type(self.wiz_model), "parse_xml_order") + # Create a new form + with Form( + self.wiz_model.with_context( + default_order_filename=order_filename, + default_confirm_order=True, + ) + ) as form: + with mock_parse_order as mocked: + # Return 'rfq' for doc_type + mocked.return_value = "rfq" + # Set values for the required fields + form.import_type = "xml" + form.order_file = order_file_data + # Test the button with the simulated values + mocked.return_value = self.parsed_order + action = form.save().import_order_button() + so = self.env["sale.order"].browse(action["res_id"]) + # Check the state of the order + self.assertEqual(so.state, "sale") diff --git a/sale_order_import/wizard/sale_order_import.py b/sale_order_import/wizard/sale_order_import.py index 583f2b360b..12ab03d660 100644 --- a/sale_order_import/wizard/sale_order_import.py +++ b/sale_order_import/wizard/sale_order_import.py @@ -56,6 +56,8 @@ class SaleOrderImport(models.TransientModel): "res.partner", string="Shipping Address", readonly=True ) sale_id = fields.Many2one("sale.order", string="Quotation to Update") + # Confirm order after creating Sale Order + confirm_order = fields.Boolean(default=False) @api.onchange("order_file") def order_file_change(self): @@ -320,6 +322,9 @@ def create_order(self, parsed_order, price_source, order_filename=None): order = soo.create(so_vals) bdio.post_create_or_update(parsed_order, order, doc_filename=order_filename) logger.info("Sale Order ID %d created", order.id) + if self.confirm_order: + order.action_confirm() + logger.info("Sale Order ID %d confirmed", order.id) return order @api.model