1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
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.
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.
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/>.
21
##############################################################################
24
from osv import osv, fields
26
from tools.translate import _
27
logger=netsvc.Logger()
29
class assign_cashflow_code(osv.osv_memory):
30
_name = 'assign.cashflow.code'
31
_description = 'Assign Cash Flow Code to selected Cash Flow Lines'
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)
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})
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']
53
'name': _('Assign Cash Flow Code done'),
58
'res_model': 'assign.cashflow.code',
59
'views': [(resource_id, 'form')],
60
'type': 'ir.actions.act_window',
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)
71
'note': _('\nNumber of updates : %s') % len(line_ids)
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']
78
'name': _('Assign Cash Flow Code done'),
83
'res_model': 'assign.cashflow.code',
84
'views': [(resource_id, 'form')],
85
'type': 'ir.actions.act_window',
89
'cashflow_code_id': fields.many2one('account.cashflow.code', 'Cash Flow Code',
90
domain=[('type', '=', 'normal')], required=True),
91
'state': fields.selection([
95
'State', required=True, readonly=True),
96
'note':fields.text('Result', readonly=True),
102
assign_cashflow_code()
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'
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})
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']
128
'name': _('Assign Cash Flow Code done'),
133
'res_model': 'assign.cashflow.code.all.line',
134
'views': [(resource_id, 'form')],
135
'type': 'ir.actions.act_window',
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')
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)
155
'note': _('\nNumber of updates : %s') % len(line_ids)
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']
162
'name': _('Assign Cash Flow Code done'),
167
'res_model': 'assign.cashflow.code.all.line',
168
'views': [(resource_id, 'form')],
169
'type': 'ir.actions.act_window',
173
'cashflow_code_id': fields.many2one('account.cashflow.code', 'Cash Flow Code',
174
domain=[('type', '=', 'normal')], required=True),
175
'state': fields.selection([
179
'State', required=True, readonly=True),
180
'note':fields.text('Result', readonly=True),
186
assign_cashflow_code_all_line()