core.wms

Model.Wms

class anyblok_wms_base.core.wms.Wms[source]

Namespace for WMS related models and transversal methods.

Since this Model does not have any persistent data, making instances of it is mostly irrelevant, and therefore, the transversal methods are classmethods.

Methods

classmethod create_root_container(container_type, **fields)[source]

Helper to create topmost containers.

Topmost containers must have themselves no surrounding container, which means they can’t have Avatars, and therefore can’t be outcomes of any Operations, which is quite exceptional in Anyblok / Wms Base.

On the other hand, at least one such container is needed to root the containing hierarchy.

Parameters:container_type – a PhysObj Type that’s suitable for containers.
Returns:the created container
classmethod quantity(**kwargs)[source]

Compute the quantity of PhysObj meeting various criteria.

This method executes quantity_query() and returns the resulting numeric value.

classmethod quantity_query(goods_type=None, additional_states=None, at_datetime=None, additional_filter=None, location=None, location_recurse=True)[source]

Query computing the quantity of PhysObj meeting various criteria.

The computation actually involves querying Avatars, which hold the information about location, states and date/time.

Returns:

Query object, with only one column (the quantity)

Parameters:
  • goods_type – if specified, restrict computation to PhysObj of this type
  • location – if specified, restrict computation to PhysObj Avatars from that location (see also location_recurse below)
  • location_recurse (bool) – If True, and location is specified, the PhysObj Avatars from sublocations of location will be taken recursively into account.
  • additional_filter

    optional function to restrict the PhysObj Avatars to take into account. It applies to the outer query, i.e., not within the containers recursions.

    The restrict_container_types() and exclude_container_types() provided methods return functions that are meant to be used with this parameter.

    In general, the passed function must have the following signature:

    def additional_filter(query):
       filtered_query = ...
       return filtered_query
    

    where query is a query object involving Avatars.

    See also

    filter_container_types() for a working example.

    Warning

    any JOINs that this function introduces should be aliased to avoid conflicting with the ones already present in query.

  • additional_states

    Optionally, states of the PhysObj Avatar to take into account in addition to the present state.

    Hence, for additional_states=['past'], we have the PhysObj Avatars that were already there and still are, as well as those that aren’t there any more, and similarly for ‘future’.

  • at_datetime

    take only into account PhysObj Avatar whose date-time range contains the specified value.

    anyblok_wms_base.constants.DATE_TIME_INFINITY can in particular be used to consider only those Avatars whose dt_until is None.

    This parameter is mandatory if additional_states is specified.

TODO: provide filtering according to PhysObj properties (should become special PostgreSQL JSON clauses)

TODO: provide a way to add more criteria from optional Bloks, e.g, wms-reservation could add a way to filter only unreserved PhysObj.

TODO PERF: for timestamp ranges, use GiST indexes and the @> operator. See the comprehensive answer to that question for an entry point. Let’s get a DB with serious volume and datetimes first.

classmethod grouped_quantity_query(joined=False, by_location=True, by_type=True, **kwargs)[source]

Build a query to count quantities, grouped by Type and location.

The grouping by location / container is about direct locations, independently of the fact that the query is able to recursively restrict to a given top location.

Parameters:
  • by_location (bool) – controls grouping by location
  • by_type (bool) – controls grouping by type
  • joined (bool) – if True, joins on Wms.PhysObj (for locations) and Wms.PhysObj.Type are performed, so that result columns contain instances of these Models; otherwise, these columns have just ids
  • kwargs – all other keyword arguments are passed to quantity_query()
Returns:

a Query object, whose result columns are: - count - (optionally) location (Wms.PhysObj or id) - (optionally) type (Wms.PhysObj.Type or id)

classmethod filter_container_types(types)[source]

Allow restricting container types in quantity queries.

Returns:a suitable filtering function that restricts the counted Avatars to those whose direct location is of the given types.
classmethod exclude_container_types(types)[source]

Allow restricting container types in quantity queries.

Returns:a suitable filtering function that restricts the counted Avatars to those whose direct location is not of the given types.

Internal methods

.. automethod:: base_quantity_query