How works printing in invoice document

hello how the generation of prints in an invoicing because when an invoice printing invoice comes , when credit notes the document name automatically changes to credit note

ERPNext User Manual

Flow Chart Of Transactions In ERPNext
https://frappe.github.io/erpnext/assets/old_images/erpnext/overview.png