~mga/openobject-addons/account_india

« back to all changes in this revision

Viewing changes to lunch/wizard/reset_box.py

  • Committer: nel
  • Date: 2007-07-16 05:55:26 UTC
  • Revision ID: nel-206acbf4defe2495320c9024df7d23203676e27c
Add lunch module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import wizard
 
2
import netsvc
 
3
import ir
 
4
import pooler
 
5
 
 
6
set_to_zero_form = """<?xml version="1.0"?>
 
7
<form string="Reset cashbox">
 
8
        <label string="Are you sure you want to reset this cashbox ?"/>
 
9
</form>"""
 
10
 
 
11
 
 
12
 
 
13
confirm_setting_zero_fields = {}
 
14
 
 
15
def _set_to_zero(self,cr,uid,data,context):
 
16
    pool= pooler.get_pool(cr.dbname)
 
17
    cashmove_ref = pool.get('lunch.cashmove')
 
18
    cr.execute("select user_cashmove, box,sum(amount) from lunch_cashmove where active= 't' and box in (%s) group by user_cashmove, box"%','.join(map(str,data['ids'])))
 
19
    res= cr.fetchall()
 
20
    cr.execute("update lunch_cashmove set active = 'f' where active= 't' and box in (%s)"%','.join(map(str,data['ids'])))
 
21
##    to_unactive= {}.fromkeys([r[0] for r in cr.fetchall]).keys()
 
22
##    print to_unactive
 
23
##    cashmove_ref.write(cr,uid,to_unactive,{'active':False})            
 
24
##    
 
25
    for (user_id,box_id,amount) in res:
 
26
        cashmove_ref.create(cr,uid,{'name': 'Summary for user'+ str(user_id),
 
27
                        'amount': amount,
 
28
                        'user_cashmove': user_id,
 
29
                        'box': box_id,
 
30
                        'active': True,
 
31
                        })
 
32
    return {}
 
33
 
 
34
 
 
35
class cashbox_set_to_zero(wizard.interface):
 
36
 
 
37
        states = {
 
38
            
 
39
                'init': {
 
40
                        'action':[],
 
41
                        'result':{'type' : 'form',
 
42
                          'arch' : set_to_zero_form,
 
43
                          'fields' : confirm_setting_zero_fields,
 
44
                          'state' : [('end', 'Cancel'),('zero', 'Set to Zero') ]},
 
45
        
 
46
                },
 
47
                'zero' : {
 
48
                        'actions' : [_set_to_zero],
 
49
                        'result' : {'type' : 'state', 'state' : 'end'}
 
50
                },
 
51
        }
 
52
        
 
53
cashbox_set_to_zero('lunch.cashbox.clean')