22
22
##############################################################################
24
24
from osv import osv
25
from osv import fields
26
from tools.translate import _
26
28
class account_analytic_line(osv.osv):
27
29
_name = 'account.analytic.line'
28
30
_inherit = 'account.analytic.line'
30
def search(self, cr, uid, args, offset=0, limit=None, order=None, context={}, count=False):
32
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
31
33
donor_line_obj = self.pool.get('financing.contract.donor.reporting.line')
32
34
if context is None:
34
36
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)
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."))
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
44
date_domain = eval(donor_line.date_domain)
45
args += [date_domain[0],
47
donor_line_obj._get_account_domain(donor_line)]
48
if context['reporting_type'] == 'allocated':
50
args += [eval(donor_line.funding_pool_domain)]
53
private_funds_id = self.pool.get('account.analytic.account').search(cr, uid, [('code', '=', 'PF')], context=context)
55
args += [('account_id', '!=', private_funds_id),
56
eval(donor_line.cost_center_domain)]
42
# Line without domain (consumption, overhead)
43
raise osv.except_osv(_('No Analytic Domain !'),_("This line does not have an analytic domain!"))
58
45
return super(account_analytic_line, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
47
def _get_fake(self, cr, uid, ids, *a, **b):
48
if isinstance(ids, (int, long)):
50
return {}.fromkeys(ids, False)
52
def _search_contract_open(self, cr, uid, obj, name, args, context):
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.'))
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)]
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."),
60
69
account_analytic_line()
61
70
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: