~noviat/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_cashflow/wizard/assign_cashflow_code.py

  • Committer: root
  • Date: 2012-04-10 20:37:39 UTC
  • Revision ID: root@oerp61-20120410203739-flykplw8jzpqa15c
update noviat v6.0 accounting modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    
 
6
#    Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
 
7
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
import time
 
24
from osv import osv, fields
 
25
import netsvc
 
26
from tools.translate import _
 
27
logger=netsvc.Logger()
 
28
 
 
29
class assign_cashflow_code(osv.osv_memory):
 
30
    _name = 'assign.cashflow.code'
 
31
    _description = 'Assign Cash Flow Code to selected Cash Flow Lines'
 
32
 
 
33
    def warning(self, cr, uid, ids, context):       
 
34
        line_ids = context['active_ids']
 
35
        note = _('\nAre you sure ?')
 
36
        note += _('\n\nNumber of lines selected : %s') % len(line_ids)
 
37
 
 
38
        line_obj = self.pool.get('account.cashflow.line')
 
39
        draft_ids = line_obj.search(cr, uid, [('id', 'in', line_ids), ('state', '=', 'draft')], context=context) 
 
40
        if len(line_ids) <> len(draft_ids):
 
41
            note += _("\nOnly lines in 'Draft' state will be updated!")
 
42
            note += _("\nNumber of 'Draft' lines selected : %s") % len(draft_ids)
 
43
            context.update({'active_ids': draft_ids})
 
44
        vals = {
 
45
            'state': 'ok',
 
46
            'note': note
 
47
        }
 
48
        self.write(cr, uid, ids, vals, context=context)
 
49
        mod_obj = self.pool.get('ir.model.data')
 
50
        model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_assign_cashflow_code')], context=context)
 
51
        resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
 
52
        return {
 
53
            'name': _('Assign Cash Flow Code done'),
 
54
            'res_id': ids[0],
 
55
            'view_type': 'form',
 
56
            'view_mode': 'form',
 
57
            'target': 'new',
 
58
            'res_model': 'assign.cashflow.code',
 
59
            'views': [(resource_id, 'form')],
 
60
            'type': 'ir.actions.act_window',
 
61
            'context': context,
 
62
        }
 
63
        
 
64
    def update_lines(self, cr, uid, ids, context):       
 
65
        line_ids = context['active_ids']
 
66
        cashflow_code_id = self.read(cr, uid, ids, ['cashflow_code_id'], context=context)[0]['cashflow_code_id']
 
67
        line_obj = self.pool.get('account.cashflow.line')
 
68
        line_obj.write(cr, uid, line_ids, {'cashflow_code_id': cashflow_code_id}, context=context)
 
69
        vals = {
 
70
            'state': 'done',
 
71
            'note': _('\nNumber of updates : %s') % len(line_ids)
 
72
        }
 
73
        self.write(cr, uid, ids, vals, context=context)
 
74
        mod_obj = self.pool.get('ir.model.data')
 
75
        model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_assign_cashflow_code')], context=context)
 
76
        resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
 
77
        return {
 
78
            'name': _('Assign Cash Flow Code done'),
 
79
            'res_id': ids[0],
 
80
            'view_type': 'form',
 
81
            'view_mode': 'form',
 
82
            'target': 'new',
 
83
            'res_model': 'assign.cashflow.code',
 
84
            'views': [(resource_id, 'form')],
 
85
            'type': 'ir.actions.act_window',
 
86
        } 
 
87
    
 
88
    _columns = {
 
89
        'cashflow_code_id': fields.many2one('account.cashflow.code', 'Cash Flow Code', 
 
90
            domain=[('type', '=', 'normal')], required=True),
 
91
        'state': fields.selection([
 
92
            ('draft', 'Draft'),
 
93
            ('ok', 'Ok'),            
 
94
            ('done', 'Done')], 
 
95
            'State', required=True, readonly=True),        
 
96
        'note':fields.text('Result', readonly=True),
 
97
    }
 
98
    _defaults = {
 
99
        'state': 'draft',
 
100
    }
 
101
 
 
102
assign_cashflow_code()
 
