def allocateFees(self):
items = list(self.invoiceitem_set.all())<EOL>if self.total != sum([x.total for x in items]):<EOL><INDENT>msg = _('<STR_LIT>')<EOL>logger.error(str(msg))<EOL>raise ValidationError(msg)<EOL><DEDENT>if self.adjustments != sum([x.adjustments for x in items]):<EOL><INDENT>msg = _('<STR_LIT>')<EOL>logger.error(str(msg))<EOL>raise ValidationError(msg)<EOL><DEDENT>for item in items:<EOL><INDENT>saveFlag = False<EOL>if self.total - self.adjustments > <NUM_LIT:0>:<EOL><INDENT>item.fees = self.fees * ((item.total - item.adjustments) / (self.total - self.adjustments))<EOL>saveFlag = True<EOL><DEDENT>elif self.total - self.adjustments == <NUM_LIT:0> and self.total > <NUM_LIT:0>:<EOL><INDENT>item.fees = self.fees * (item.total / self.total)<EOL>saveFlag = True<EOL><DEDENT>elif self.fees:<EOL><INDENT>item.fees = self.fees * (<NUM_LIT:1> / len(items))<EOL>saveFlag = True<EOL><DEDENT>if saveFlag:<EOL><INDENT>item.save()<EOL><DEDENT><DEDENT>
Fees are allocated across invoice items based on their discounted
total price net of adjustments as a proportion of the overall
invoice's total price