Functional Weave
Code in Rust

hospitality.gross-profit-menu@1.0.0

impl/python/menu_gross_profit.py

1,264 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .finance_margin import margin  ← from finance.margin ^1.0.0 · built alongside by fune
from .finance_tax_remove_vat import remove_vat  ← from finance.tax.remove-vat ^1.0.0 · built alongside by fune
from .hospitality_gross_profit_menu_types import MenuGrossProfit
from .money_amount import Money  ← from money.amount ^1.0.0 · built alongside by fune


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,
    )