Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

Database structure in Lino Tera

This page is a tested document and the following instructions are used for initialization:

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

Complexity factors

>>> print(analyzer.show_complexity_factors())
... 
- 50 plugins
- 101 models
- 4 user types
- 380 views
- 29 dialog actions

Journals overview

>>> rt.show(ledger.JournalsOverview)
... 
**47 Sales invoices (SLS)**
**0 Sales credit notes (SLC)**
**35 Purchase invoices (PRC)**
**4 Bestbank Payment Orders (PMO)**
**0 Cash book (CSH)**
**4 Bestbank (BNK)**
**0 Miscellaneous transactions (MSC)**
**1 Preliminary transactions (PRE)**
**0 Paychecks (SAL)**
**3 VAT declarations (VAT)**

The database models

>>> from lino.utils.diag import analyzer
>>> print(analyzer.show_db_overview())
... 
50 apps: lino, about, ipdict, jinja, bootstrap3, extjs, printing, system, users, contenttypes, gfks, help, office, xl, excerpts, courses, dashboard, countries, contacts, households, clients, healthcare, products, memo, linod, checkdata, weasyprint, uploads, ledger, bevats, vat, trading, cal, calview, invoicing, sepa, finan, ana, sheets, topics, notes, appypod, export_excel, tinymce, tera, teams, lists, search, staticfiles, sessions.
101 models:
=========================== ============================== ========= =======
 Name                        Default table                  #fields   #rows
