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

« back to all changes in this revision

Viewing changes to financing_contract/analytic.py

  • Committer: Olivier DOSSMANN
  • Date: 2014-03-31 09:31:46 UTC
  • mto: This revision was merged to the branch mainline in revision 2086.
  • Revision ID: od@tempo-consulting.fr-20140331093146-tgvxnly1kc1hbv1s
UF-2171 [ADD] Analytic distribution reset button for recurring models

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 _
25
27
 
26
28
class account_analytic_line(osv.osv):
27
29
    _name = 'account.analytic.line'
28
30
    _inherit = 'account.analytic.line'
29
31
 
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:
33
35
            context = {}
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)
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
 
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
42
41
                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
 
        
 
42
                    # Line without domain (consumption, overhead)
 
43
                    raise osv.except_osv(_('No Analytic Domain !'),_("This line does not have an analytic domain!"))
 
44
                    
58
45
        return super(account_analytic_line, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
59
46
 
 
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
    }
60
69
account_analytic_line()
61
70
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: