Data Models and Customizations
This document covers the schema extensions and doctypes introduced by the
Digital Invoicing app.
Installation and Migration Behavior
After Install
di.install.after_install() creates the custom fields.
After Migrate
di.migrate.after_migrate() re-applies custom fields to keep the ERPNext schema
aligned with the app.
Make sure your site do not have custom fields that are present in
diapp
Core App Doctypes
The app defines these primary doctypes:
DI SettingsDI LogProvinceHS CodeHS UomSale TypeTransaction TypeSRO ScheduleSRO ItemSandbox ScenarioCompany Sale TypeCompany Sandbox ScenarioDI Error Code
DI Settings
DI Settings is the central company configuration doctype.
It stores:
- enable/disable state
- sync mode
- auto-post toggle
- access token
- POS fiscal settings
- company NTN/CNIC, province, and address
- company sale types
- company sandbox scenarios
DI Log
DI Log stores the audit trail for API activity.
Typical fields include:
- title
- document type
- document name
- API type
- status
- FBR invoice number
- payload
- response
- error code
- error message
ERPNext Custom Field Extensions
The app creates custom fields on ERPNext doctypes to collect FBR-specific data.
Customer
- NTN / CNIC
- DI Address
- Province
- Registration Type
- Enable Digital Invoicing
Supplier
- DI Address
- Province
- Registration Type
Company
- FBR settings tab
- company sale type table
Item
- HS Code
- HS UOM
- Sale Type
- SRO item serial number
- SRO schedule number
Sales Invoice
- FBR invoice number
- DI posted flag
- DI posting datetime
- DI invoice type
- QR code storage
- sandbox scenario selector
Sales Invoice Item
- HS Code
- HS UOM
- Sale Type
- SRO serial number
- SRO schedule number
- FED payable
Purchase Invoice
- FBR invoice number
- DI posted flag
- posting datetime
Purchase Invoice Item
- HS Code
Sales Taxes and Charges
- DI tax type
Supported values:
Sales TaxFurther TaxAdvance Tax
POS Profile
- enable FBR integration
- FBR environment
- FBR POS ID
- FBR bearer token
- optional FBR API URL override
Mode of Payment
- FBR payment mode code
Event Hooks That Use the Data Model
The app registers these document event hooks:
Sales Invoice.before_submitPurchase Invoice.before_submitItem.before_saveCompany.before_save
These hooks rely on the custom fields above to validate and build FBR payloads.