1
##############################################################################
3
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
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
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.
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.
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.
26
##############################################################################
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
34
class sandwich_order_wizard(wizard.interface):
36
def _sandwich_order_wizard_order(self, cr, uid, data, context):
37
if not len(data['ids']):
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)]):
48
'product_type_id': producttype
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)
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"/>
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'},
69
'result': {'type': 'form', 'arch':_sandwich_order_wizard_form, 'fields':_sandwich_order_wizard_fields, 'state':[('end','Cancel'),('complete','Complete order')]}
72
'actions': [_sandwich_order_wizard_order],
73
'result': {'type': 'state', 'state': 'end'}
77
sandwich_order_wizard('sandwich.order.wizard')
80
# This class send a request message to users who don't have their order filled in for this day
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",
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...
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"/>
113
_sandwich_order_recall_wizard_fields = {
114
'user_id': {'string': 'Baaaad users !', 'type': 'many2many', 'relation': 'res.users'},
120
'result' : {'type': 'form', 'arch': _sandwich_order_recall_wizard_form, 'fields': _sandwich_order_recall_wizard_fields, 'state': [('end','Cancel'),('send','Send')]},
123
'actions' : [_sandwich_order_recall_wizard_send],
124
'result' : {'type': 'state', 'state': 'end'},
128
sandwich_order_recall_wizard('sandwich.order.recall.wizard')