|
4 | 4 |
|
5 | 5 | from unittest import mock
|
6 | 6 |
|
7 |
| -from odoo.tests.common import SavepointCase |
| 7 | +from odoo import fields |
8 | 8 |
|
9 |
| -from odoo.addons.edi_oca.tests.common import EDIBackendTestMixin |
10 |
| - |
11 |
| -from .common import OrderInboundTestMixin, get_xml_handler |
| 9 | +from odoo.addons.edi_oca.tests.common import EDIBackendCommonComponentTestCase |
| 10 | +from odoo.addons.edi_sale_ubl_oca.tests.common import ( |
| 11 | + OrderInboundTestMixin, |
| 12 | + get_xml_handler, |
| 13 | +) |
12 | 14 |
|
13 | 15 | # TODO: split in different tests w/ SingleTransaction
|
14 | 16 |
|
15 | 17 |
|
16 |
| -class TestOrderInboundFull(SavepointCase, EDIBackendTestMixin, OrderInboundTestMixin): |
| 18 | +class TestOrderInboundFull(EDIBackendCommonComponentTestCase, OrderInboundTestMixin): |
17 | 19 |
|
18 | 20 | _schema_path = "base_ubl:data/xsd-2.2/maindoc/UBL-OrderResponse-2.2.xsd"
|
19 | 21 |
|
| 22 | + maxDiff = None |
| 23 | + |
20 | 24 | @classmethod
|
21 | 25 | def setUpClass(cls):
|
22 | 26 | super().setUpClass()
|
23 | 27 | cls._setup_env()
|
24 | 28 | cls.backend = cls._get_backend()
|
25 |
| - cls._setup_inbound_order(cls.backend) |
26 |
| - cls.edi_conf = cls.env.ref("edi_sale_oca.demo_edi_configuration_confirmed") |
| 29 | + cls.exc_type_out = cls.env.ref( |
| 30 | + "edi_sale_ubl_output_oca.demo_edi_sale_ubl_output_so_out" |
| 31 | + ) |
| 32 | + cls.exc_type_in = cls.env.ref( |
| 33 | + "edi_sale_ubl_output_oca.demo_edi_sale_ubl_output_so_in" |
| 34 | + ) |
| 35 | + cls._setup_inbound_order(cls.backend, cls.exc_type_in) |
| 36 | + cls.edi_conf = cls.env.ref( |
| 37 | + "edi_sale_oca.demo_edi_configuration_confirmed" |
| 38 | + ).copy( |
| 39 | + { |
| 40 | + "name": "UBL IN EDI Conf", |
| 41 | + "type_id": cls.exc_type_out.id, |
| 42 | + "backend_id": cls.backend.id, |
| 43 | + } |
| 44 | + ) |
27 | 45 |
|
28 | 46 | @classmethod
|
29 | 47 | def _get_backend(cls):
|
30 | 48 | return cls.env.ref("edi_ubl_oca.edi_backend_ubl_demo")
|
31 | 49 |
|
| 50 | + def _create_order(self): |
| 51 | + # Simulate order creation via incoming EDI exchange |
| 52 | + order = self.env["sale.order"].create( |
| 53 | + { |
| 54 | + "client_order_ref": self.client_order_ref, |
| 55 | + "partner_id": self.order_data.partner.id, |
| 56 | + "origin_exchange_record_id": self.exc_record_in.id, |
| 57 | + "commitment_date": fields.Date.today(), |
| 58 | + } |
| 59 | + ) |
| 60 | + self.exc_record_in._set_related_record(order) |
| 61 | + self.exc_record_in.edi_exchange_state = "input_processed" |
| 62 | + order.invalidate_cache() |
| 63 | + return order |
| 64 | + |
32 | 65 | # No need to test sending data
|
33 | 66 | @mock.patch("odoo.addons.edi_oca.models.edi_backend.EDIBackend._exchange_send")
|
34 | 67 | def test_new_order(self, mock_send):
|
35 |
| - self.backend._check_input_exchange_sync() |
36 |
| - self.assertEqual(self.exc_record_in.edi_exchange_state, "input_processed") |
37 |
| - order = self._find_order() |
| 68 | + order = self._create_order() |
38 | 69 | order.partner_id.edi_sale_conf_ids = self.edi_conf
|
39 |
| - self.assertEqual(self.exc_record_in.record, order) |
40 |
| - order_msg = order.message_ids[0] |
41 |
| - self.assertIn("Exchange processed successfully", order_msg.body) |
42 |
| - self.assertIn(self.exc_record_in.identifier, order_msg.body) |
43 |
| - order.invalidate_cache() |
44 |
| - # Test relations |
45 | 70 | self.assertEqual(len(order.exchange_record_ids), 1)
|
46 |
| - exc_record = order.exchange_record_ids.filtered( |
47 |
| - lambda x: x.type_id == self.exc_type_in |
48 |
| - ) |
49 |
| - self.assertEqual(exc_record, self.exc_record_in) |
50 |
| - # Confirm the order |
51 | 71 | order.action_confirm()
|
52 | 72 | # Should give us a valid order response ack record
|
53 | 73 | ack_exc_record = order.exchange_record_ids.filtered(
|
54 | 74 | lambda x: x.type_id == self.exc_type_out
|
55 | 75 | )
|
56 | 76 | file_content = ack_exc_record._get_file_content()
|
57 |
| - self.assertTrue(file_content) |
58 |
| - # TMP / |
59 |
| - # path = "/tmp/order.response.test.xml" |
60 |
| - # with open(path, "w") as out: |
61 |
| - # out.write(file_content) |
62 |
| - # / TMP |
| 77 | + self.assertEqual(ack_exc_record.edi_exchange_state, "output_sent") |
63 | 78 | handler = get_xml_handler(self.backend, self._schema_path)
|
64 |
| - # Test is a valid file |
65 | 79 | err = handler.validate(file_content)
|
66 | 80 | self.assertEqual(err, None, err)
|
67 |
| - # TODO: test data |
| 81 | + data = handler.parse_xml(file_content) |
| 82 | + # TODO: test all main data |
| 83 | + self.assertEqual(data["cbc:OrderResponseCode"], "AP") |
0 commit comments