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

« back to all changes in this revision

Viewing changes to financing_contract/analytic.py

UF-558 [ADD] Copy analytic distribution from invoice to move line and copy invoice header if no analytic distribution is given

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
##############################################################################
23
23
 
24
24
from osv import osv
25
 
import tools
26
 
from tools.translate import _
27
25
 
28
26
class account_analytic_line(osv.osv):
29
27
    _name = 'account.analytic.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 'active_id' in context:
 
35
            if 'active_id' in context and \
 
36
               'reporting_type' in context:
38
37
                donor_line = donor_line_obj.browse(cr, uid, context['active_id'], context=context)
39
 
                if donor_line.analytic_domain:
40
 
                    args += donor_line.analytic_domain
 
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
60
account_analytic_line()