--------------------------- ------------------------------ --------- -------
 ana.Account                 ana.Accounts                   6         20
 ana.AnaAccountInvoice       ana.Invoices                   20        35
 ana.InvoiceItem             ana.InvoiceItemTable           10        55
 bevats.Declaration          bevats.Declarations            28        3
 cal.Calendar                cal.Calendars                  6         1
 cal.EntryRepeater           cal.EntryRepeaterTable         17        0
 cal.Event                   cal.Events                     27        363
 cal.EventPolicy             cal.EventPolicies              20        6
 cal.EventType               cal.EventTypes                 24        6
 cal.Guest                   cal.Guests                     7         280
 cal.GuestRole               cal.GuestRoles                 6         2
 cal.RecurrentEvent          cal.RecurrentEvents            22        15
 cal.RemoteCalendar          cal.RemoteCalendars            7         0
 cal.Room                    cal.Rooms                      10        0
 cal.Subscription            cal.Subscriptions              4         0
 cal.Task                    cal.Tasks                      17        0
 calview.DailyPlannerRow     calview.DailyPlannerRows       7         2
 checkdata.Message           checkdata.Messages             6         0
 clients.ClientContact       clients.ClientContacts         7         0
 clients.ClientContactType   clients.ClientContactTypes     5         0
 contacts.Company            contacts.Companies             30        30
 contacts.CompanyType        contacts.CompanyTypes          7         16
 contacts.Partner            contacts.Partners              28        105
 contacts.Person             contacts.Persons               35        69
 contacts.Role               contacts.Roles                 4         3
 contacts.RoleType           contacts.RoleTypes             5         5
 contenttypes.ContentType    gfks.ContentTypes              3         101
 countries.Country           countries.Countries            6         10
 countries.Place             countries.Places               9         80
 courses.Course              courses.Activities             44        52
 courses.Enrolment           courses.Enrolments             15        78
 courses.Line                courses.Lines                  25        3
 courses.Slot                courses.Slots                  5         0
 courses.Topic               courses.Topics                 4         0
 dashboard.Widget            dashboard.Widgets              5         0
 excerpts.Excerpt            excerpts.Excerpts              12        0
 excerpts.ExcerptType        excerpts.ExcerptTypes          17        9
 finan.BankStatement         finan.BankStatements           16        4
 finan.BankStatementItem     finan.BankStatementItemTable   9         55
 finan.JournalEntry          finan.FinancialVouchers        14        1
 finan.JournalEntryItem      finan.JournalEntryItemTable    9         4
 finan.PaymentOrder          finan.PaymentOrders            15        4
 finan.PaymentOrderItem      finan.PaymentOrderItemTable    9         32
 healthcare.Plan             healthcare.Plans               4         5
 healthcare.Rule             healthcare.Rules               6         0
 healthcare.Situation        healthcare.Situations          6         0
 households.Household        households.Households          31        6
 households.Member           households.Members             14        12
 households.Type             households.Types               4         6
 invoicing.FollowUpRule      invoicing.FollowUpRules        5         3
 invoicing.Item              invoicing.Items                10        0
 invoicing.Plan              invoicing.Plans                8         1
 invoicing.SalesRule         invoicing.SalesRules           3         6
 invoicing.Tariff            invoicing.Tariffs              8         2
 invoicing.Task              invoicing.Tasks                27        1
 ledger.Account              ledger.Accounts                21        21
 ledger.AccountingPeriod     ledger.AccountingPeriods       7         6
 ledger.FiscalYear           ledger.FiscalYears             5         6
 ledger.Journal              ledger.Journals                26        10
 ledger.LedgerInfo           ledger.LedgerInfoTable         2         0
 ledger.MatchRule            ledger.MatchRules              3         33
 ledger.Movement             ledger.Movements               12        321
 ledger.PaymentTerm          ledger.PaymentTerms            11        8
 ledger.Voucher              ledger.AllVouchers             8         94
 linod.SystemTask        linod.SystemTasks          23        0
 lists.List                  lists.Lists                    7         8
 lists.ListType              lists.ListTypes                4         3
 lists.Member                lists.Members                  5         105
 memo.Mention                memo.Mentions                  5         0
 notes.EventType             notes.EventTypes               8         1
 notes.Note                  notes.Notes                    17        100
 notes.NoteType              notes.NoteTypes                11        3
 products.Category           products.Categories            15        2
 products.PriceRule          products.PriceRules            7         3
 products.Product            products.Products              20        6
 sepa.Account                sepa.Accounts                  6         30
 sessions.Session            users.Sessions                 3         ...
 sheets.AccountEntry         sheets.AccountEntries          7         12
 sheets.AnaAccountEntry      sheets.AnaAccountEntries       7         15
 sheets.Item                 sheets.Items                   9         29
 sheets.ItemEntry            sheets.ItemEntries             7         16
 sheets.PartnerEntry         sheets.PartnerEntries          8         47
 sheets.Report               sheets.Reports                 6         1
 system.SiteConfig           system.SiteConfigs             12        1
 teams.Team                  teams.Teams                    5         2
 tera.Client                 tera.Clients                   45        58
 tera.LifeMode               tera.LifeModes                 4         0
 tera.Procurer               tera.Procurers                 4         0
 tinymce.TextFieldTemplate   tinymce.TextFieldTemplates     5         2
 topics.Interest             topics.Interests               6         86
 topics.Topic                topics.Topics                  8         3
 trading.InvoiceItem         trading.InvoiceItems           15        76
 trading.PaperType           trading.PaperTypes             5         2
 trading.VatProductInvoice   trading.Invoices               27        47
 uploads.Upload              uploads.Uploads                12        7
 uploads.UploadType          uploads.UploadTypes            8         1
 uploads.Volume              uploads.Volumes                5         0
 users.Authority             users.Authorities              3         0
 users.User                  users.AllUsers                 22        6
 vat.InvoiceItem             vat.InvoiceItemTable           9         0
 vat.VatAccountInvoice       vat.Invoices                   20        0
=========================== ============================== ========= =======

Foreign Keys and their on_delete setting

Here is a list of foreign keys in Lino Tera and their on_delete behaviour. See also Customize delete behaviour.

>>> from lino.utils.diag import analyzer
>>> print(analyzer.show_foreign_keys())
... 
- ana.Account :
  - PROTECT : ana.InvoiceItem.ana_account, ledger.Account.ana_account, ledger.Movement.ana_account, sheets.AnaAccountEntry.ana_account
- ana.AnaAccountInvoice :
  - CASCADE : ana.InvoiceItem.voucher
- cal.Calendar :
  - CASCADE : cal.Subscription.calendar
  - PROTECT : cal.Room.calendar, system.SiteConfig.site_calendar
- cal.Event :
  - CASCADE : cal.Guest.event
  - PROTECT : cal.EntryRepeater.cal_entry
- cal.EventType :
  - PROTECT : cal.Event.event_type, cal.EventPolicy.event_type, cal.RecurrentEvent.event_type, courses.Line.event_type, products.PriceRule.selector, system.SiteConfig.default_event_type, users.User.event_type
- cal.GuestRole :
  - PROTECT : cal.Guest.role, courses.Enrolment.guest_role, courses.Line.guest_role, system.SiteConfig.pupil_guestrole
