Compute sale margin subtotals

This commit is contained in:
Jordi Esteve 2014-08-30 15:16:39 +02:00
parent f84eed597a
commit b3472cd075
1 changed files with 13 additions and 1 deletions

14
sale.py
View File

@ -88,10 +88,22 @@ class SaleLine:
Return the margin of each sale lines
'''
Currency = Pool().get('currency.currency')
currency = self.sale.currency
if self.type == 'line':
cost = Decimal(str(self.quantity)) * (self.cost_price or
Decimal('0.0'))
return Currency.round(self.sale.currency, self.amount - cost)
return Currency.round(currency, self.amount - cost)
elif self.type == 'subtotal':
cost = Decimal('0.0')
for line2 in self.sale.lines:
if line2.type == 'line':
cost2 = Decimal(str(line2.quantity)) * (line2.cost_price or
Decimal('0.0'))
cost += Currency.round(currency, line2.amount - cost2)
elif line2.type == 'subtotal':
if self == line2:
return cost
cost = Decimal('0.0')
else:
return Decimal('0.0')