1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) Camptocamp SA - http://www.camptocamp.com
7
# This file is part of the c2c_budget module
9
# WARNING: This program as such is intended to be used by professional
10
# programmers who take the whole responsability of assessing all potential
11
# consequences resulting from its eventual inadequacies and bugs
12
# End users who are looking for a ready-to-use solution with commercial
13
# garantees and support are strongly adviced to contract a Free Software
16
# This program is Free Software; you can redistribute it and/or
17
# modify it under the terms of the GNU General Public License
18
# as published by the Free Software Foundation; either version 2
19
# of the License, or (at your option) any later version.
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU General Public License for more details.
26
# You should have received a copy of the GNU General Public License
27
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
##############################################################################
35
from tools.misc import UpdateableStr
37
arch = UpdateableStr()
39
_form_header = """<?xml version="1.0"?>
40
<form string="Budget lines search" height="200" width="800">
41
<separator string="Choose periods (empty for all)" colspan="2"/>
42
<separator string="Choose items (empty for all)" colspan="2"/>
43
<field name="periods" nolabel="1" colspan="2" width="400" height="150"/>
44
<field name="items" nolabel="1" colspan="2" width="400"/>"""
46
_form_footer = """</form>"""
52
'periods': {'string':'Periods', 'type':'many2many', 'relation':'account.period'},
53
'items': {'string':'Budget Items', 'type':'many2many', 'relation':'c2c_budget.item'},
57
class wiz_advanced_search(wizard.interface):
58
""" this wizard provide a advanced search form for budget lines """
61
def _build_form(self, cr, uid, data, context):
62
"""complete the form with abstracted parts from c2c_budget.wizard_abstraction """
64
wiz_abstract_obj = pooler.get_pool(cr.dbname).get('c2c_budget.wizard_abstraction')
66
#complete the form with the abstraction
67
arch.string = _form_header + wiz_abstract_obj.advanced_search_get_form(cr, uid, data,context) + _form_footer
69
#complete the fields with the abstraction
70
fields = wiz_abstract_obj.advanced_search_get_fields(cr, uid, data,context)
72
_fields[f] = fields[f]
76
def _get_budget_lines(self, cr, uid, data, context):
77
""" retrieve lines to work on """
79
line_obj = pooler.get_pool(cr.dbname).get('c2c_budget.line')
81
item_obj = pooler.get_pool(cr.dbname).get('c2c_budget.item')
82
anal_account_obj = pooler.get_pool(cr.dbname).get('account.analytic.account')
84
period_ids = data['form']['periods'][0][2]
85
item_ids = item_obj.get_sub_items(cr, data['form']['items'][0][2])
87
version_ids = data['form']['versions'][0][2]
89
anal_account_ids = anal_account_obj.get_children_flat_list(cr, uid, data['form']['analytic_accounts'][0][2])
91
if data['form']['empty_aa_too']:
92
anal_account_ids.append(False)
94
#build the search criteria list
97
criteria.append(('budget_item_id', 'in', item_ids))
98
if len(period_ids) > 0:
99
criteria.append(('period_id', 'in', period_ids))
100
if len(version_ids) > 0:
101
criteria.append(('budget_version_id', 'in', version_ids))
102
if len(anal_account_ids) > 0:
103
criteria.append(('analytic_account_id', 'in', anal_account_ids))
105
line_ids = line_obj.search(cr, uid, criteria)
109
# Construct domain: if there is only one item selected,
110
# put it in the domain to improve input of lines (what is in the domain will be auto-selected)
113
domain.append("('budget_item_id','=',%d)"%item_ids[0])
114
elif len(item_ids) > 1:
115
domain.append("('budget_item_id','in',["+','.join(map(str,item_ids))+"])")
117
if len(period_ids)==1:
118
domain.append("('period_id','=',%d)"%period_ids[0])
119
elif len(period_ids) > 1:
120
domain.append("('period_id','in',["+','.join(map(str,period_ids))+"])")
122
if len(version_ids)==1:
123
domain.append("('budget_version_id','=',%d)"%version_ids[0])
124
elif len(version_ids) > 1:
125
domain.append("('budget_version_id','in',["+','.join(map(str,version_ids))+"])")
127
if len(anal_account_ids)==1:
128
domain.append("('analytic_account_id','=',%d)"%anal_account_ids[0])
129
elif len(anal_account_ids) > 1:
130
domain.append("('analytic_account_id','in',["+','.join(map(str,anal_account_ids))+"])")
132
domain = "[%s]"%','.join(map(str,domain))
137
'name': 'Selected Budget Lines',
139
'view_mode': 'tree,form',
140
'res_model': 'c2c_budget.line',
142
'type': 'ir.actions.act_window',
152
'actions':[_build_form],
153
'result' : {'type':'form', 'arch':arch, 'fields':_fields, 'state': [('end','Cancel'),('open','Show lines')]},
157
'result' : {'type':'action', 'action':_get_budget_lines, 'state':'end'},
163
wiz_advanced_search('budget.advanced_search')
b'\\ No newline at end of file'