from .finance_margin import margin from .finance_tax_remove_vat import remove_vat from .hospitality_gross_profit_menu_types import MenuGrossProfit from .money_amount import Money def menu_gross_profit(cost: Money, menu_price: Money, jurisdiction: str, category: str, on_date: str) -> MenuGrossProfit: """Gross profit on a menu price. Hospitality GP is worked out on the price without VAT, because the VAT is the tax authority's money, not the kitchen's: a 14.50 dish costing 3.50 at 20% VAT is a 71.03% GP, not the 75.86% the VAT-inclusive price suggests. """ if cost.minor < 0: raise ValueError("cost must not be negative, received %d" % (cost.minor,)) if menu_price.minor < 0: raise ValueError("menuPrice must not be negative, received %d" % (menu_price.minor,)) vat = remove_vat(menu_price, jurisdiction, category, on_date) breakdown = margin(cost, vat.net) gp = breakdown.margin_basis_points return MenuGrossProfit( menu_price=menu_price, vat=vat.tax, net_price=vat.net, cost=cost, gross_profit=breakdown.profit, gp_basis_points=gp, cost_basis_points=None if gp is None else 10000 - gp, vat_rate_basis_points=vat.basis_points, )