[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:
Ted Salmon
2017-01-12 13:16:25 -08:00
committed by Rad0van
parent f27aefee28
commit 7bbfbe1967
20 changed files with 725 additions and 0 deletions

View 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

View 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
)

View 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,
})