clients : Manage clients and client contacts

The lino_xl.lib.clients plugin adds the notions of clients and client contacts.

A tested document

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

>>> import lino
>>> lino.startup('lino_book.projects.avanti1.settings.doctests')
>>> from lino.api.doctest import *
>>> from django.db.models import Q

Database structure

class lino_xl.lib.clients.ClientContactBase

Also used by aids.RefundPartner.

class lino_xl.lib.clients.ClientBase

Base class for a client. The model specified as client_model must implement this.

client_state

Pointer to ClientStates

class lino_xl.lib.clients.ClientStates

The list of client states.

>>> rt.show(clients.ClientStates)
... 
======= ========== ============ =============
 value   name       text         Button text
------- ---------- ------------ -------------
 05      incoming   Incoming
 07      informed   Informed
 10      newcomer   Newcomer
 20      coached    Registered
 25      inactive   Inactive
 30      former     Ended
 40      refused    Abandoned
======= ========== ============ =============
class lino_xl.lib.clients.ClientEvents

The list of observable client events.

>>> rt.show(clients.ClientEvents)
========== ========== ==========
 value      name       text
---------- ---------- ----------
 created    created    Created
 modified   modified   Modified
 note       note       Note
========== ========== ==========
created

Select clients whose record has been created during the observed period.

modified

The choice for ClientEvents which selects clients whose main record has been modified during the observed period.

class lino_xl.lib.clients.ClientContacts
class lino_xl.lib.clients.ClientContact

A client contact is when a given partner has a given role for a given client.

client

The Client.

type

The type of contact. Pointer to ClientContactType.

company

The organization.

contact_person

The contact person in the organization.

contact_role

The role of the contact person in the organization.

class lino_xl.lib.clients.ClientContactTypes
class lino_xl.lib.clients.ClientContactType

A client contact type is the type or "role" which must be specified for a given ClientContact.

can_refund

Whether persons of this type can be used as doctor of a refund confirmation. Injected by lino_welfare.modlib.aids.

class lino_xl.lib.clients.PartnersByClientContactType

Known contact types

class lino_xl.lib.clients.KnownContactType
class lino_xl.lib.clients.KnownContactTypes

The clients plugin also adds a choicelist of known contact types.

>>> rt.show(clients.KnownContactTypes)
======= ================== ================================== ==================================
 value   name               text                               Client Contact type
------- ------------------ ---------------------------------- ----------------------------------
 10      health_insurance   Health insurance                   Health insurance
 20      school             School                             School
 30      pharmacy           Pharmacy                           Pharmacy
 40      social_center      Public Center for Social Welfare   Public Center for Social Welfare
 60      work_consultant    Work consultant                    Work consultant
======= ================== ================================== ==================================

A known contact type is a named pointer to a corresponding client contact type object in the database. The database object itself may exist or not. This enables us to programmatically work with a given client contact type. Since contact types are database objects, it can be anything or nothing for a given site. By using known contact type we can access them.

For example here are the partners having the client contact type "school":

>>> obj = clients.KnownContactTypes.school.get_object()
>>> rt.show(clients.PartnersByClientContactType, obj)
================== ===== ================================
 Name               ID    See as
------------------ ----- --------------------------------
 Best School        184   **Partner**, Person, Household
 Favourite School   183   **Partner**, Person, Household
================== ===== ================================

Here are the actual client contacts of that type:

>>> rt.login('robin').show(clients.ClientContactsByType, obj)
================== ================ ========================== =========
 Organization       Contact person   Client                     Remarks
------------------ ---------------- -------------------------- ---------
 Favourite School                    ABDALLA Aádil (120)
 Best School                         ABED Abdul Báári (159)
 Favourite School                    ARSHUN Aloyoshenká (135)
 Best School                         BERENDT Antoshá (165)
 Favourite School                    FALL Dembe (145)
================== ================ ========================== =========

Configuration

See lino_xl.lib.clients.Plugin

Injects

The lino_xl.lib.clients plugin injects the following fields into models of other plugins.

class contacts.Partner
client_contact_type

Setting this field on a partner makes this partner available as a client contact.