You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from mock import MagicMock
  5. from odoo.tests.common import TransactionCase
  6. class TestSaleOrder(TransactionCase):
  7. def setUp(self):
  8. super(TestSaleOrder, self).setUp()
  9. self.product = self.env.ref('product.product_product_1')
  10. self.sale = self.env.ref('sale.sale_order_2')
  11. self.contract = self.env['account.analytic.contract'].create({
  12. 'name': 'Test',
  13. 'recurring_rule_type': 'yearly',
  14. 'recurring_interval': 12345,
  15. })
  16. self.product.product_tmpl_id.is_contract = True
  17. self.product.product_tmpl_id.contract_template_id = self.contract.id
  18. def tearDown(self):
  19. self.env['account.analytic.account']._revert_method(
  20. 'create',
  21. )
  22. super(TestSaleOrder, self).tearDown()
  23. def test_action_done(self):
  24. """ It should create a contract when the sale for a contract is set
  25. to done for the first time """
  26. self.env['account.analytic.account']._patch_method(
  27. 'create', MagicMock()
  28. )
  29. self.sale.action_confirm()
  30. self.env['account.analytic.account'].create.assert_called_once_with({
  31. 'name': '%s Contract' % self.sale.name,
  32. 'partner_id': self.sale.partner_id.id,
  33. 'contract_template_id': self.contract.id,
  34. })