~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to c2c_budget/wizard/advanced_search.py

  • Committer: Launchpad Translations on behalf of openerp-commiter
  • Date: 2012-11-24 07:05:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5825.
  • Revision ID: launchpad_translations_on_behalf_of_openerp-commiter-20121124070522-2i7pnpw5hq4wuz4g
Launchpad automatic translations update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*- 
2
 
##############################################################################
3
 
#
4
 
# Copyright (c) Camptocamp SA - http://www.camptocamp.com
5
 
# Author: Arnaud Wüst
6
 
#
7
 
#    This file is part of the c2c_budget module
8
 
#
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
14
 
# Service Company
15
 
#
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.
20
 
#
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.
25
 
#
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.
29
 
#
30
 
##############################################################################
31
 
 
32
 
import wizard
33
 
import netsvc
34
 
import pooler
35
 
from tools.misc import UpdateableStr
36
 
 
37
 
arch = UpdateableStr()
38
 
 
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"/>"""
45
 
    
46
 
_form_footer = """</form>"""
47
 
 
48
 
 
49
 
 
50
 
 
51
 
_fields = {
52
 
    'periods': {'string':'Periods', 'type':'many2many', 'relation':'account.period'},
53
 
    'items': {'string':'Budget Items', 'type':'many2many', 'relation':'c2c_budget.item'},
54
 
}
55
 
 
56
 
 
57
 
class wiz_advanced_search(wizard.interface):
58
 
    """ this wizard provide a advanced search form for budget lines """
59
 
  
60
 
  
61
 
    def _build_form(self, cr, uid, data, context):
62
 
        """complete the form with abstracted parts from  c2c_budget.wizard_abstraction """
63
 
        
64
 
        wiz_abstract_obj = pooler.get_pool(cr.dbname).get('c2c_budget.wizard_abstraction')
65
 
        
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
68
 
        
69
 
        #complete the fields with the abstraction
70
 
        fields = wiz_abstract_obj.advanced_search_get_fields(cr, uid, data,context)
71
 
        for f in fields:
72
 
            _fields[f] = fields[f]
73
 
        return {} 
74
 
  
75
 
  
76
 
    def _get_budget_lines(self, cr, uid, data, context):
77
 
        """ retrieve lines to work on """
78
 
        
79
 
        line_obj = pooler.get_pool(cr.dbname).get('c2c_budget.line')
80
 
        
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')
83
 
        
84
 
        period_ids = data['form']['periods'][0][2]
85
 
        item_ids = item_obj.get_sub_items(cr, data['form']['items'][0][2])
86
 
        
87
 
        version_ids = data['form']['versions'][0][2]
88
 
        
89
 
        anal_account_ids = anal_account_obj.get_children_flat_list(cr, uid, data['form']['analytic_accounts'][0][2])
90
 
        
91
 
        if data['form']['empty_aa_too']:
92
 
            anal_account_ids.append(False)
93
 
 
94
 
        #build the search criteria list
95
 
        criteria = []
96
 
        if len(item_ids) > 0:
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))
104
 
        
105
 
        line_ids = line_obj.search(cr, uid, criteria)
106
 
        
107
 
        
108
 
        
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)
111
 
        domain=[]
112
 
        if len(item_ids)==1:
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))+"])")
116
 
            
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))+"])")
121
 
            
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))+"])")
126
 
            
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))+"])")
131
 
            
132
 
        domain = "[%s]"%','.join(map(str,domain))        
133
 
        
134
 
        
135
 
        result = {
136
 
            'domain': domain,
137
 
            'name': 'Selected Budget Lines',
138
 
            'view_type': 'form',
139
 
            'view_mode': 'tree,form',
140
 
            'res_model': 'c2c_budget.line',
141
 
            'view_id': False,
142
 
            'type': 'ir.actions.act_window',
143
 
            'res_id':line_ids,
144
 
        }       
145
 
        
146
 
        return result
147
 
        
148
 
        
149
 
    states = {
150
 
    
151
 
        'init' : {
152
 
            'actions':[_build_form],
153
 
            'result' : {'type':'form', 'arch':arch, 'fields':_fields, 'state': [('end','Cancel'),('open','Show lines')]},
154
 
        },
155
 
        'open' : {
156
 
            'actions' : [],
157
 
            'result' : {'type':'action', 'action':_get_budget_lines, 'state':'end'},
158
 
        },
159
 
 
160
 
    }
161
 
    
162
 
    
163
 
wiz_advanced_search('budget.advanced_search')
 
 
b'\\ No newline at end of file'