added from extra-addons
[odoo/odoo.git] / addons / account_balance / account_move_line.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ##############################################################################
30
31 import time
32 import netsvc
33 from osv import fields, osv
34
35
36 class account_move_line(osv.osv):
37     _name="account.move.line"
38     _inherit="account.move.line"
39     _description = "Entry lines"
40
41     def _query_get(self, cr, uid, obj='l', context={}):
42
43         if not 'fiscalyear' in context:
44             context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
45
46         strQuery = ""
47         if context.get('periods', False):
48             ids = ','.join([str(x) for x in context['periods']])
49
50             if not 'period_manner' in context:
51                 strQuery = obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d)" % (context['fiscalyear'],)
52             else:
53                 if context['period_manner']=='actual':
54
55                     strQuery = obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d AND id in (%s))" % (context['fiscalyear'], ids)
56                 else:
57 #                   p_id="in (SELECT id from account_period WHERE fiscalyear_id=%d AND id in (%s)))" % (context['fiscalyear'], ids)
58                     strQuery = obj+".active AND "+obj+".state<>'draft' AND("
59
60                     p_id=self.pool.get('account.period').search(cr,uid,[('fiscalyear_id','=',context['fiscalyear']),('id','in',context['periods'])])
61
62                     periods = self.pool.get('account.period').read(cr,uid,p_id,['date_start','date_stop'])
63
64                     count=1
65                     len_periods=len(p_id)
66
67
68                     for period in periods:
69                         strQuery += "("+obj+".create_date between to_date('" + period['date_start']  + "','yyyy-mm-dd') and to_date('" + period['date_stop']  + "','yyyy-mm-dd'))"
70                         if len_periods!=1 and count!=len_periods:
71                             strQuery+=" OR "
72                             count=count+1
73                     if p_id==[]:
74                         strQuery+=obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d))" % (context['fiscalyear'],)
75                     else:
76                         strQuery+=")"
77         else:
78             strQuery = obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d)" % (context['fiscalyear'],)
79
80         return strQuery
81 account_move_line()
82
83
84 class account_bank_statement_reconcile(osv.osv):
85     _inherit = "account.bank.statement.reconcile"
86     _columns = {
87         'line_ids': fields.many2many('account.move.line', 'account_bank_statement_line_rel', 'statement_id', 'line_id', 'Entries'),
88     }
89 account_bank_statement_reconcile()
90
91
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
93