I have a sale.order.line field commission_line that computes the commission amount of the product line.
class SaleOrderlineInherited(models.Model):
_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')
@api.depends('commission_line_percentage')
def get_commission(self):
for record in self:
record['commission_line'] = (record.price_subtotal * record.commission_line_percentage) / 100
return None
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.
class CustommSaleOrder(models.Model):
_inherit = 'sale.order'
commission = fields.Char(string='Total Commission', compute='calculate_total_commission')
def calculate_total_commission(self):
print 'came in'
summ = None
for record in self.env['sale.order.line']:
print 'commission'
summ += record.commission_line_percentage
self.env['sale.order'].commission = summ
return None
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.