mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - Create contract on sale order confirmation
- On Sale Order confirmation, a contract is created for each contract template used on sale order lines - A not finished contract can be mentioned on sale order line - A sale order line linked to a contract will update it and don't create a new one if it had the same template
This commit is contained in:
@@ -5,4 +5,3 @@
|
||||
|
||||
from . import test_product
|
||||
from . import test_sale_order
|
||||
from . import test_sale_order_line
|
||||
|
||||
@@ -2,39 +2,93 @@
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from mock import MagicMock
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class TestSaleOrder(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSaleOrder, self).setUp()
|
||||
self.product = self.env.ref('product.product_product_1')
|
||||
self.product1 = self.env.ref('product.product_product_1')
|
||||
self.product2 = self.env.ref('product.product_product_2')
|
||||
self.sale = self.env.ref('sale.sale_order_2')
|
||||
self.contract = self.env['account.analytic.contract'].create({
|
||||
'name': 'Test',
|
||||
})
|
||||
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',
|
||||
self.contract_template1 = self.env['account.analytic.contract'].create(
|
||||
{'name': 'Template 1'}
|
||||
)
|
||||
self.contract_template2 = self.env['account.analytic.contract'].create(
|
||||
{'name': 'Template 2'}
|
||||
)
|
||||
self.product1.write(
|
||||
{
|
||||
'is_contract': True,
|
||||
'contract_template_id': self.contract_template1.id,
|
||||
}
|
||||
)
|
||||
self.product2.write(
|
||||
{
|
||||
'is_contract': True,
|
||||
'contract_template_id': self.contract_template2.id,
|
||||
}
|
||||
)
|
||||
self.order_line1 = self.sale.order_line.filtered(
|
||||
lambda l: l.product_id == self.product1
|
||||
)
|
||||
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 """
|
||||
|
||||
def test_compute_is_contract(self):
|
||||
"""Sale Order should have is_contract true if one of its lines is
|
||||
contract"""
|
||||
self.assertTrue(self.sale.is_contract)
|
||||
self.env['account.analytic.account']._patch_method(
|
||||
'create', MagicMock()
|
||||
)
|
||||
|
||||
def test_action_confirm(self):
|
||||
""" It should create a contract for each contract template used in
|
||||
order_line """
|
||||
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,
|
||||
})
|
||||
contracts = self.sale.order_line.mapped('contract_id')
|
||||
self.assertEqual(len(contracts), 2)
|
||||
self.assertEqual(
|
||||
self.order_line1.contract_id.contract_template_id,
|
||||
self.contract_template1,
|
||||
)
|
||||
|
||||
def test_sale_contract_count(self):
|
||||
"""It should count contracts as many different contract template used
|
||||
in order_line"""
|
||||
self.sale.action_confirm()
|
||||
self.assertEqual(self.sale.contract_count, 2)
|
||||
|
||||
def test_onchange_product(self):
|
||||
""" It should get recurrence invoicing info to the sale line from
|
||||
its product """
|
||||
self.assertEqual(
|
||||
self.order_line1.recurring_rule_type,
|
||||
self.product1.recurring_rule_type,
|
||||
)
|
||||
self.assertEqual(
|
||||
self.order_line1.recurring_interval,
|
||||
self.product1.recurring_interval,
|
||||
)
|
||||
self.assertEqual(
|
||||
self.order_line1.recurring_invoicing_type,
|
||||
self.product1.recurring_invoicing_type,
|
||||
)
|
||||
|
||||
def test_check_contract_sale_partner(self):
|
||||
contract2 = self.env['account.analytic.account'].create(
|
||||
{
|
||||
'name': 'Contract',
|
||||
'contract_template_id': self.contract_template2.id,
|
||||
'partner_id': self.sale.partner_id.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.order_line1.contract_id = contract2
|
||||
|
||||
def test_check_contract_sale_contract_template(self):
|
||||
contract1 = self.env['account.analytic.account'].create(
|
||||
{
|
||||
'name': 'Contract',
|
||||
'contract_template_id': self.contract_template1.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.order_line1.contract_id = contract1
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018 ACSONE SA/NV.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from mock import MagicMock
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestSaleOrder(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSaleOrder, self).setUp()
|
||||
self.product = self.env.ref('product.product_product_1')
|
||||
self.sale = self.env.ref('sale.sale_order_2')
|
||||
self.contract = self.env['account.analytic.contract'].create({
|
||||
'name': 'Test',
|
||||
})
|
||||
self.product.product_tmpl_id.is_contract = True
|
||||
self.sale_order_line = self.sale.order_line.filtered(
|
||||
lambda l: l.product_id == self.product
|
||||
)
|
||||
|
||||
def test_onchange_product(self):
|
||||
""" It should get recurrence invoicing info to the sale line from
|
||||
its product """
|
||||
self.assertEqual(
|
||||
self.sale_order_line.recurring_rule_type,
|
||||
self.product.recurring_rule_type
|
||||
)
|
||||
self.assertEqual(
|
||||
self.sale_order_line.recurring_interval,
|
||||
self.product.recurring_interval
|
||||
)
|
||||
self.assertEqual(
|
||||
self.sale_order_line.recurring_invoicing_type,
|
||||
self.product.recurring_invoicing_type
|
||||
)
|
||||
Reference in New Issue
Block a user