### Installation and Setup Source: https://context7.com/arrobalytics/django-ledger/llms.txt Instructions for installing and setting up Django Ledger in your Django project. ```APIDOC ## Installation and Setup Add Django Ledger to your Django project and configure it properly. ### settings.py ```python # settings.py INSTALLED_APPS = [ # ... other apps 'django_ledger', ] TEMPLATES = [ { 'OPTIONS': { 'context_processors': [ # ... other processors 'django_ledger.context.django_ledger_context', ], }, }, ] ``` ### urls.py ```python # urls.py from django.urls import include, path urlpatterns = [ # ... other urls path('ledger/', include('django_ledger.urls', namespace='django_ledger')), ] ``` ### Migrations ```bash # Run migrations python manage.py migrate ``` ``` -------------------------------- ### Install PipEnv Source: https://github.com/arrobalytics/django-ledger/blob/master/README.md Install or upgrade PipEnv, a dependency management tool for Python. Ensure you have the latest version for consistent environment setup. ```shell pip install -U pipenv ``` -------------------------------- ### Install Django Ledger in settings.py Source: https://context7.com/arrobalytics/django-ledger/llms.txt Add 'django_ledger' to INSTALLED_APPS and include the context processor in TEMPLATES settings. ```python # settings.py INSTALLED_APPS = [ # ... other apps 'django_ledger', ] TEMPLATES = [ { 'OPTIONS': { 'context_processors': [ # ... other processors 'django_ledger.context.django_ledger_context', ], }, }, ] ``` -------------------------------- ### Run Django Development Server Source: https://github.com/arrobalytics/django-ledger/blob/master/README.md Start the Django development server to access your project and Django Ledger. ```shell python manage.py runserver ``` -------------------------------- ### Get All Product Items Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all product items. Optionally converts the result to a Pandas DataFrame if PANDAS_INSTALLED is true. ```python products_qs = entity_model.get_items_products() pd.DataFrame(products_qs.values()) if PANDAS_INSTALLED else products_qs ``` -------------------------------- ### Define Start Date for Transactions Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/DjangoCon2024.ipynb Sets a specific datetime object to be used as the starting point for populating random transaction data. ```python START_DTTM = datetime(year=2022, month=10, day=1, tzinfo=ZoneInfo('UTC')) ``` -------------------------------- ### Get Product Items Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves a queryset of all product items. The results can be converted into a pandas DataFrame. ```python products_qs = entity_model.get_items_products() pd.DataFrame(products_qs.values()) ``` -------------------------------- ### Get All Service Items Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all service items. Optionally converts the result to a Pandas DataFrame if PANDAS_INSTALLED is true. ```python services_qs = entity_model.get_items_services() pd.DataFrame(services_qs.values()) if PANDAS_INSTALLED else services_qs ``` -------------------------------- ### Get Customers Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves all customer records and displays them as a Pandas DataFrame. Assumes `entity_model` is initialized. ```python customer_qs = entity_model.get_customers() pd.DataFrame(customer_qs.values()) ``` -------------------------------- ### Get Customer Query Set Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieve all customers associated with the entity model. Optionally display as a Pandas DataFrame if available. ```python customer_qs = entity_model.get_customers() pd.DataFrame(customer_qs.values()) if PANDAS_INSTALLED else customer_qs ``` -------------------------------- ### Configure and Save InvoiceModel Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Example demonstrating how to instantiate, configure, and save an InvoiceModel. Requires a user model and entity slug. ```python >>> user_model = request.user # django UserModel >>> entity_slug = kwargs['entity_slug'] # may come from view kwargs >>> invoice_model = InvoiceModel() >>> ledger_model, invoice_model = invoice_model.configure(entity_slug=entity_slug, user_model=user_model) >>> invoice_model.save() ``` -------------------------------- ### Get Estimates as DataFrame Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all estimates for an entity and optionally converts them to a Pandas DataFrame if Pandas is installed. ```python estimates_qs = entity_model.get_estimates() pd.DataFrame(estimates_qs.values()) if PANDAS_INSTALLED else estimates_qs ``` -------------------------------- ### Get Entity Bills as DataFrame Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all bills for an entity and optionally converts them to a Pandas DataFrame if Pandas is installed. ```python bills_qs = entity_model.get_bills() pd.DataFrame(bills_qs.values()) if PANDAS_INSTALLED else bills_qs ``` -------------------------------- ### Initialize IO Library Source: https://context7.com/arrobalytics/django-ledger/llms.txt Create an IOLibrary instance to organize related IOBluePrint objects for complex multi-transaction operations. ```python from django_ledger.io.io_library import IOBluePrint, IOLibrary # Create a library to organize related blueprints library = IOLibrary(name='sales-library') ``` -------------------------------- ### Create an IO Library Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Initializes an IO Library instance with a given name. This library will manage blueprints for financial transactions. ```python library = IOLibrary(name='quickstart-library') ``` -------------------------------- ### Get Bank Accounts as DataFrame Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all bank accounts for an entity and optionally converts them to a Pandas DataFrame if Pandas is installed. ```python bank_accounts_qs = entity_model.get_bank_accounts() pd.DataFrame(bank_accounts_qs.values()) if PANDAS_INSTALLED else bank_accounts_qs ``` -------------------------------- ### Get Purchase Orders as DataFrame Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves all purchase orders for an entity and optionally converts them to a Pandas DataFrame if Pandas is installed. ```python purchase_orders_qs = entity_model.get_purchase_orders() pd.DataFrame(purchase_orders_qs.values()) if PANDAS_INSTALLED else purchase_orders_qs ``` -------------------------------- ### Initialize Django and Import Models Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Sets up the Django environment and imports necessary models and utilities for Django Ledger. Ensure DJANGO_SETTINGS_MODULE is correctly configured. ```python import os from datetime import date, datetime from random import randint, choices, random from zoneinfo import ZoneInfo import django # for easier visualization it is recommended to use pandas to render data... # if pandas is not installed, you may install it with this command: pip install -U pandas # pandas is not a dependency of django_ledger... from django.core.exceptions import ObjectDoesNotExist # Set your django settings module if needed... os.environ['DJANGO_SETTINGS_MODULE'] = 'dev_env.settings' # if using jupyter notebook need to set DJANGO_ALLOW_ASYNC_UNSAFE as "true" os.environ['DJANGO_ALLOW_ASYNC_UNSAFE'] = 'true' # change your working directory as needed... # os.chdir('../') django.setup() from django_ledger.models.entity import EntityModel from django_ledger.models.items import ItemModel from django_ledger.models.invoice import InvoiceModel from django_ledger.models.bill import BillModel from django_ledger.models.estimate import EstimateModel from django.contrib.auth import get_user_model from django_ledger.io import roles from django_ledger.io.io_library import IOBluePrint, IOLibrary try: import pandas as pd PANDAS_INSTALLED = True except ImportError: PANDAS_INSTALLED = False ``` -------------------------------- ### Create a Customer Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Create a new customer model with specified details like name and description. ```python customer_model = entity_model.create_customer(customer_model_kwargs={ 'customer_name': 'Mr. Big', 'description': 'A great paying customer!', }) ``` -------------------------------- ### Get Accounts by Codes with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves accounts based on a list of codes from the default chart of accounts and displays them as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_codes_qs = entity_model.get_accounts_with_codes(code_list=['1010', '1050']) pd.DataFrame(coa_accounts_by_codes_qs) ``` -------------------------------- ### Get CoA Accounts by CoA Model with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves accounts for a specific chart of accounts model and displays them as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_coa_model_qs = entity_model.get_coa_accounts(coa_model=default_coa_model) pd.DataFrame(coa_accounts_by_coa_model_qs) ``` -------------------------------- ### Initialize Theme from Local Storage or System Preference Source: https://github.com/arrobalytics/django-ledger/blob/master/django_ledger/templates/django_ledger/layouts/base.html This JavaScript code initializes the theme by checking local storage for a saved theme ('dark' or 'light'). If no saved theme is found, it checks the system's preferred color scheme. The theme is then applied to the document's root element. This script should be placed in the header to ensure the theme is applied early. ```javascript (function () { try { var saved = localStorage.getItem('djl-theme'); var theme; if (saved === 'dark' || saved === 'light') { theme = saved; } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { theme = 'dark'; } else { theme = 'light'; } document.documentElement.setAttribute('data-theme', theme); } catch (e) { document.documentElement.setAttribute('data-theme', 'light'); } })(); ``` -------------------------------- ### Get CoA Accounts by CoA Model Slug with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves accounts for a chart of accounts using its slug and displays them as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_coa_slug_qs = entity_model.get_coa_accounts(coa_model=default_coa_model.slug) pd.DataFrame(coa_accounts_by_coa_slug_qs) ``` -------------------------------- ### Setup Django Environment Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Imports necessary modules and sets up the Django environment. Ensure DJANGO_SETTINGS_MODULE is correctly configured for your project. For Jupyter notebooks, set DJANGO_ALLOW_ASYNC_UNSAFE to 'true'. ```python import os from datetime import date, datetime from decimal import Decimal from random import randint, choices, random from zoneinfo import ZoneInfo import django # for easier visualization it is recommended to use pandas to render data... # if pandas is not installed, you may install it with this command: pip install -U pandas # pandas is not a dependecy of django_ledger... import pandas as pd from django.core.exceptions import ObjectDoesNotExist # Set your django settings module if needed... os.environ['DJANGO_SETTINGS_MODULE'] = 'dev_env.settings' # if using jupyter notebook need to set DJANGO_ALLOW_ASYNC_UNSAFE as "true" os.environ['DJANGO_ALLOW_ASYNC_UNSAFE'] = 'true' # change your working directory as needed... os.chdir('../') django.setup() from django_ledger.models.entity import EntityModel from django_ledger.models.items import ItemModel from django_ledger.models.invoice import InvoiceModel from django_ledger.models.bill import BillModel from django_ledger.models.estimate import EstimateModel from django.contrib.auth import get_user_model from django_ledger.io import roles, DEBIT, CREDIT from django_ledger.io.io_library import IOBluePrint, IOLibrary ``` -------------------------------- ### Get CoA Accounts by CoA Model UUID with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves accounts for a chart of accounts using its UUID and displays them as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_coa_uuid_qs = entity_model.get_coa_accounts(coa_model=default_coa_model.uuid) pd.DataFrame(coa_accounts_by_coa_uuid_qs) ``` -------------------------------- ### Create Product Item Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Use this to create a new product item. Provide the name, UOM model, and item type. ```python product_model = entity_model.create_item_product( name='1/2" Premium PVC Pipe', uom_model=uom_model_ft, item_type=ItemModel.ITEM_TYPE_MATERIAL ) ``` ```python product_model.is_product() ``` -------------------------------- ### Get Default CoA Accounts with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves all accounts associated with the entity's default chart of accounts and displays them as a Pandas DataFrame. Requires pandas to be installed. ```python default_coa_accounts_qs = entity_model.get_default_coa_accounts() pd.DataFrame(default_coa_accounts_qs) ``` -------------------------------- ### Initialize IOLibrary Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/DjangoCon2024.ipynb Initializes the IOLibrary with a given name. This library is used for managing and processing financial transactions. ```python from django_ledger.io.io_library import IOLibrary library = IOLibrary(name='djangocon-2024-library') ``` -------------------------------- ### Get Accounts by Codes for Empty CoA with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Attempts to retrieve accounts by codes from a specified (empty) chart of accounts and displays the result as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_codes_qs = entity_model.get_accounts_with_codes( code_list=['1010', '1050'], coa_model=another_coa_model ) pd.DataFrame(coa_accounts_by_codes_qs) ``` -------------------------------- ### Run Django Ledger Migrations Source: https://context7.com/arrobalytics/django-ledger/llms.txt Apply database migrations for Django Ledger. ```bash # Run migrations python manage.py migrate ``` -------------------------------- ### Get CoA Accounts for Empty CoA with Pandas Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Attempts to retrieve accounts for a specified chart of accounts model (which is empty) and displays the result as a Pandas DataFrame. Requires pandas to be installed. ```python coa_accounts_by_coa_model_qs = entity_model.get_coa_accounts(coa_model=another_coa_model) pd.DataFrame(coa_accounts_by_coa_model_qs) ``` -------------------------------- ### Get CoA Accounts by Explicit CoA Model Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves accounts for a specific Chart of Accounts model. Use this when you have multiple CoAs and need to target one explicitly. The output can be a Django QuerySet or a Pandas DataFrame if pandas is installed. ```python coa_accounts_by_coa_model_qs = entity_model.get_coa_accounts(coa_model=default_coa_model).values('code', 'name', 'role', 'balance_type', 'active', 'locked') pd.DataFrame(coa_accounts_by_coa_model_qs) if PANDAS_INSTALLED else coa_accounts_by_coa_model_qs ``` ```python coa_accounts_by_coa_model_qs = entity_model.get_coa_accounts(coa_model=another_coa_model).values('code', 'name', 'role', 'balance_type', 'active', 'locked') pd.DataFrame(coa_accounts_by_coa_model_qs) if PANDAS_INSTALLED else coa_accounts_by_coa_model_qs ``` -------------------------------- ### Create a Vendor Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Create a new vendor model with specified details like name and description. ```python vendor_model = entity_model.create_vendor(vendor_model_kwargs={ 'vendor_name': 'ACME LLC', 'description': 'A Reliable Vendor!' }) ``` -------------------------------- ### Initialization and Account Filter Source: https://github.com/arrobalytics/django-ledger/blob/master/django_ledger/templates/django_ledger/data_import/import_job_txs.html Initializes the UI by calling updateMatchUI and updateChips, and sets the initial account filter based on the current input value. ```javascript // initialize updateMatchUI(); updateChips(); // Initialize account filter to current query (if any) filterAccountOptions(accountSearchInput ? accountSearchInput.value : ''); }); }); })(); ``` -------------------------------- ### Get Balance Sheet Statement Report Data Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/DjangoCon2024.ipynb Explicitly calls the method to get the report data from a balance sheet statement object. ```python bs_report.get_report_data() ``` -------------------------------- ### Create Customer Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Creates a new customer record with a specified name and description. Uses `customer_model_kwargs` for defining customer attributes. ```python customer_model = entity_model.create_customer(customer_model_kwargs={ 'customer_name': 'Mr. Big', 'description': 'A great paying customer!', }) ``` -------------------------------- ### Get EntityModel QuerySet for User Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Use this to get a filtered QuerySet of EntityModels that the current user has access to. It ensures users only operate on entities they are authorized for. ```python >>> user = request.user >>> entity_model_qs = EntityModel.objects.for_user(user_model=user) ``` -------------------------------- ### Invoice Model Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Details about the InvoiceModel, its purpose, and usage examples. ```APIDOC ## Invoice Model Django Ledger created by Miguel Sanda . Copyright© EDMA Group Inc licensed under the GPLv3 Agreement. This module implements the InvoiceModel, which represents the Sales Invoice/ Sales Invoice/ Tax Invoice/ Proof of Sale which the [`EntityModel`](#django_ledger.models.entity.EntityModel) issues to its customers for the supply of goods or services. The model manages all the Sales Invoices which are issued by the [`EntityModel`](#django_ledger.models.entity.EntityModel). In addition to tracking the invoice amount , it tracks the receipt and due amount. ### Examples ```pycon >>> user_model = request.user # django UserModel >>> entity_slug = kwargs['entity_slug'] # may come from view kwargs >>> invoice_model = InvoiceModel() >>> ledger_model, invoice_model = invoice_model.configure(entity_slug=entity_slug, user_model=user_model) >>> invoice_model.save() ``` ### *class* django_ledger.models.invoice.InvoiceModel(*args, **kwargs) Base Invoice Model from Abstract. #### *exception* DoesNotExist #### *exception* MultipleObjectsReturned ### *class* django_ledger.models.invoice.InvoiceModelAbstract(*args, **kwargs) This is the main abstract class which the InvoiceModel database will inherit from. The InvoiceModel inherits functionality from the following MixIns: > 1. `LedgerWrapperMixIn` > 2. [`PaymentTermsMixIn`](#django_ledger.models.mixins.PaymentTermsMixIn) > 3. [`MarkdownNotesMixIn`](#django_ledger.models.mixins.MarkdownNotesMixIn) > 4. [`CreateUpdateMixIn`](#django_ledger.models.mixins.CreateUpdateMixIn) #### uuid This is a unique primary key generated for the table. The default value of this field is uuid4(). * **Type:** UUID ``` -------------------------------- ### Build and Run Docker Compose Source: https://github.com/arrobalytics/django-ledger/blob/master/README.md Build the Docker image and start the Django Ledger container using Docker Compose. Ensure '0.0.0.0' is added to ALLOWED_HOSTS in settings.py. ```shell docker compose up --build ``` -------------------------------- ### Create a Product Item Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Creates a new product item with a name, unit of measure, and item type. ```python product_model = entity_model.create_item_product( name='1/2" Premium PVC Pipe', uom_model=uom_model_ft, item_type=ItemModel.ITEM_TYPE_MATERIAL ) ``` -------------------------------- ### Get Item Model QuerySet Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Fetches the ItemModelQuerySet eligible for itemization. ```APIDOC ## GET /api/items/eligible ### Description Fetches the ItemModelQuerySet eligible for itemization. ### Method GET ### Endpoint /api/items/eligible ### Response #### Success Response (200) - **ItemModelQuerySet** (object) - A queryset of item models. #### Response Example ```json [ { "id": 1, "name": "Item A", "price": "10.00" }, { "id": 2, "name": "Item B", "price": "20.00" } ] ``` ``` -------------------------------- ### Purchase Order Configuration Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Configures the initial setup for a Purchase Order, associating it with an entity and setting initial values. This method should only be called once per Purchase Order. ```APIDOC ## POST /api/purchase-orders/configure ### Description Configures the initial setup for a Purchase Order, associating it with an entity and setting initial values. This method should only be called once per Purchase Order. ### Method POST ### Endpoint /api/purchase-orders/configure ### Parameters #### Request Body - **entity_slug** (str or EntityModel) - Required - The entity slug or EntityModel to associate the Purchase Order with. - **po_title** (str) - Optional - The title of the purchase order. - **user_model** (User) - Optional - The UserModel making the request to check for QuerySet permissions. - **draft_date** (date) - Optional - The date to set for the draft. - **estimate_model** (EstimateModel) - Optional - The associated estimate model. - **commit** (bool) - Optional - Saves the current PurchaseOrderModel after being configured. Defaults to False. ### Response #### Success Response (200) - **PurchaseOrderModel** (object) - The configured PurchaseOrderModel instance. #### Response Example ```json { "id": 1, "entity_slug": "example-entity", "po_title": "Example PO", "created_at": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### Get Estimate Profit Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the total profit estimate for an estimate. ```python estimate_model.get_profit_estimate() ``` -------------------------------- ### Get Estimate Revenue Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the total revenue estimate for an estimate. ```python estimate_model.get_revenue_estimate() ``` -------------------------------- ### Create an Invoice Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Create a new invoice model, linking it to a customer and setting payment terms. ```python invoice_model = entity_model.create_invoice( customer_model='C-0000000006', terms=InvoiceModel.TERMS_NET_30 ) ``` -------------------------------- ### Get Estimate Cost Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the total cost estimate for an estimate. ```python estimate_model.get_cost_estimate() ``` -------------------------------- ### Prepare Invoice Items Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieve existing invoice item models and prepare a dictionary for updating their details, including unit cost, quantity, and total amount. ```python invoices_item_models = invoice_model.get_item_model_qs() # K= number of items... K = 6 invoice_itemtxs = { im.item_number: { 'unit_cost': round(random() * 10, 2), 'quantity': round(random() * 100, 2), 'total_amount': None } for im in choices(invoices_item_models, k=K) } ``` -------------------------------- ### Get Bill Amount Due Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the amount due for a bill. ```python bill_model.amount_due ``` -------------------------------- ### Get Invoice Amount Due Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the amount due for an invoice. ```python invoice_model.amount_due ``` -------------------------------- ### Get Purchase Order Amount Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the total amount of a purchase order. ```python po_model.po_amount ``` -------------------------------- ### Create Entity Model Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/DjangoCon2024.ipynb Creates a new entity with a specified name, administrator, accrual method, and fiscal year start month. This is a core step for setting up financial tracking. ```python from django_ledger.models.entity import EntityModel ENTITY_NAME = 'One Big Company, LLC' entity_model = EntityModel.create_entity( name=ENTITY_NAME, admin=user_model, use_accrual_method=True, fy_start_month=1 ) entity_model ``` -------------------------------- ### Get Local Time Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/io.md Retrieves the local time, optionally based on a specified timezone. ```APIDOC ## GET /api/get/local_time ### Description Retrieve the local time based on the specified timezone. ### Method GET ### Endpoint /api/get/local_time ### Parameters #### Query Parameters - **tz** (timezone or None) - Optional - The timezone to determine the local time. If None, defaults to the system timezone. ### Response #### Success Response (200) - **datetime** (datetime) - A datetime object representing the calculated local time. #### Response Example { "datetime": "2023-10-27T10:30:00" } ``` -------------------------------- ### Perform Database Migrations Source: https://github.com/arrobalytics/django-ledger/blob/master/README.md Run Django migrations to create the necessary database tables for Django Ledger. ```shell python manage.py migrate ``` -------------------------------- ### Get Income Statement Raw Data Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves the raw data for the income statement. ```python ic_report.get_report_data() ``` -------------------------------- ### Render Action Links with Icons Source: https://github.com/arrobalytics/django-ledger/blob/master/django_ledger/templates/django_ledger/customer/tags/customer_table.html Create clickable links for viewing and updating customer details, each prefixed with an appropriate icon and translated text. ```django [{% icon 'bi:eye' 16 %} {% trans 'View' %}]({{ customer_model.get_detail_url }}) [{% icon 'bi:pencil' 16 %} {% trans 'Update' %}]({{ customer_model.get_update_url }}) ``` -------------------------------- ### Create Vendor Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Creates a new vendor record with a specified name and description. Uses `vendor_model_kwargs` for defining vendor attributes. ```python vendor_model = entity_model.create_vendor(vendor_model_kwargs={ 'vendor_name': 'ACME LLC', 'description': 'A Reliable Vendor!' }) ``` -------------------------------- ### ItemTransactionModel QuerySet Annotation Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Gets an annotated ItemTransactionModelQuerySet with additional average unit cost & revenue. ```APIDOC ## GET /api/item_transactions/annotate ### Description Gets an annotated ItemTransactionModelQuerySet with additional average unit cost & revenue. ### Method GET ### Endpoint /api/item_transactions/annotate ### Query Parameters - **itemtxs_qs** (ItemTransactionModelQuerySet) - Optional - Prefetched ItemTransactionModelQuerySet if any. If None a new queryset will be evaluated. Will be validated if provided. ### Response #### Success Response (200) - **annotated_itemtxs** (ItemTransactionModelQuerySet) - The original and annotated ItemTransactionModelQuerySet. ``` -------------------------------- ### Register a Sale Blueprint Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/DjangoCon2024.ipynb Defines and registers a 'sale_blueprint' with the IOLibrary. This blueprint outlines the debit and credit entries for a sales transaction, including cost of goods sold. ```python from django_ledger.io.io_library import IOBluePrint @library.register def sale_blueprint( sale_amount: Union[int, float, Decimal], contribution_margin_percent: float, description: Optional[str] = None ) -> IOBluePrint: blueprint = IOBluePrint() cogs_amount = (1 - contribution_margin_percent) * sale_amount blueprint.debit(account_code='1010', amount=sale_amount, description=description) blueprint.credit(account_code='4010', amount=sale_amount, description=description) blueprint.credit(account_code='1200', amount=cogs_amount, description=description) blueprint.debit(account_code='5010', amount=cogs_amount, description=description) return blueprint ``` -------------------------------- ### Get Estimate Gross Margin Percentage Source: https://github.com/arrobalytics/django-ledger/blob/master/notebooks/QuickStart Notebook.ipynb Retrieves the gross margin estimate as a percentage for an estimate. ```python estimate_model.get_gross_margin_estimate(as_percent=True) ``` -------------------------------- ### Create and Retrieve Customers Source: https://context7.com/arrobalytics/django-ledger/llms.txt Creates a customer record for generating invoices and tracking receivables. Use this to manage your client base. ```python # Create a new customer customer = entity_model.create_customer(customer_model_kwargs={ 'customer_name': 'ABC Industries', 'description': 'Enterprise client - Net 30 terms', }) # Retrieve customers customers = entity_model.get_customers() for c in customers: print(f"{c.customer_number}: {c.customer_name}") # Get specific customer customer = entity_model.get_customer_by_number('C-0000000001') ``` -------------------------------- ### Get Inventory Items Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/quickstart_notebook.md Retrieves a queryset of all inventory items. The results can be converted into a pandas DataFrame. ```python inventory_qs = entity_model.get_items_inventory() pd.DataFrame(inventory_qs.values()) ``` -------------------------------- ### Account Creation Source: https://github.com/arrobalytics/django-ledger/blob/master/docs/source/models.md Method for creating new AccountModel instances with various configuration options. ```APIDOC ## create_account() ### Description Create a new AccountModel instance, managing parent/child relationships properly. This convenience method ensures correct creation of new accounts, handling the intricate logic needed for maintaining hierarchical relationships between accounts. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Required - Name of the new account entity. - **role** (str) - Required - Role assigned to the account. - **balance_type** (str) - Required - Type of balance associated with the account. Must be either ‘debit’ or ‘credit’. - **is_role_default** (bool) - Optional - Indicates if the account should be the default for its role. Only one default account per role is allowed. Defaults to False. - **locked** (bool) - Optional - Flags the account as locked. Defaults to False. - **active** (bool) - Optional - Flags the account as active. Defaults to True. - **kwargs** (dict) - Optional - Additional attributes for account creation. ### Request Example None ### Response #### Success Response (200) - **AccountModel** ([AccountModel](#django_ledger.models.accounts.AccountModel)) - The newly created AccountModel instance. #### Response Example None ```