- cal.Room :
  - PROTECT : cal.Event.room, courses.Course.room
- clients.ClientContactType :
  - PROTECT : clients.ClientContact.type, contacts.Partner.client_contact_type
- contacts.Company :
  - PROTECT : cal.Room.company, clients.ClientContact.company, contacts.Role.company, courses.Line.company, excerpts.Excerpt.company, healthcare.Plan.provider, ledger.Journal.partner, notes.Note.company, system.SiteConfig.site_company
- contacts.CompanyType :
  - PROTECT : contacts.Company.type
- contacts.Partner :
  - CASCADE : contacts.Company.partner_ptr, contacts.Person.partner_ptr, courses.Course.partner, households.Household.partner_ptr, invoicing.Item.partner, invoicing.SalesRule.partner, lists.Member.partner, sepa.Account.partner
  - PROTECT : ana.AnaAccountInvoice.partner, bevats.Declaration.partner, clients.ClientContact.client, finan.BankStatementItem.partner, finan.JournalEntryItem.partner, finan.PaymentOrderItem.partner, invoicing.Plan.partner, invoicing.SalesRule.invoice_recipient, ledger.Movement.partner, sheets.PartnerEntry.partner, trading.VatProductInvoice.partner, users.User.partner, vat.VatAccountInvoice.partner
- contacts.Person :
  - CASCADE : tera.Client.person_ptr
  - PROTECT : cal.Guest.partner, cal.Room.contact_person, clients.ClientContact.contact_person, contacts.Role.person, courses.Enrolment.pupil, courses.Line.contact_person, excerpts.Excerpt.contact_person, healthcare.Situation.client, households.Member.person, notes.Note.contact_person
- contacts.RoleType :
  - PROTECT : cal.Room.contact_role, clients.ClientContact.contact_role, contacts.Role.type, courses.Line.contact_role, excerpts.Excerpt.contact_role, notes.Note.contact_role
- contenttypes.ContentType :
  - PROTECT : cal.Event.owner_type, cal.Task.owner_type, checkdata.Message.owner_type, excerpts.Excerpt.owner_type, excerpts.ExcerptType.content_type, invoicing.FollowUpRule.invoice_generator, invoicing.Item.generator_type, memo.Mention.owner_type, memo.Mention.source_type, notes.Note.owner_type, topics.Interest.owner_type, trading.InvoiceItem.invoiceable_type, uploads.Upload.owner_type
- countries.Country :
  - PROTECT : contacts.Partner.country, countries.Place.country, tera.Client.nationality
- countries.Place :
  - PROTECT : contacts.Partner.city, contacts.Partner.region, countries.Place.parent
- courses.Course :
  - CASCADE : topics.Interest.partner
  - PROTECT : cal.Event.project, cal.Task.project, courses.Enrolment.course, excerpts.Excerpt.project, invoicing.Plan.order, notes.Note.project
- courses.Line :
  - PROTECT : courses.Course.line
- courses.Slot :
  - PROTECT : courses.Course.slot
- courses.Topic :
  - PROTECT : courses.Line.topic
- excerpts.Excerpt :
  - SET_NULL : bevats.Declaration.printed_by, courses.Enrolment.printed_by, finan.BankStatement.printed_by, finan.JournalEntry.printed_by, finan.PaymentOrder.printed_by, sheets.Report.printed_by, trading.VatProductInvoice.printed_by
- excerpts.ExcerptType :
  - PROTECT : excerpts.Excerpt.excerpt_type
- finan.BankStatement :
  - CASCADE : finan.BankStatementItem.voucher
- finan.JournalEntry :
  - CASCADE : finan.JournalEntryItem.voucher
- finan.PaymentOrder :
  - CASCADE : finan.PaymentOrderItem.voucher
- healthcare.Plan :
  - PROTECT : courses.Course.healthcare_plan, healthcare.Rule.plan, healthcare.Situation.healthcare_plan
- households.Household :
  - CASCADE : households.Member.household
- households.Type :
  - PROTECT : households.Household.type
- invoicing.Plan :
  - CASCADE : invoicing.Item.plan
- invoicing.Task :
  - CASCADE : invoicing.FollowUpRule.invoicing_task
  - PROTECT : invoicing.Plan.invoicing_task
