From b408f986113e98d9a1d0a65b7316ebfb6d3e5c55 Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Tue, 1 Oct 2019 15:02:05 +0200 Subject: [PATCH] [ADD] Contract Sale Mandate: unit test --- contract_sale_mandate/tests/__init__.py | 1 + .../tests/test_contract_sale_mandate.py | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 contract_sale_mandate/tests/__init__.py create mode 100644 contract_sale_mandate/tests/test_contract_sale_mandate.py diff --git a/contract_sale_mandate/tests/__init__.py b/contract_sale_mandate/tests/__init__.py new file mode 100644 index 00000000..4e4986a6 --- /dev/null +++ b/contract_sale_mandate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract_sale_mandate diff --git a/contract_sale_mandate/tests/test_contract_sale_mandate.py b/contract_sale_mandate/tests/test_contract_sale_mandate.py new file mode 100644 index 00000000..eb36adcd --- /dev/null +++ b/contract_sale_mandate/tests/test_contract_sale_mandate.py @@ -0,0 +1,52 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase + + +class TestContractSaleMandate(TestContractBase): + @classmethod + def setUpClass(cls): + super(TestContractSaleMandate, cls).setUpClass() + cls.partner_bank = cls.env['res.partner.bank'].create({ + 'acc_number': '1234', + 'partner_id': cls.partner.id, + }) + cls.mandate = cls.env['account.banking.mandate'].create({ + 'partner_id': cls.partner.id, + 'partner_bank_id': cls.partner_bank.id, + 'signature_date': '2017-01-01', + }) + cls.product1 = cls.env.ref('product.product_product_1') + cls.contract_template1 = cls.env['contract.template'].create( + {'name': 'Template 1'} + ) + cls.product1.write( + { + 'is_contract': True, + 'default_qty': 12, + 'recurring_rule_type': "monthlylastday", + 'contract_template_id': cls.contract_template1.id, + } + ) + cls.sale = cls.env.ref('sale.sale_order_2') + cls.sale.mandate_id = cls.mandate + cls.order_line1 = cls.sale.order_line.filtered( + lambda l: l.product_id == cls.product1 + ) + + def test_01(self): + """ + Data: + - A sale order with a mandate + Test case: + - Confirm the sale order + Expected result: + - The mandate of the sale order is copied on the generated + contract + """ + self.order_line1.onchange_product() + self.sale.action_confirm() + contracts = self.sale.order_line.mapped('contract_id') + self.assertEqual(len(contracts), 1) + self.assertEqual(contracts[0].mandate_id, self.mandate)