40
40
_inherit = 'account.commitment.line'
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),
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
for aline in pol.analytic_distribution_id.cost_center_lines:
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)
63
origin_cc_lines = pol.analytic_distribution_id.cost_center_lines
64
# else retrieve CC lines from PO
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:
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)
68
73
# Browse result and create corresponding analytic lines
70
75
# create distribution an link it to commitment line
71
76
distrib_id = self.pool.get('analytic.distribution').create(cr, uid, {}, context=context)
72
77
self.write(cr, uid, [line.id], {'analytic_distribution_id': distrib_id}, context=context)
73
for analytic_id in cc_lines:
79
analytic_id = el[0] or False
75
81
'distribution_id': distrib_id,
76
82
'analytic_id': analytic_id,
77
83
'currency_id': line.commit_id.currency_id.id,
84
'destination_id': el[1] or False,
80
87
# fetch total amount
81
for amount in cc_lines[analytic_id]:
88
for amount in cc_lines[el]:
82
89
total_amount += amount
83
90
if not total_amount:
86
93
percentage = (total_amount / line.amount) * 100 or 0.0
87
94
vals.update({'percentage': percentage})
88
95
# create cost_center_line
89
distrib_line_id = self.pool.get('cost.center.distribution.line').create(cr, uid, vals, context=context)
96
self.pool.get('cost.center.distribution.line').create(cr, uid, vals, context=context)
90
97
# Create funding pool lines if needed
91
self.pool.get('analytic.distribution').create_funding_pool_lines(cr, uid, [distrib_id], context=context)
98
self.pool.get('analytic.distribution').create_funding_pool_lines(cr, uid, [distrib_id], line.account_id.id, context=context)
94
101
account_commitment_line()