~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to financing_contract/analytic.py

[MERGE] Financing Contract

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#-*- encoding:utf-8 -*-
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution
 
6
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
 
7
#    Developer: Olivier DOSSMANN
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU Affero General Public License as
 
11
#    published by the Free Software Foundation, either version 3 of the
 
12
#    License, or (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU Affero General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU Affero General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import osv
 
25
 
 
26
class account_analytic_line(osv.osv):
 
27
    _name = 'account.analytic.line'
 
28
    _inherit = 'account.analytic.line'
 
29
 
 
30
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context={}, count=False):
 
31
        donor_line_obj = self.pool.get('financing.contract.donor.reporting.line')
 
32
        if context is None:
 
33
            context = {}
 
34
        if 'search_financing_contract' in context and context['search_financing_contract']:
 
35
            if 'active_id' in context and \
 
36
               'reporting_type' in context:
 
37
                donor_line = donor_line_obj.browse(cr, uid, context['active_id'], context=context)
 
38
                # project domain
 
39
                if donor_line.computation_type not in ('children_sum', 'analytic_sum'):
 
40
                    raise osv.except_osv(_('Warning !'), _("The line selected has no analytic lines associated."))
 
41
                    return
 
42
                else:
 
43
                    # common domain part
 
44
                    date_domain = eval(donor_line.date_domain)
 
45
                    args += [date_domain[0],
 
46
                             date_domain[1],
 
47
                             donor_line_obj._get_account_domain(donor_line)]
 
48
                    if context['reporting_type'] == 'allocated':
 
49
                        # funding pool lines
 
50
                        args += [eval(donor_line.funding_pool_domain)]
 
51
                    else:
 
52
                        # total project lines
 
53
                        private_funds_id = self.pool.get('account.analytic.account').search(cr, uid, [('code', '=', 'PF')], context=context)
 
54
                        if private_funds_id:
 
55
                            args += [('account_id', '!=', private_funds_id),
 
56
                                     eval(donor_line.cost_center_domain)]
 
57
        
 
58
        return super(account_analytic_line, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
 
59
 
 
60
account_analytic_line()
 
61
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: