products : defining the things you sell and buy

The lino_xl.lib.products plugin adds functionality for managing "products".

A tested document

This is a tested document. The following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_book.projects.apc.settings.doctests')
>>> from lino.api.doctest import *

Overview

product

Something you can trade (e.g. sell, buy, rent) in an item of a trade document. Mostly a name and a price. It can be material (a good) or immaterial (a service).

The lino_xl.lib.sales plugins injects a sales_price field to the product model.

Products can be grouped into categories, and every product must be of a given product type.

product category

A group of products that fit together.

The list of product categories of a site can be modified by its end users (provided they have access rights).

product type

A name for the nature or type of a set of products.

Used for example to differentiate between "Services" and "Goods".

The detail layout of a product can vary depending on its type, but not depending on its category.

Every application has its specific list of product types. This list can be locally modified by the site maintainer.

Rule of thumb: product categories can get edited by end users while product types are hard-coded by the application developer.

price factor

A property of a partner that may influence the price of certain products.

The list of price factors is meant to be defined by the application developer. Changing it locally would also require changes in the some layouts. Changes to this list may require a database migration because every price factor causes a field to be injected to the lino_xl.lib.contats.Partner model.

price rules

A set of rules that specify which product to use for a given price selector and a given set of price factors.

price selector

A database object used to specify "what is being sold" in price rules.

In Lino Voga and Lino Presto we use the calendar entry type as price selector, in Lino Noi the lino_xl.lib.working.SessionType.

Products

class lino_xl.lib.products.Product

Django model to represent a product.

description

The description of this product.

This is a BabelField, so there will be one field for every language defined in lino.core.site.Site.languages.

product_type

The type of this product.

This field may not be blank and must be an item of ProductTypes.

The default value is set by the actor used for creating the product. Some product actors don't have a default product type, in that case the default value is ProductTypes.default.

cat

The category of this product.

This is a pointer to ProductCat, but the selection list is limited to thos categories having the same product_type.

delivery_unit

Pointer to DeliveryUnits

vat_class

The VAT class. Injected by lino_xl.lib.vat. If that plugin is not installed, vat_class is a dummy field.

get_ruled_price(self, partner, selector)

Return the product to use for this partner and this selector according to the price rules.

class lino_xl.lib.products.Products

Base class for all tables of products.

>>> rt.show(products.Products)  
==== ================================================================ ================================================================ ================================================================ ================= ===============
 ID   Bezeichnung                                                      Bezeichnung (fr)                                                 Bezeichnung (en)                                                 Kategorie         Verkaufspreis
---- ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ----------------- ---------------
 9    Bildbearbeitung und Unterhalt Website                            Traitement d'images et maintenance site existant                 Image processing and website content maintenance                 Website-Hosting   25,00
 10   Book                                                             Book                                                             Book                                                             Sonstige          29,90
 6    EDV Konsultierung & Unterhaltsarbeiten                           ICT Consultation & maintenance                                   IT consultation & maintenance                                    Website-Hosting   30,00
 8    Programmierung                                                   Programmation                                                    Programming                                                      Website-Hosting   40,00
 7    Server software installation, configuration and administration   Server software installation, configuration and administration   Server software installation, configuration and administration   Website-Hosting   35,00
 11   Stamp                                                            Stamp                                                            Stamp                                                            Sonstige          1,40
 2    Stuhl aus Holz                                                   Chaise en bois                                                   Wooden chair                                                     Möbel             99,99
 4    Stuhl aus Metall                                                 Chaise en métal                                                  Metal chair                                                      Möbel             79,99
 1    Tisch aus Holz                                                   Table en bois                                                    Wooden table                                                     Möbel             199,99
 3    Tisch aus Metall                                                 Table en métal                                                   Metal table                                                      Möbel             129,99
 5    Website-Hosting 1MB/Monat                                        Hébergement 1MB/mois                                             Website hosting 1MB/month                                        Website-Hosting   3,99
                                                                                                                                                                                                                           **675,25**
==== ================================================================ ================================================================ ================================================================ ================= ===============

Product categories

Product categories can be used to group products into "categories". Categories can be edited by the user via Configure ‣ Products ‣ Categories or Configure ‣ Sales ‣ Categories.

>>> show_menu_path(products.ProductCats)
Konfigurierung --> Verkauf --> Produktkategorien
class lino_xl.lib.products.ProductCat

Django model to represent a product category.

product_type

The product type to apply to products of this category.

>>> rt.show(products.ProductCats)
==== ================= =============================== ================== ============== =============
 ID   Bezeichnung       Bezeichnung (fr)                Bezeichnung (en)   Product type   description
---- ----------------- ------------------------------- ------------------ -------------- -------------
 1    Möbel             Meubles                         Furniture          Produkte
 2    Website-Hosting   Hébergement de sites Internet   Website Hosting    Produkte
 3    Sonstige          Autre                           Other              Produkte
==== ================= =============================== ================== ============== =============

Product types

Products can be differentiated by their "type". Types cannot be edited by the user. But every product type can have a layout on its own. Every product type has its own menu entry.

class lino_xl.lib.products.ProductType
text

The verbose name of this product type.

This string is used for the menu entries in Configure ‣ Products.

table_name

The name of the table to use for displaying a list of products with this type.

class lino_xl.lib.products.ProductTypes

The list of product types.

It should contain at least one item whose name is default.

For each item of this list the plugin adds one menu entry to the Configure menu.

default

The product type to be set on new products when they are created in an actor that doesn't have a default product type.

>>> rt.show(products.ProductTypes)
====== ========= ========== ===================
 Wert   name      Text       Table name
------ --------- ---------- -------------------
 100    default   Produkte   products.Products
====== ========= ========== ===================
class lino_xl.lib.products.DeliveryUnits

The list of possible delivery units of a product.

>>> rt.show(products.DeliveryUnits)
====== ======= =======
 Wert   name    Text
------ ------- -------
 10     hour    Hour
 20     piece   Piece
 30     kg      Kg
====== ======= =======

Price rules

Price rules can be used to define which products are available for a given partner, and optionally to find a default product for a given price selector.

class lino_xl.lib.products.PriceFactors

The choicelist of price factors.

This list is empty by default. See Lino Tera or Lino Presto for examples of applications that use price factors.

>>> rt.show(products.PriceFactors)
Keine Daten anzuzeigen
class lino_xl.lib.products.PriceRule
seqno

The sequence number of this rule. Lino loops over price rules in this order and returns the first one that applies.

product

The product to use for getting the price when this rule applies.

selector

Either None or an additional selector for this price rule.

When given, this must be an instance of lino_xl.lib.products.Plugin.price_selector.

Every price rule also has one automatic field for each price factor.

class lino_xl.lib.products.PriceRules

The list of price rules.

>>> rt.show(products.PriceRules)
Keine Daten anzuzeigen