- ledger.Account :
  - PROTECT : ana.InvoiceItem.account, finan.BankStatement.item_account, finan.BankStatementItem.account, finan.JournalEntry.item_account, finan.JournalEntryItem.account, finan.PaymentOrder.item_account, finan.PaymentOrderItem.account, ledger.Journal.account, ledger.MatchRule.account, ledger.Movement.account, sheets.AccountEntry.account, vat.InvoiceItem.account
- ledger.AccountingPeriod :
  - PROTECT : bevats.Declaration.end_period, bevats.Declaration.start_period, ledger.Voucher.accounting_period, sheets.Report.end_period, sheets.Report.start_period
- ledger.FiscalYear :
  - PROTECT : ledger.AccountingPeriod.year
- ledger.Journal :
  - CASCADE : invoicing.FollowUpRule.source_journal, ledger.MatchRule.journal
  - PROTECT : invoicing.Task.target_journal, ledger.Voucher.journal
- ledger.PaymentTerm :
  - PROTECT : ana.AnaAccountInvoice.payment_term, bevats.Declaration.payment_term, contacts.Partner.payment_term, courses.Course.payment_term, trading.VatProductInvoice.payment_term, vat.VatAccountInvoice.payment_term
- ledger.Voucher :
  - CASCADE : ledger.Movement.voucher
  - PROTECT : ana.AnaAccountInvoice.voucher_ptr, bevats.Declaration.voucher_ptr, finan.BankStatement.voucher_ptr, finan.JournalEntry.voucher_ptr, finan.PaymentOrder.voucher_ptr, trading.VatProductInvoice.voucher_ptr, vat.VatAccountInvoice.voucher_ptr
  - SET_NULL : invoicing.Item.invoice
- lists.List :
  - CASCADE : lists.Member.list
- lists.ListType :
  - PROTECT : lists.List.list_type
- notes.EventType :
  - PROTECT : notes.Note.event_type, system.SiteConfig.system_note_type
- notes.NoteType :
  - PROTECT : notes.Note.type
- products.Category :
  - PROTECT : courses.Line.fees_cat, courses.Line.options_cat, products.Category.parent, products.Product.category
- products.Product :
  - PROTECT : courses.Enrolment.option, courses.Line.fee, healthcare.Rule.client_fee, healthcare.Rule.provider_fee, invoicing.Tariff.product, products.PriceRule.product, trading.InvoiceItem.product, users.User.cash_daybook
- sepa.Account :
  - PROTECT : finan.PaymentOrderItem.bank_account, ledger.Journal.sepa_account
- sheets.Item :
  - PROTECT : ledger.Account.sheet_item, sheets.ItemEntry.item
- sheets.Report :
  - CASCADE : sheets.AccountEntry.report, sheets.AnaAccountEntry.report, sheets.ItemEntry.report, sheets.PartnerEntry.report
- teams.Team :
  - PROTECT : courses.Course.team, users.User.team
- tera.Client :
  - PROTECT : tera.Client.obsoletes
- tera.LifeMode :
  - PROTECT : tera.Client.life_mode
- tera.Procurer :
  - PROTECT : courses.Course.procurer
- topics.Topic :
  - PROTECT : topics.Interest.topic
- trading.PaperType :
  - PROTECT : courses.Course.paper_type, invoicing.SalesRule.paper_type, trading.VatProductInvoice.paper_type
- trading.VatProductInvoice :
  - CASCADE : trading.InvoiceItem.voucher
- uploads.UploadType :
  - PROTECT : uploads.Upload.type
- uploads.Volume :
  - PROTECT : ledger.Journal.uploads_volume, uploads.Upload.volume
- users.User :
  - CASCADE : cal.Subscription.user, ledger.LedgerInfo.user
  - PROTECT : cal.Event.assigned_to, cal.Event.user, cal.RecurrentEvent.user, cal.Task.user, checkdata.Message.user, courses.Course.teacher, courses.Course.user, courses.Enrolment.user, dashboard.Widget.user, excerpts.Excerpt.user, invoicing.Plan.user, invoicing.Task.user, ledger.Voucher.user, notes.Note.user, sheets.Report.user, tera.Client.user, tinymce.TextFieldTemplate.user, uploads.Upload.user, users.Authority.authorized, users.Authority.user
- vat.VatAccountInvoice :
  - CASCADE : vat.InvoiceItem.voucher