From 984c5aa0817a8ae304ae985b65bebb9671ccda21 Mon Sep 17 00:00:00 2001 From: thaolt Date: Tue, 31 Oct 2023 16:28:58 +0700 Subject: [PATCH] [IMP] sale_order_import: warn user when no price is defined in the file --- sale_order_import/tests/test_order_import.py | 20 +++++++++++++++++++ sale_order_import/wizard/sale_order_import.py | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sale_order_import/tests/test_order_import.py b/sale_order_import/tests/test_order_import.py index f95b53264fd..7c5578791d0 100644 --- a/sale_order_import/tests/test_order_import.py +++ b/sale_order_import/tests/test_order_import.py @@ -6,6 +6,7 @@ import base64 from unittest import mock +from odoo import exceptions from odoo.tests.common import Form from .common import TestCommon @@ -64,6 +65,25 @@ def test_order_import(self): self.assertEqual(len(order.order_line), 2) self.assertEqual(int(order.order_line[0].product_uom_qty), 3) + def test_order_import_without_price(self): + test_data = self.parsed_order.copy() + test_data["doc_type"] = "order" + test_data["price_source"] = "order" + test_data["lines"][0]["price_unit"] = None + order = self.wiz_model.create_order(test_data, "pricelist") + self.assertEqual(order.client_order_ref, test_data["order_ref"]) + self.assertEqual( + order.order_line[0].product_id.default_code, + test_data["lines"][0]["product"]["code"], + ) + self.assertEqual(int(order.order_line[0].product_uom_qty), 2) + expected_msg = ( + "No price is defined in the file. Please double check " + "file or select Pricelist as the source for prices." + ) + with self.assertRaisesRegex(exceptions.UserError, expected_msg): + self.wiz_model.update_order_lines(test_data, "order", "order") + def test_order_import_default_so_vals(self): default = {"client_order_ref": "OVERRIDE"} order = self.wiz_model.with_context( diff --git a/sale_order_import/wizard/sale_order_import.py b/sale_order_import/wizard/sale_order_import.py index 12ab03d660d..11922442046 100644 --- a/sale_order_import/wizard/sale_order_import.py +++ b/sale_order_import/wizard/sale_order_import.py @@ -467,8 +467,16 @@ def _prepare_create_order_line( "company_id": company_id, } ) + if price_source == "order": - vals["price_unit"] = import_line["price_unit"] # TODO : fix + if "price_unit" not in import_line: + raise UserError( + _( + "No price is defined in the file. Please double check " + "file or select Pricelist as the source for prices." + ) + ) + vals["price_unit"] = import_line["price_unit"] elif price_source == "pricelist": # product_id_change is played in the inherit of create() # of sale.order.line cf odoo/addons/sale/models/sale.py