1 from openerp import SUPERUSER_ID
2 from openerp.tests import common
3 from .. import test_models
5 class base_action_rule_test(common.TransactionCase):
9 super(base_action_rule_test, self).setUp()
10 cr, uid = self.cr, self.uid
11 self.demo = self.registry('ir.model.data').get_object(cr, uid, 'base', 'user_demo').id
12 self.admin = SUPERUSER_ID
13 self.model = self.registry('base.action.rule.lead.test')
15 def create_filter_done(self, cr, uid, context=None):
16 filter_pool = self.registry('ir.filters')
17 return filter_pool.create(cr, uid, {
18 'name': "Lead is in done state",
20 'model_id': 'base.action.rule.lead.test',
21 'domain' : "[('state','=','done')]",
24 def create_filter_draft(self, cr, uid, context=None):
25 filter_pool = self.registry('ir.filters')
26 return filter_pool.create(cr, uid, {
27 'name': "Lead is in draft state",
29 'model_id': "base.action.rule.lead.test",
30 'domain' : "[('state','=','draft')]",
33 def create_lead_test_1(self, cr, uid, context=None):
35 Create a new lead_test
37 return self.model.create(cr, uid, {
38 'name': "Lead Test 1",
39 'user_id': self.admin,
42 def create_rule(self, cr, uid, filter_id=False, filter_pre_id=False, context=None):
44 The "Rule 1" says that when a lead goes to the 'draft' state, the responsible for that lead changes to user "demo"
46 self.action_pool = self.registry('base.action.rule')
47 return self.action_pool.create(cr,uid,{
49 'model_id': self.registry('ir.model').search(cr, uid, [('model','=','base.action.rule.lead.test')], context=context)[0],
51 'trg_date_type' : 'none',
52 'filter_pre_id' : filter_pre_id,
53 'filter_id' : filter_id,
54 'act_user_id': self.demo,
57 def test_00_check_to_state_draft_pre(self):
59 Check that a new record (with state = draft) doesn't change its responsible when there is a precondition filter which check that the state is draft.
61 cr, uid = self.cr, self.uid
62 filter_draft = self.create_filter_draft(cr, uid)
63 rule_1_id = self.create_rule(cr, uid, filter_pre_id=filter_draft)
64 new_lead_id = self.create_lead_test_1(cr, uid)
65 new_lead = self.model.browse(cr, uid, new_lead_id)
66 self.assertEquals(new_lead.state, 'draft')
67 self.assertEquals(new_lead.user_id.id, self.admin)
69 def test_01_check_to_state_draft_post(self):
71 Check that a new record (with state = draft) changes its responsible when there is a postcondition filter which check that the state is draft.
73 cr, uid = self.cr, self.uid
74 filter_draft = self.create_filter_draft(cr, uid)
75 rule_1_id = self.create_rule(cr, uid, filter_id=filter_draft)
76 new_lead_id = self.create_lead_test_1(cr, uid)
77 new_lead = self.model.browse(cr, uid, new_lead_id)
78 self.assertEquals(new_lead.state, 'draft')
79 self.assertEquals(new_lead.user_id.id, self.demo)
81 def test_02_check_from_draft_to_done_with_steps(self):
83 A new record will be created and will goes from draft to done state via the other states (open, pending and cancel)
84 We will create a rule that says in precondition that the record must be in the "draft" state while a postcondition filter says
85 that the record will be done. If the state goes from 'draft' to 'done' the responsible will change. If those two conditions aren't
86 verified, the responsible will stay the same
87 The responsible in that test will never change
89 cr, uid = self.cr, self.uid
90 filter_draft = self.create_filter_draft(cr, uid)
91 filter_done = self.create_filter_done(cr, uid)
92 self.create_rule(cr, uid, filter_pre_id=filter_draft, filter_id=filter_done)
93 new_lead_id = self.create_lead_test_1(cr, uid)
94 new_lead = self.model.browse(cr, uid, new_lead_id)
95 self.assertEquals(new_lead.state, 'draft')
96 self.assertEquals(new_lead.user_id.id, self.admin)
97 """ change the state of new_lead to open and check that responsible doen't change"""
98 new_lead.write({'state': 'open'})
99 new_lead = self.model.browse(cr, uid, new_lead_id)
100 self.assertEquals(new_lead.state, 'open')
101 self.assertEquals(new_lead.user_id.id, self.admin)
102 """ change the state of new_lead to pending and check that responsible doen't change"""
103 new_lead.write({'state': 'pending'})
104 new_lead = self.model.browse(cr, uid, new_lead_id)
105 self.assertEquals(new_lead.state, 'pending')
106 self.assertEquals(new_lead.user_id.id, self.admin)
107 """ change the state of new_lead to cancel and check that responsible doen't change"""
108 new_lead.write({'state': 'cancel'})
109 new_lead = self.model.browse(cr, uid, new_lead_id)
110 self.assertEquals(new_lead.state, 'cancel')
111 self.assertEquals(new_lead.user_id.id, self.admin)
112 """ change the state of new_lead to done and check that responsible doen't change """
113 new_lead.write({'state': 'done'})
114 new_lead = self.model.browse(cr, uid, new_lead_id)
115 self.assertEquals(new_lead.state, 'done')
116 self.assertEquals(new_lead.user_id.id, self.admin)
118 def test_02_check_from_draft_to_done_without_steps(self):
120 A new record will be created and will goes from draft to done in one operation
121 We will create a rule that says in precondition that the record must be in the "draft" state while a postcondition filter says
122 that the record will be done. If the state goes from 'draft' to 'done' the responsible will change. If those two conditions aren't
123 verified, the responsible will stay the same
124 The responsible in that test will change to user "demo"
126 cr, uid = self.cr, self.uid
127 filter_draft = self.create_filter_draft(cr, uid)
128 filter_done = self.create_filter_done(cr, uid)
129 self.create_rule(cr, uid, filter_pre_id=filter_draft, filter_id=filter_done)
130 new_lead_id = self.create_lead_test_1(cr, uid)
131 new_lead = self.model.browse(cr, uid, new_lead_id)
132 self.assertEquals(new_lead.state, 'draft')
133 self.assertEquals(new_lead.user_id.id, self.admin)
134 """ change the state of new_lead to done and check that responsible change to Demo_user"""
135 new_lead.write({'state': 'done'})
136 new_lead = self.model.browse(cr, uid, new_lead_id)
137 self.assertEquals(new_lead.state, 'done')
138 self.assertEquals(new_lead.user_id.id, self.demo)