LineMaker#

Every co.pl.<kind> and co.bs.<kind> is a line maker. The Line makers pages list the makers of each layout and document the call of each template.

class boki.LineMaker(entity, kind, create)#

Callable that adds line items of one kind to an entity and totals them.

co.pl.<kind> and co.bs.<kind> are line makers, one for each kind in the entity’s layout (co.pl.revenue, co.bs.loan). Calling one books a line of its kind in the entity and returns the new LineItem. The maker keeps every line it created, so the lines of a kind are read back through total, items, opening and total_of. Subtotals such as co.pl.gross_profit are not line makers.

The parameters of a call depend on the kind. Each maker carries the signature and documentation of its template, so inspect.signature(co.bs.loan) and help(co.bs.loan) show the loan parameters.

Parameters:
entityEntity

The entity whose books the lines are added to.

kindstr

Name of the layout kind the maker belongs to, such as "revenue" or "loan".

createCallable[…, LineItem]

Function that books one line from the call’s arguments and returns its LineItem.

Attributes:
entityEntity

The entity that owns the maker.

kindstr

Name of the layout kind, as in co.pl.<kind>.

totalSeries

Sum of the lines’ values in each period, including lines added later. What a line’s value is (a flow or a closing balance) depends on the kind; the template of the kind says which.

Notes

Only the entity creates line makers, when it builds co.pl and co.bs; user code never constructs one. The layout decides which kinds exist: general layouts are in boki.layouts, and a custom Layout gets one maker per Kind it lists.

Examples

Book two revenue lines in a monthly model and read the kind back:

>>> import boki as b
>>> m = b.Model("Makers", start="2027-01", periods=3, step=b.month)
>>> co = m.entity("A", standard=b.IFRS)
>>> product = co.pl.revenue("Product", 100, category="Products")
>>> service = co.pl.revenue("Service", 40, category="Services")
>>> r = m.render()
>>> r.value(co.pl.revenue.total, "2027-02")
140
>>> r.value(co.pl.revenue.total_of(category="Services"), "2027-02")
40
>>> [item.name for item in co.pl.revenue.items]
['Product', 'Service']
__call__(*args, **kwargs)#

Add a line of this kind to the entity’s books and return it.

The accepted parameters, and what the call posts, depend on the kind; the signature and documentation of this maker describe them. The call forwards its arguments unchanged to the kind’s create function.

Parameters:
*argsobject

Positional arguments of the kind’s create function, starting with the line name.

**kwargsobject

Keyword arguments of the kind’s create function.

Returns:
LineItem

The new line. It is also appended to items.

Raises:
TypeError

At construction, if the arguments do not fit the kind; the template of the kind lists each case.

ValueError

At construction, if the arguments are valid in form but not in value, such as a duplicate line name.

UnitError

At construction, if an amount is not in the entity’s currency.

Examples

>>> import boki as b
>>> m = b.Model("Maker call", start="2027-01", periods=2, step=b.year)
>>> co = m.entity("A", standard=b.IFRS)
>>> sales = co.pl.revenue("Product", 100)
>>> sales.name, co.pl.revenue.items == [sales]
('Product', True)
property items#

The lines created through this maker so far, in creation order.

Returns:
list[LineItem]

A new list on every access; changing it does not change the maker.

Examples

>>> import boki as b
>>> m = b.Model("Maker items", start="2027-01", periods=2, step=b.year)
>>> co = m.entity("A", standard=b.IFRS)
>>> product = co.pl.revenue("Product", 100)
>>> service = co.pl.revenue("Service", 40)
>>> [line.name for line in co.pl.revenue.items]
['Product', 'Service']
property opening#

Sum of the lines’ opening balances, for balance-sheet kinds.

Returns:
Series

In each period, the previous period’s closing balance of every line, added up; in the first period, the declared opening balances.

Examples

>>> import boki as b
>>> m = b.Model("Maker opening", start="2027-01", periods=2, step=b.year)
>>> co = m.entity("A", standard=b.IFRS)
>>> co.bs.opening(cash=100)
>>> a = co.bs.receivable("Customer A", opening=50)
>>> c = co.bs.receivable("Customer B", opening=30)
>>> r = m.render()
>>> r.value(co.bs.receivable.opening, "2027")
80
total_of(**filters)#

Sum the lines whose attributes equal the given values.

Parameters:
**filtersobject

attribute=value pairs. A line is included when each named attribute of the LineItem equals the value, such as category="Services" or name="Product". With no filters, every line is included.

Returns:
Series

The sum of the matching lines in each period, including lines added later.

Raises:
AttributeError

At evaluation, if a filter names an attribute that a line does not have.

Examples

>>> import boki as b
>>> m = b.Model("Maker filter", start="2027-01", periods=2, step=b.year)
>>> co = m.entity("A", standard=b.IFRS)
>>> goods = co.pl.revenue("Product", 100, category="Goods")
>>> services = co.pl.revenue("Support", 40, category="Services")
>>> r = m.render()
>>> r.value(co.pl.revenue.total_of(category="Services"), "2027")
40