|
| 1 | +# Copyright 2024 CamptoCamp SA |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 3 | + |
| 4 | +from unittest import mock |
| 5 | + |
| 6 | +from odoo.addons.edi_oca.tests.common import EDIBackendCommonComponentTestCase |
| 7 | + |
| 8 | + |
| 9 | +class TestsPurchaseEDIConfiguration(EDIBackendCommonComponentTestCase): |
| 10 | + @classmethod |
| 11 | + def setUpClass(cls): |
| 12 | + super().setUpClass() |
| 13 | + cls.purchase_order = cls.env["purchase.order"] |
| 14 | + cls.product = cls.env["product.product"].create( |
| 15 | + { |
| 16 | + "name": "Product 1", |
| 17 | + "default_code": "1234567", |
| 18 | + } |
| 19 | + ) |
| 20 | + cls.exc_type_out = cls.env.ref("edi_purchase_oca.demo_edi_exc_type_order_out") |
| 21 | + cls.edi_conf = cls.env.ref("edi_purchase_oca.demo_edi_configuration_confirmed") |
| 22 | + cls.partner.edi_purchase_conf_ids = cls.edi_conf |
| 23 | + |
| 24 | + @mock.patch("odoo.addons.edi_oca.models.edi_backend.EDIBackend._validate_data") |
| 25 | + @mock.patch("odoo.addons.edi_oca.models.edi_backend.EDIBackend._exchange_generate") |
| 26 | + @mock.patch("odoo.addons.edi_oca.models.edi_backend.EDIBackend._exchange_send") |
| 27 | + def test_order_confirm(self, mock_send, mock_generate, mock_validate): |
| 28 | + mock_generate.return_value = "TEST PO OUT" |
| 29 | + order = self.purchase_order.create( |
| 30 | + { |
| 31 | + "partner_id": self.partner.id, |
| 32 | + "order_line": [ |
| 33 | + ( |
| 34 | + 0, |
| 35 | + 0, |
| 36 | + { |
| 37 | + "product_id": self.product.id, |
| 38 | + "product_qty": 10, |
| 39 | + "price_unit": 100.0, |
| 40 | + }, |
| 41 | + ) |
| 42 | + ], |
| 43 | + } |
| 44 | + ) |
| 45 | + self.assertEqual(order.state, "draft") |
| 46 | + self.assertEqual(len(order.exchange_record_ids), 0) |
| 47 | + order.button_confirm() |
| 48 | + self.assertEqual(order.state, "purchase") |
| 49 | + self.assertEqual(len(order.exchange_record_ids), 1) |
| 50 | + self.assertEqual(order.exchange_record_ids[0].type_id, self.exc_type_out) |
| 51 | + self.assertEqual( |
| 52 | + order.exchange_record_ids[0]._get_file_content(), "TEST PO OUT" |
| 53 | + ) |
0 commit comments