103
 
 
104
 
 
105
class assign_cashflow_code_all_line(osv.osv_memory):
 
106
    _name = 'assign.cashflow.code.all.line'
 
107
    _description = 'Assign Cash Flow Code to selected Cash Flow Lines'
 
108
 
 
109
    def warning(self, cr, uid, ids, context):       
 
110
        line_ids = context['active_ids']
 
111
        note = _('\nAre you sure ?')
 
112
        note += _('\n\nNumber of lines selected : %s') % len(line_ids)
 
113
        oline_obj = self.pool.get('account.cashflow.line.overview')
 
114
        draft_ids = oline_obj.search(cr, uid, [('id', 'in', line_ids), ('state', '=', 'draft')], context=context) 
 
115
        if len(line_ids) <> len(draft_ids):
 
116
            note += _("\nOnly lines in 'Draft' state will be updated!")
 
117
            note += _("\nNumber of 'Draft' lines selected : %s") % len(draft_ids)
 
118
            context.update({'active_ids': draft_ids})
 
119
        vals = {
 
120
            'state': 'ok',
 
121
            'note': note
 
122
        }
 
123
        self.write(cr, uid, ids, vals, context=context)
 
124
        mod_obj = self.pool.get('ir.model.data')
 
125
        model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_assign_cashflow_code_all_line')], context=context)
 
126
        resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
 
127
        return {
 
128
            'name': _('Assign Cash Flow Code done'),
 
129
            'res_id': ids[0],
 
130
            'view_type': 'form',
 
131
            'view_mode': 'form',
 
132
            'target': 'new',
 
133
            'res_model': 'assign.cashflow.code.all.line',
 
134
            'views': [(resource_id, 'form')],
 
135
            'type': 'ir.actions.act_window',
 
136
            'context': context,
 
137
        }
 
138
        
 
139
    def update_lines(self, cr, uid, ids, context):       
 
140
        line_ids = context['active_ids']
 
141
        cfc = self.browse(cr, uid, ids[0]).cashflow_code_id
 
142
        cline_obj = self.pool.get('account.cashflow.line')
 
143
        pline_obj = self.pool.get('account.cashflow.provision.line')
 
144
        cline_ids = []
 
145
        pline_ids = []
 
146
        for i in line_ids:
 
147
            if i < 0:
 
148
                pline_ids += [-i]
 
149
            else:
 
150
                cline_ids += [i]       
 
151
        cline_obj.write(cr, uid, cline_ids, {'cashflow_code_id': cfc.id}, context=context)
 
152
        pline_obj.write(cr, uid, pline_ids, {'cashflow_code_id': cfc.twin_id.id}, context=context)
 
153
        vals = {
 
154
            'state': 'done',
 
155
            'note': _('\nNumber of updates : %s') % len(line_ids)
 
156
        }
 
157
        self.write(cr, uid, ids, vals, context=context)
 
158
        mod_obj = self.pool.get('ir.model.data')
 
159
        model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_assign_cashflow_code_all_line')], context=context)
 
160
        resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
 
161
        return {
 
162
            'name': _('Assign Cash Flow Code done'),
 
163
            'res_id': ids[0],
 
164
            'view_type': 'form',
 
165
            'view_mode': 'form',
 
166
            'target': 'new',
 
167
            'res_model': 'assign.cashflow.code.all.line',
 
168
            'views': [(resource_id, 'form')],
 
169
            'type': 'ir.actions.act_window',
 
170
        } 
 
171
    
 
172
    _columns = {
 
173
        'cashflow_code_id': fields.many2one('account.cashflow.code', 'Cash Flow Code', 
 
174
            domain=[('type', '=', 'normal')], required=True),
 
175
        'state': fields.selection([
 
176
            ('draft', 'Draft'),
 
177
            ('ok', 'Ok'),            
 
178
            ('done', 'Done')], 
 
179
            'State', required=True, readonly=True),        
 
180
        'note':fields.text('Result', readonly=True),
 
181
    }
 
182
    _defaults = {
 
183
        'state': 'draft',
 
184
    }
 
185
 
 
186
assign_cashflow_code_all_line()