[IMP] - Product with is_contract can be only of type service

This commit is contained in:
sbejaoui
2018-10-31 16:23:34 +01:00
committed by Denis Roussel
parent 88112d316f
commit 4b260d57bb
5 changed files with 47 additions and 37 deletions

View File

@@ -2,5 +2,5 @@
# 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_product
from . import test_sale_order

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
class TestProductTemplate(TransactionCase):
def setUp(self):
super(TestProductTemplate, self).setUp()
self.service_product = self.env.ref('product.product_product_1')
self.consu_product = self.env.ref('product.product_product_5')
self.contract = self.env['account.analytic.contract'].create(
{'name': 'Test'}
)
def test_change_is_contract(self):
""" It should verify that the contract_template_id is removed
when is_contract is False """
self.service_product.is_contract = True
self.service_product.contract_template_id = self.contract.id
self.service_product.is_contract = False
self.service_product.product_tmpl_id._change_is_contract()
self.assertEquals(len(self.service_product.contract_template_id), 0)
def test_check_contract_product_type(self):
"""
It should raise ValidationError on change of is_contract to True
for consu product
"""
with self.assertRaises(ValidationError):
self.consu_product.is_contract = True

View File

@@ -1,31 +0,0 @@
# -*- 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
)

View File

@@ -14,8 +14,6 @@ class TestSaleOrder(TransactionCase):
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