diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 7ca4c099904..efe7e398c59 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -2,7 +2,7 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from mock import MagicMock +import mock from odoo.tests.common import TransactionCase @@ -23,12 +23,11 @@ def setUp(self): def test_action_done(self): """ It should create a contract when the sale for a contract is set to done for the first time """ - self.env['account.analytic.account']._patch_method( - 'create', MagicMock() - ) - self.sale.action_confirm() - self.env['account.analytic.account'].create.assert_called_once_with({ - 'name': '%s Contract' % self.sale.name, - 'partner_id': self.sale.partner_id.id, - 'contract_template_id': self.contract.id, - }) + Model = self.env['account.analytic.account'] + with mock.patch.object(Model, 'create'): + self.sale.action_confirm() + Model.create.assert_called_once_with({ + 'name': '%s Contract' % self.sale.name, + 'partner_id': self.sale.partner_id.id, + 'contract_template_id': self.contract.id, + })