addresses : Multiple addresses per partner

The lino_xl.lib.addresses plugin adds functionality and models to handle multiple addresses per lino_xl.lib.contacts.Partner. When this plugin is installed, your application gets a "Manage addresses" button per partner.

A tested document

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

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

Examples

>>> rt.show(addresses.Addresses)
... 
=================================== ==================== ======== ===================================================== ========= ==================
 Partner                             Address type         Remark   Address                                               Primary   Data source
----------------------------------- -------------------- -------- ----------------------------------------------------- --------- ------------------
 Bäckerei Ausdemwald                 Official address              Vervierser Straße 45, 4700 Eupen                      Yes       Manually entered
 Bäckerei Ausdemwald                 Official address              Aachener Straße 1                                     No        Manually entered
 Bäckerei Mießen                     Official address              Gospert 103, 4700 Eupen                               Yes       Manually entered
 Bäckerei Mießen                     Unverified address            Akazienweg 2                                          No        Manually entered
 Arens Andreas                       Official address              Akazienweg, 4700 Eupen                                Yes       Manually entered
 Arens Andreas                       Declared address              Alter Malmedyer Weg 4                                 No        Manually entered
 Arens Annette                       Official address              Alter Malmedyer Weg, 4700 Eupen                       Yes       Manually entered
 Arens Annette                       Reference address             Am Bahndamm 5                                         No        Manually entered
 Ausdemwald Alfons                   Official address              Am Bahndamm, 4700 Eupen                               Yes       Manually entered
 Ausdemwald Alfons                   Obsolete                      Am Berg 7                                             No        Manually entered
 ...
 Denon Denis                         Official address              Paris, France                                         Yes       Manually entered
 Jeanémart Jérôme                    Official address              Paris, France                                         Yes       Manually entered
=================================== ==================== ======== ===================================================== ========= ==================

The primary address is show in the partner's overview field:

>>> obj = contacts.Partner.objects.get(name="Arens Andreas")
>>> print(to_rst(contacts.Partners.request().get_data_value(obj, 'overview')))
See as Organisation, **Partner**, Household
**Arens Andreas**
Akazienweg
4700 Eupen[Manage addresses]

When you click on [Manage addresses] you see:

>>> rt.show(addresses.AddressesByPartner, obj)
... 
================== ======== ======================== =========
 Address type       Remark   Address                  Primary
------------------ -------- ------------------------ ---------
 Official address            Akazienweg, 4700 Eupen   Yes
 Declared address            Alter Malmedyer Weg 4    No
================== ======== ======================== =========
>>> rt.show(addresses.AddressTypes)
======= ============ ====================
 value   name         text
------- ------------ --------------------
 01      official     Official address
 02      unverified   Unverified address
 03      declared     Declared address
 04      reference    Reference address
 98      obsolete     Obsolete
 99      other        Other
======= ============ ====================
>>> rt.show(addresses.DataSources)
======= ========== ==================
 value   name       text
------- ---------- ------------------
 01      manually   Manually entered
 02      eid        Read from eID
======= ========== ==================

Reference

class lino_xl.lib.addresses.Address

Inherits fields from lino_xl.lib.countries.CountryRegionCity (country, region, city. zip_code) and lino_xl.lib.contacts.AddresssLocation (street, street_no, ...)

partner
address_type
data_source

Pointer to DataSources.

Specifies how this information entered into our database.

primary

Whether this address is the primary address of its owner. Setting this field will automatically uncheck any previousl primary addresses and update the owner's address fields.

class lino_xl.lib.addresses.Addresses

Shows all addresses in the database.

class lino_xl.lib.addresses.AddressesByPartner

Shows all addresses of this partner.

class lino_xl.lib.addresses.AddressOwner

Base class for the "addressee" of any address.

class lino_xl.lib.addresses.AddressTypes
class lino_xl.lib.addresses.DataSources
class lino_xl.lib.addresses.AddressOwnerChecker

Checks for the following data problems:

  • Unique address is not marked primary. -- if there is exactly one Address object which just fails to be marked as primary, mark it as primary and return it.

  • Non-empty address fields, but no address record. -- if there is no Address object, and if the Partner has some non-empty address field, create an address record from these, using AddressTypes.official as type.