[MERGE] forward port of branch 7.0 up to de07c64
[odoo/odoo.git] / addons / lunch / tests / test_lunch.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp import tools
23 from openerp.tests import common
24
25 class Test_Lunch(common.TransactionCase):
26
27     def setUp(self):
28         """*****setUp*****"""
29         super(Test_Lunch, self).setUp()
30         cr, uid = self.cr, self.uid
31
32         self.res_users = self.registry('res.users')
33         self.lunch_order = self.registry('lunch.order')
34         self.lunch_order_line = self.registry('lunch.order.line')
35         self.lunch_cashmove = self.registry('lunch.cashmove')
36         self.lunch_product = self.registry('lunch.product')
37         self.lunch_alert = self.registry('lunch.alert')
38         self.lunch_product_category = self.registry('lunch.product.category')
39
40         self.demo_id = self.res_users.search(cr, uid, [('name', '=', 'Demo User')])
41         self.product_bolognese_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'lunch', 'product_Bolognese')
42         self.product_Bolognese_id = self.product_bolognese_ref and self.product_bolognese_ref[1] or False
43         self.new_id_order = self.lunch_order.create(cr,uid,{
44             'user_id': self.demo_id[0],
45             'order_line_ids':'[]',
46             },context=None)
47         self.new_id_order_line = self.lunch_order_line.create(cr,uid,{
48             'order_id':self.new_id_order,
49             'product_id':self.product_Bolognese_id,
50             'note': '+Emmental',
51             'cashmove': [],
52             'price': self.lunch_product.browse(cr,uid,self.product_Bolognese_id,context=None).price,
53             })
54
55     def test_00_lunch_order(self):
56         """Change the state of an order line from 'new' to 'ordered'. Check that there are no cashmove linked to that order line"""
57         cr, uid = self.cr, self.uid
58         self.order_one = self.lunch_order_line.browse(cr,uid,self.new_id_order_line,context=None)
59         #we check that our order_line is a 'new' one and that there are no cashmove linked to that order_line:
60         self.assertEqual(self.order_one.state,'new')
61         self.assertEqual(self.order_one.cashmove, [])
62         #we order that orderline so it's state will be 'ordered'
63         self.order_one.order()
64         self.order_one = self.lunch_order_line.browse(cr,uid,self.new_id_order_line,context=None)
65         #we check that our order_line is a 'ordered' one and that there are no cashmove linked to that order_line:
66         self.assertEqual(self.order_one.state,'ordered')
67         self.assertEqual(self.order_one.cashmove, [])
68
69     def test_01_lunch_order(self):
70         """Change the state of an order line from 'new' to 'ordered' then to 'confirmed'. Check that there is a cashmove linked to the order line"""
71         cr, uid = self.cr, self.uid
72         self.test_00_lunch_order()
73         #We receive the order so we confirm the order line so it's state will be 'confirmed'
74         #A cashmove will be created and we will test that the cashmove amount equals the order line price
75         self.order_one.confirm()
76         self.order_one = self.lunch_order_line.browse(cr,uid,self.new_id_order_line,context=None)
77         #we check that our order_line is a 'confirmed' one and that there are a cashmove linked to that order_line with an amount equals to the order line price:
78         self.assertEqual(self.order_one.state,'confirmed')
79         self.assertTrue(self.order_one.cashmove!=[])
80         self.assertTrue(self.order_one.cashmove[0].amount==-self.order_one.price)
81
82     def test_02_lunch_order(self):
83         """Change the state of an order line from 'confirmed' to 'cancelled' and check that the cashmove linked to that order line will be deleted"""
84         cr, uid = self.cr, self.uid
85         self.test_01_lunch_order()
86         #We have a confirmed order with its associate cashmove
87         #We execute the cancel function
88         self.order_one.cancel()
89         self.order_one = self.lunch_order_line.browse(cr,uid,self.new_id_order_line,context=None)
90         #We check that the state is cancelled and that the cashmove has been deleted
91         self.assertEqual(self.order_one.state,'cancelled')
92         self.assertTrue(self.order_one.cashmove==[])