Skip to content

Commit

Permalink
[IMP] sale_order_import: warn user when no price is defined in the file
Browse files Browse the repository at this point in the history
  • Loading branch information
thaolt99 committed Nov 22, 2023
1 parent 0801b88 commit 49b51a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions sale_order_import/tests/test_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
from unittest import mock

from odoo import exceptions
from odoo.tests.common import Form

from .common import TestCommon
Expand Down Expand Up @@ -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].pop("price_unit")
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(
Expand Down
10 changes: 9 additions & 1 deletion sale_order_import/wizard/sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49b51a2

Please sign in to comment.