Skip to content

Commit

Permalink
[IMP] sale_order_import: Add tests for create/update order button
Browse files Browse the repository at this point in the history
  • Loading branch information
duongtq committed Oct 11, 2023
1 parent 9e50719 commit 470e4fb
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
80 changes: 80 additions & 0 deletions sale_order_import/tests/test_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
from unittest import mock

from odoo.tests.common import Form

from .common import TestCommon


Expand Down Expand Up @@ -65,3 +70,78 @@ def test_order_import_default_so_vals(self):
sale_order_import__default_vals=dict(order=default)
).create_order(self.parsed_order, "pricelist")
self.assertEqual(order.client_order_ref, "OVERRIDE")

def test_with_order_buttons(self):
# Prepare test data
order_file_data = base64.b64encode(
b"<?xml version='1.0' encoding='utf-8'?><root><foo>baz</foo></root>"
)
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,
)
) 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
mocked.assert_called()
# Test the button with the simulated values
mocked.return_value = self.parsed_order
action = form.save().import_order_button()
self.assertEqual(action["xml_id"], "sale.action_quotations")
self.assertEqual(action["view_mode"], "form,tree,calendar,graph")
self.assertEqual(action["view_id"], False)
mocked.assert_called()
so = self.env["sale.order"].browse(action["res_id"])
self.assertEqual(so.partner_id.email, "[email protected]")
self.assertEqual(so.client_order_ref, "TEST1242")
self.assertEqual(so.order_line.product_id.code, "FURN_8888")
self.assertEqual(so.state, "draft")

# Create another form to update the above sale order
with Form(
self.wiz_model.with_context(
default_order_filename=order_filename,
)
) as form:
with mock_parse_order as mocked:
# Return 'rfq' for doc_type
mocked.return_value = "rfq"
# Set the required fields
form.import_type = "xml"
form.order_file = order_file_data
parsed_order_up = dict(
self.parsed_order,
lines=[
{
"product": {"code": "FURN_8888"},
"qty": 3,
"uom": {"unece_code": "C62"},
"price_unit": 12.42,
},
{
"product": {"code": "FURN_9999"},
"qty": 1,
"uom": {"unece_code": "C62"},
"price_unit": 1.42,
},
],
)
mocked.return_value = parsed_order_up
action = form.save().import_order_button()
form = form.save()
self.assertEqual(
action["xml_id"], "sale_order_import.sale_order_import_action"
)
self.assertEqual(form.state, "update")
self.assertEqual(form.sale_id, so)
form.update_order_button()

self.assertEqual(len(so.order_line), 2)
self.assertEqual(so.order_line[0].product_uom_qty, 3)
4 changes: 0 additions & 4 deletions sale_order_import/wizard/sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ def parse_order(self, order_file, order_filename, partner=False):
)
return parsed_order

# TODO: add tests
def import_order_button(self):
self.ensure_one()
bdio = self.env["business.document.import"]
Expand Down Expand Up @@ -406,7 +405,6 @@ def create_order_button(self):
)
return self.create_order_return_action(parsed_order, self.order_filename)

Check warning on line 406 in sale_order_import/wizard/sale_order_import.py

View check run for this annotation

Codecov / codecov/patch

sale_order_import/wizard/sale_order_import.py#L406

Added line #L406 was not covered by tests

# TODO: add tests
def create_order_return_action(self, parsed_order, order_filename):
self.ensure_one()
order = self.create_order(parsed_order, self.price_source, order_filename)
Expand Down Expand Up @@ -443,7 +441,6 @@ def _prepare_update_order_vals(self, parsed_order, order, partner):
vals["client_order_ref"] = parsed_order["order_ref"]
return vals

# TODO: add tests
@api.model
def _prepare_create_order_line(
self, product, uom, order, import_line, price_source
Expand Down Expand Up @@ -612,7 +609,6 @@ def _prepare_update_order_line_vals(self, change_dict):
# Allows other module to update some fields on the line
return {}

# TODO: add tests
def update_order_button(self):
self.ensure_one()
bdio = self.env["business.document.import"]
Expand Down

0 comments on commit 470e4fb

Please sign in to comment.