mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[ADD] product_contract: Create module
* Add contract functionality to `product.templates` * Add logic to create contracts from `sale.order` that contains contract products.
This commit is contained in:
committed by
Denis Roussel
parent
b3ef1f1e4f
commit
5b970e39e3
6
product_contract/tests/__init__.py
Normal file
6
product_contract/tests/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import test_product_template
|
||||
from . import test_sale_order
|
||||
31
product_contract/tests/test_product_template.py
Normal file
31
product_contract/tests/test_product_template.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestProductTemplate(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestProductTemplate, self).setUp()
|
||||
self.product = self.env.ref(
|
||||
'product.product_product_4_product_template'
|
||||
)
|
||||
self.contract = self.env['account.analytic.contract'].create({
|
||||
'name': 'Test',
|
||||
'recurring_rule_type': 'yearly',
|
||||
'recurring_interval': 12345,
|
||||
})
|
||||
|
||||
def test_change_is_contract(self):
|
||||
""" It should verify that the contract_template_id is removed
|
||||
when is_contract is False """
|
||||
self.product.is_contract = True
|
||||
self.product.contract_template_id = self.contract.id
|
||||
self.product.is_contract = False
|
||||
self.product._change_is_contract()
|
||||
self.assertEquals(
|
||||
len(self.product.contract_template_id),
|
||||
0
|
||||
)
|
||||
34
product_contract/tests/test_sale_order.py
Normal file
34
product_contract/tests/test_sale_order.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
|
||||
|
||||
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',
|
||||
'recurring_rule_type': 'yearly',
|
||||
'recurring_interval': 12345,
|
||||
})
|
||||
self.product.product_tmpl_id.is_contract = True
|
||||
self.product.product_tmpl_id.contract_template_id = self.contract.id
|
||||
|
||||
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,
|
||||
})
|
||||
Reference in New Issue
Block a user