question 268 Inheritance & Composition · medium
An invoice whose lines know their tax
Different products are taxed differently, and the rules change. Each invoice line therefore holds a tax-rule object and asks it for the tax. The rules StandardVat and ZeroRated are given. Write InvoiceLine and Invoice, and an Invoice.summary() that turns the whole invoice into a dictionary.
`InvoiceLine(description, quantity, unit_price, tax_rule)`
net() → quantity × unit price, rounded to 2 places; tax() → tax_rule.tax(net)`Invoice(number, customer_name, lines)`
net(), tax() and gross() add up the lines (each rounded to 2 places)`summary()`
{"number": …, "customer": …, "net": …, "tax": …, "gross": …, "lines": [[description, net, tax], …]}