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

« back to all changes in this revision

Viewing changes to financing_contract/analytic.py

  • Committer: Quentin THEURET
  • Date: 2011-12-12 08:02:59 UTC
  • mto: This revision was merged to the branch mainline in revision 724.
  • Revision ID: qt@tempo-consulting.fr-20111212080259-oul1f0g37hcpubyc
UF-641 [ADD] Added the empty purchase_followup module

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
##############################################################################
23
23
 
24
24
from osv import osv
25
 
from osv import fields
26
 
from tools.translate import _
27
25
 
28
26
class account_analytic_line(osv.osv):
29
27
    _name = 'account.analytic.line'
30
28
    _inherit = 'account.analytic.line'
31
29
 
32
 
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
30
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context={}, count=False):
33
31
        donor_line_obj = self.pool.get('financing.contract.donor.reporting.line')
34
32
        if context is None:
35
33
            context = {}
36
34
        if 'search_financing_contract' in context and context['search_financing_contract']:
37
 
            if 'reporting_line_id' in context and context['reporting_line_id']:
38
 
                donor_line = donor_line_obj.browse(cr, uid, context['reporting_line_id'], context=context)
39
 
                if donor_line.analytic_domain:
40
 
                    args += donor_line.analytic_domain
 
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
41
42
                else:
42
 
                    # Line without domain (consumption, overhead)
43
 
                    raise osv.except_osv(_('No Analytic Domain !'),_("This line does not have an analytic domain!"))
44
 
                    
 
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
        
45
58
        return super(account_analytic_line, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
46
59
 
47
 
    def _get_fake(self, cr, uid, ids, *a, **b):
48
 
        if isinstance(ids, (int, long)):
49
 
            ids = [ids]
50
 
        return {}.fromkeys(ids, False)
51
 
 
52
 
    def _search_contract_open(self, cr, uid, obj, name, args, context):
53
 
        if not len(args):
54
 
            return []
55
 
 
56
 
        if args[0][1] != '=' or not args[0][2]:
57
 
            raise osv.except_osv(_('Warning'), _('Filter contract_open is not implemented with those arguments.'))
58
 
 
59
 
        cr.execute('''select distinct fpline.funding_pool_id 
60
 
                from financing_contract_funding_pool_line fpline
61
 
                left join financing_contract_contract contract on contract.format_id = fpline.contract_id
62
 
                where contract.state in ('soft_closed', 'hard_closed') ''')
63
 
        ids = [x[0] for x in cr.fetchall()]
64
 
        return [('account_id', 'not in', ids)]
65
 
 
66
 
    _columns = {
67
 
        'contract_open': fields.function(_get_fake, type='boolean', method=True, string='Exclude closed contract', fnct_search=_search_contract_open, help="Field used only to search lines."),
68
 
    }
69
60
account_analytic_line()
70
61
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: