I have a sale.order.line field commission_line that computes the commission amount of the product line.
_inherit = 'sale.order.line'
commission_line_percentage = fields.Float(related='product_id.product_tmpl_id.commission_percentage')
commission_line = fields.Float(string='Commission', compute='get_commission')
for record in self:
record['commission_line'] = (record.price_subtotal * record.commission_line_percentage) / 100
The above code runs fine. Next I want to calculate all the sum of commission_line fields to get the total commission from the sale.order. I tried this code.
_inherit = 'sale.order'
commission = fields.Char(string='Total Commission', compute='calculate_total_commission')
print 'came in'
summ = None
for record in self.env['sale.order.line']:
summ += record.commission_line_percentage
self.env['sale.order'].commission = summ
This doesn't work. How to correct the code so as to get the sum of all commission_line as the total commission?
Thanks in advance.