def sales_payment_summary():
def value_or_zero(aggregate, key):<EOL><INDENT>return aggregate[key] or <NUM_LIT:0><EOL><DEDENT>def sum_amount(payment_set):<EOL><INDENT>a = payment_set.values("<STR_LIT>").aggregate(total=Sum("<STR_LIT>"))<EOL>return value_or_zero(a, "<STR_LIT>")<EOL><DEDENT>headings = ["<STR_LIT>", "<STR_LIT>"]<EOL>data = []<EOL>sales = commerce.LineItem.objects.filter(<EOL>invoice__status=commerce.Invoice.STATUS_PAID,<EOL>).values(<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>).aggregate(<EOL>total=Sum(F("<STR_LIT>") * F("<STR_LIT>"), output_field=CURRENCY()),<EOL>)<EOL>sales = value_or_zero(sales, "<STR_LIT>")<EOL>all_payments = sum_amount(commerce.PaymentBase.objects.all())<EOL>all_credit_notes = <NUM_LIT:0> - sum_amount(commerce.CreditNote.objects.all())<EOL>unclaimed_credit_notes = <NUM_LIT:0> - sum_amount(commerce.CreditNote.unclaimed())<EOL>claimed_credit_notes = sum_amount(<EOL>commerce.CreditNoteApplication.objects.all()<EOL>)<EOL>refunded_credit_notes = <NUM_LIT:0> - sum_amount(commerce.CreditNote.refunded())<EOL>data.append(["<STR_LIT>", sales])<EOL>data.append(["<STR_LIT>", all_payments])<EOL>data.append(["<STR_LIT>", sales - all_payments])<EOL>data.append(["<STR_LIT>", all_credit_notes])<EOL>data.append(["<STR_LIT>", claimed_credit_notes])<EOL>data.append(["<STR_LIT>", refunded_credit_notes])<EOL>data.append(["<STR_LIT>", unclaimed_credit_notes])<EOL>data.append([<EOL>"<STR_LIT>",<EOL>all_credit_notes - claimed_credit_notes -<EOL>refunded_credit_notes - unclaimed_credit_notes<EOL>])<EOL>return ListReport("<STR_LIT>", headings, data)<EOL>
Summarises paid items and payments.