~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to sandwich/wizard/sandwich_wizard.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# WARNING: This program as such is intended to be used by professional
 
6
# programmers who take the whole responsability of assessing all potential
 
7
# consequences resulting from its eventual inadequacies and bugs
 
8
# End users who are looking for a ready-to-use solution with commercial
 
9
# garantees and support are strongly adviced to contract a Free Software
 
10
# Service Company
 
11
#
 
12
# This program is Free Software; you can redistribute it and/or
 
13
# modify it under the terms of the GNU General Public License
 
14
# as published by the Free Software Foundation; either version 2
 
15
# of the License, or (at your option) any later version.
 
16
#
 
17
# This program is distributed in the hope that it will be useful,
 
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
# GNU General Public License for more details.
 
21
#
 
22
# You should have received a copy of the GNU General Public License
 
23
# along with this program; if not, write to the Free Software
 
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
#
 
26
##############################################################################
 
27
 
 
28
import wizard
 
29
import pooler
 
30
 
 
31
#
 
32
# This class fill in the order with kind of automatically generated order lines, based on the last order for a user concerning a type of product
 
33
#
 
34
class sandwich_order_wizard(wizard.interface):
 
35
 
 
36
        def _sandwich_order_wizard_order(self, cr, uid, data, context):
 
37
                if not len(data['ids']):
 
38
                        return {}
 
39
                cr.execute('update sandwich_order_line set order_id=%d where order_id is null', (data['ids'][0],))
 
40
                for order in pooler.get_pool(cr.dbname).get('sandwich.order').browse(cr, uid, data['ids']):
 
41
                        for user_id in data['form']['user_id'][0][2]:
 
42
                                for producttype in data['form']['product_type_id'][0][2]:
 
43
                                        if not pooler.get_pool(cr.dbname).get('sandwich.order.line').search(cr, uid, [('user_id','=',user_id),('product_type_id','=',producttype),('order_id','=',order.id)]):
 
44
                                                vals = {
 
45
                                                        'user_id': user_id,
 
46
                                                        'order_id': order.id,
 
47
                                                        'date': order.date,
 
48
                                                        'product_type_id': producttype
 
49
                                                }
 
50
                                                vals.update( pooler.get_pool(cr.dbname).get('sandwich.order.line').onchange_user_id(cr, uid, uid, user_id, producttype)['value'] )
 
51
                                                pooler.get_pool(cr.dbname).get('sandwich.order.line').create(cr, uid, vals)
 
52
                return {}
 
53
 
 
54
        _sandwich_order_wizard_form =  '''<?xml version="1.0"?>
 
55
                <form string="Complete order">
 
56
                <separator string="Set orders for the day" colspan="4"/>
 
57
                        <field name="user_id"/>
 
58
                        <field name="product_type_id"/>
 
59
                </form> '''
 
60
        
 
61
        _sandwich_order_wizard_fields = {
 
62
                'user_id': {'string': 'User', 'type': 'many2many','relation':'res.users'},
 
63
                'product_type_id': {'string': 'Product', 'type': 'many2many', 'relation':'sandwich.product.type'},
 
64
        }
 
65
 
 
66
        states = {
 
67
                'init': {
 
68
                        'actions': [],
 
69
                        'result': {'type': 'form', 'arch':_sandwich_order_wizard_form, 'fields':_sandwich_order_wizard_fields,  'state':[('end','Cancel'),('complete','Complete order')]}
 
70
                },
 
71
                'complete': {
 
72
                        'actions': [_sandwich_order_wizard_order],
 
73
                        'result': {'type': 'state', 'state': 'end'}
 
74
                }
 
75
        }
 
76
 
 
77
sandwich_order_wizard('sandwich.order.wizard')
 
78
 
 
79
#
 
80
# This class send a request message to users who don't have their order filled in for this day
 
81
#
 
82
class sandwich_order_recall_wizard(wizard.interface):
 
83
        def _sandwich_order_recall_wizard_send(self, cr, uid, data, context):
 
84
                for user_id in data['form']['user_id'][0][2]:
 
85
                        if not pooler.get_pool(cr.dbname).get('sandwich.order.line').search(cr, uid, [('user_id','=',user_id),('order_id','=',data['id'])]):
 
86
                                request = pooler.get_pool(cr.dbname).get('res.request')
 
87
                                request.create(cr, uid, {
 
88
                                        'name' : "Please order your lunch of the day",
 
89
                                        'priority' : '0',
 
90
                                        'state' : 'active',
 
91
                                        'body' : """Hello,
 
92
 
 
93
It seems like you have forgotten to order your sandwich (or meal).
 
94
As it will be ordered soon, it seems to be a rather nice idea to complete your
 
95
order for today ASAP. If you do not, you'll probably get the same meal as yesterday...
 
96
 
 
97
Thanks,
 
98
 
 
99
-- 
 
100
Tiny ERP
 
101
""",
 
102
                                        'act_from' : uid,
 
103
                                        'act_to' : user_id,
 
104
                                })
 
105
                return {}
 
106
                
 
107
        _sandwich_order_recall_wizard_form = '''<?xml version="1.0"?>
 
108
                <form string="Recall orders to users">
 
109
                        <separator string="List of user to remind the order" colspan="4"/>
 
110
                        <field name="user_id" colspan="4"/>
 
111
                </form>'''
 
112
                
 
113
        _sandwich_order_recall_wizard_fields = {
 
114
                'user_id': {'string': 'Baaaad users !', 'type': 'many2many', 'relation': 'res.users'},
 
115
        }
 
116
        
 
117
        states = {
 
118
                'init' : {
 
119
                        'actions' : [],
 
120
                        'result' : {'type': 'form', 'arch': _sandwich_order_recall_wizard_form, 'fields': _sandwich_order_recall_wizard_fields, 'state': [('end','Cancel'),('send','Send')]},
 
121
                },
 
122
                'send' : {
 
123
                        'actions' : [_sandwich_order_recall_wizard_send],
 
124
                        'result' : {'type': 'state', 'state': 'end'},
 
125
                }
 
126
        }
 
127
        
 
128
sandwich_order_recall_wizard('sandwich.order.recall.wizard')