Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

Cloning (duplicating) database objects

When a database model inherits from Clonable, then Lino adds a 🗗 button in the toolbar, which will clone (duplicate) the selected row, i.e. create a new row as a copy of it.

Clicking the 🗗 button calls the clone_row action. The default behaviour is to copy all fields except the primary key and all related objects that are clonable.

Lino provides several ways to customize what exactly happens during duplication.

For example in an accounting application, when you clone a business partner, you probably also want to clone their contact details, but not their invoices. Or when cloning a registered invoice, you do not want the new invoice to be registered as well.

Two methods Model.on_duplicate() and Model.after_duplicate() are called by lino.mixins.clonable.Clonable.clone_row.

The attributes Model.allow_cascaded_delete and Model.allow_cascaded_copy and

>>> from lino_book.projects.noi1e.startup import *

The output of lino.api.doctest.show_clonables() gives an overview of the rules that apply for clonable objects.

>>> show_clonables()
- accounting.Account
- accounting.Journal : accounting.MatchRule.journal, invoicing.FollowUpRule.source_journal
- accounting.Voucher : accounting.Movement.voucher, storage.Movement.voucher
- calview.DailyPlannerRow
- contacts.Company
- contacts.Partner : invoicing.Item.partner, lists.Member.partner, sepa.Account.partner, trading.TradingRule.partner
- contacts.Person
- countries.Place
- dashboard.Widget
- excerpts.Excerpt
- excerpts.ExcerptType
- invoicing.FollowUpRule
- invoicing.Task : invoicing.FollowUpRule.invoicing_task
- linod.SystemTask
- lists.Member
- periods.StoredPeriod
- products.Category
- products.PriceRule
- products.Product
- storage.DeliveryItem
- storage.DeliveryNote : storage.DeliveryItem.voucher
- storage.TransferRule
- subscriptions.Subscription : subscriptions.SubscriptionItem.voucher
- subscriptions.SubscriptionItem
- tickets.Ticket : nicknames.Naming.named
- trading.InvoiceItem
- trading.VatProductInvoice : trading.InvoiceItem.voucher
- vat.InvoiceItem
- vat.VatAccountInvoice
- working.ReportingRule