[FIX] product_contract. Correctly create contract from template.

This commit is contained in:
Ronald Portier
2019-05-05 14:49:52 +02:00
parent b6f75686bc
commit 09245d0e0e
8 changed files with 58 additions and 55 deletions

View File

@@ -15,7 +15,7 @@ class TestProductTemplate(TransactionCase):
self.contract = self.env['account.analytic.contract'].create({
'name': 'Test',
'recurring_rule_type': 'yearly',
'recurring_interval': 12345,
'recurring_interval': 1,
})
def test_change_is_contract(self):

View File

@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from mock import MagicMock
# Copyright 2019 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# pylint: disable=missing-docstring,protected-access,invalid-name
from odoo.tests.common import TransactionCase
@@ -15,26 +15,16 @@ class TestSaleOrder(TransactionCase):
self.contract = self.env['account.analytic.contract'].create({
'name': 'Test',
'recurring_rule_type': 'yearly',
'recurring_interval': 12345,
})
'recurring_interval': 1})
self.product.product_tmpl_id.is_contract = True
self.product.product_tmpl_id.contract_template_id = self.contract.id
def tearDown(self):
self.env['account.analytic.account']._revert_method(
'create',
)
super(TestSaleOrder, self).tearDown()
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()
)
def test_action_confirm(self):
"""Contract should be created when sale is confirmed."""
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,
})
contract_model = self.env['account.analytic.account']
product_contract = contract_model.search([
('recurring_invoices', '=', True),
('partner_id', '=', self.sale.partner_id.id),
('contract_template_id', '=', self.contract.id)], limit=1)
self.assertTrue(product_contract)