~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to analytic_distribution_supply/account_commitment.py

  • Committer: jf
  • Date: 2012-04-17 15:29:16 UTC
  • mfrom: (631.3.7 UF_828)
  • Revision ID: jf@tempo4-20120417152916-svm6ioq8ur2bi5tu
UF-955 [DEV] Reporting (Month-end) - 2 remaining reports
lp:~unifield-team/unifield-wm/UF_955

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    _inherit = 'account.commitment.line'
41
41
 
42
42
    _columns = {
43
 
        'purchase_order_line_ids': fields.many2many('purchase.order.line', 'purchase_line_commitment_rel', 'commitment_id', 'purchase_id',
 
43
        'purchase_order_line_ids': fields.many2many('purchase.order.line', 'purchase_line_commitment_rel', 'commitment_id', 'purchase_id', 
44
44
            string="Purchase Order Lines", readonly=True),
45
45
    }
46
46
 
60
60
            for pol in line.purchase_order_line_ids:
61
61
                # browse cost_center line if an analytic distribution exists for this purchase order line
62
62
                if pol.analytic_distribution_id:
63
 
                    origin_cc_lines = pol.analytic_distribution_id.cost_center_lines
64
 
                # else retrieve CC lines from PO
65
 
                else:
66
 
                    origin_cc_lines = pol.order_id.analytic_distribution_id.cost_center_lines
67
 
                # Compute CC lines amounts
68
 
                for aline in origin_cc_lines:
69
 
                    if aline.analytic_id:
70
 
                        # Compute amount regarding pol subtotal and cost_center_line percentage
71
 
                        amount = (pol.price_subtotal * aline.percentage) / 100
72
 
                        cc_lines[(aline.analytic_id.id, aline.destination_id and aline.destination_id.id or False)].append(amount)
 
63
                    for aline in pol.analytic_distribution_id.cost_center_lines:
 
64
                        if aline.analytic_id:
 
65
                            # Compute amount regarding pol subtotal and cost_center_line percentage
 
66
                            amount = (pol.price_subtotal * aline.percentage) / 100
 
67
                            cc_lines[aline.analytic_id.id].append(amount)
73
68
            # Browse result and create corresponding analytic lines
74
69
            if cc_lines:
75
70
                # create distribution an link it to commitment line
76
71
                distrib_id = self.pool.get('analytic.distribution').create(cr, uid, {}, context=context)
77
72
                self.write(cr, uid, [line.id], {'analytic_distribution_id': distrib_id}, context=context)
78
 
                for el in cc_lines:
79
 
                    analytic_id = el[0] or False
 
73
                for analytic_id in cc_lines:
80
74
                    vals = {
81
75
                            'distribution_id': distrib_id,
82
76
                            'analytic_id': analytic_id,
83
77
                            'currency_id': line.commit_id.currency_id.id,
84
 
                            'destination_id': el[1] or False,
85
78
                    }
86
79
                    total_amount = 0.0
87
80
                    # fetch total amount
88
 
                    for amount in cc_lines[el]:
 
81
                    for amount in cc_lines[analytic_id]:
89
82
                        total_amount += amount
90
83
                    if not total_amount:
91
84
                        continue
93
86
                    percentage = (total_amount / line.amount) * 100 or 0.0
94
87
                    vals.update({'percentage': percentage})
95
88
                    # create cost_center_line
96
 
                    self.pool.get('cost.center.distribution.line').create(cr, uid, vals, context=context)
 
89
                    distrib_line_id = self.pool.get('cost.center.distribution.line').create(cr, uid, vals, context=context)
97
90
                # Create funding pool lines if needed
98
 
                self.pool.get('analytic.distribution').create_funding_pool_lines(cr, uid, [distrib_id], line.account_id.id, context=context)
 
91
                self.pool.get('analytic.distribution').create_funding_pool_lines(cr, uid, [distrib_id], context=context)
99
92
        return True
100
93
 
101
94
account_commitment_line()