# V1 Week Finale # Accounting analysis / Bookkeeping ###### tags: `OneLeap v1` # Concepts Definition: Recording money flow from one entity to another ## Stages 1. Enter records of financial nature 2. Analize the financial records based on Accounts and assiciates (Customers, Suppliers .. etc) * Movables - Account, Customer, Supplier, Curiour, Transporter, Partner, .. etc 4. Extract financial reports and lists ```python= class MovableMixin(models.Model): class Meta: abstract = True # stock_activity # customer # supplier # employee # inventory # freight # project # cost_center # profit_center class AbstractLeg(IntEntity, MovableMixin): account = models.ForeignKey('accounting.Account', verbose_name='الحساب', related_name='legs', on_delete=models.CASCADE) transaction = models.ForeignKey('accounting.Transaction', verbose_name='السند', related_name='legs', on_delete=models.CASCADE) amount = MoneyField( max_digits=defaults.MAX_DIGITS, decimal_places=defaults.DECIMAL_PLACES, default_currency=defaults.DEFAULT_CURRENCY, verbose_name='المقدار', blank=True, ) is_posted = models.BooleanField('حالة الترحيل', default=False) memo = models.TextField(default='', blank=True, verbose_name='البيان') type = models.CharField('نوع القيد', max_length=255, choices=Transaction.TransactionTypeChoices.choices, null=True, blank=True) date = models.DateTimeField('تأريخ القيد', default=timezone.now, null=True, blank=True) ``` ## types of accounts There are two types of accounts: * Real accounts: (Assets, Liabilities) * Virtual accounts: (Income, Expenses) ## Types of expenses * Cost: all expeses made to support an asset * Expense: all expenses made with/without supporting assets * Loss: all expenses made without benefits * Capital expenses: Fixed assets expenses (Purchases to support the business) ## process * Document Lifecycle * When and How does the document starts * When and How does the document ends * Determin whether the document should include financial records, inventory records, or both! * Accounting analysis / Bookkeeping * What types of records should be listed, whether financial or inventory * To determin what records should be added financially * Supportive documents * All documents that supports the original document, which represents a component of its lifecycle * eg. PaymentRecord, ExpenseRecord, CostRecord, CreditNote, DebitNote, .. etc * Movables * are accounts, each account is a combination of multiple sources of money movement, each account is a true real actual category, and muliple combinations of account movables (Customer, Supplier, Employee, Cost center, etc) # Types of Documents Lifecycle > *Purchase, Sales, Inventory: Are part of the SCM* > *Income, Expenses, Bill, Invoice, PayrollSlip: Are part of the ACCOUNTING* > *Payroll, HR: Is part of HCM* > *DMS* > There are three types of records that generate Legs, which could be included inside Transactions: StockActivity, AssetLine, PayrollLine ## Purchase cycle * Purchase requisition * Initiator * Approval workflow * StockActivity - uncommitted items * Next step - purchase order * Purchase order * Initiator * Approval workflow * StockActivity - uncommitted items * Supplier * Next step - Bill * Upfront payment * Purchase Bill * Initiator * Approval workflow * StockActivity - uncommitted items -> Vendor * Supplier * Curiour * Extra * Earned discount * Debit note * Next step - Inventory takein * Settlement - ExpenseRecord - Legs ## Sales cycle * Sales qoutation * Initiator * Approval workflow * StockActivity - uncommitted items * Customer * Sales rep - optional * Next step - Sales Order * Sales Order * Initiator * Approval Workflow * StockActivity - uncommitted items * Customer * Sales rep - optional * Next step - Sales Invoice * Unfront payment * Sales Invoice * Initiator * Approval Workflow * StockActivity - uncommitted items * Customer * Curiour * Extra * Allowed discount * Credit note * Sales rep - optional * Next step - Inventory takeout * Settlement - PaymentRecord - Legs ## POS Sales * POS invoice * POS bill ## Inventory cycle * Inventory takein * Initiator * Approval workflow - automatic * Stockactivity - committed -> Vendor * Supplier * Curiour * Next step - None * Settlement already done, ExpenseRecords already done, Legs already posted, DONE * Inventory takeout * Initiator * Approval workflow - automatic * StockActivity - committed * Customer * Curiour * Next step - None * Settlement already done, PaymentRecord already done, Legs already posted, DONE * Inventory damage * Initiator * Approval workflow - approval committee * Disposal mechanism * Disposal expenses - ExpenseRecord * Next step - None * Disposal accounts - cost centers, accounts, records (Legs), extra cost * Inventory transfer * Initiator * Approval workflow * From inventory, To inventory * Accounts - from -> to * Next step - None * Extra expenses - curiour, loading unloading costs * Combination of two notes, Inventory Takein, Inventory Takeout * Inventory adjustment * Inventory * Inventory adjustment increase * Inventory adjustment decrease * Initator * Approval workflow - committee * On single inventory level, and combines with other inventories to produce general inventory adjustment report * Accounts, records the increase or dicrease in invetory levels * StockActivity which is either increase or dicrease, committed * Asset requisition * Initiator * Approval workflow * AssetLine - uncommitted items * Next step - Asset order * Asset order/Bill/Takein * Initiator * Approval workflow * AssetLine - uncommitted items -> committed items - Vendor * Supplier * Next step - Bill * Upfront payment * Settlements * Extra * Earned discount * Debit note * Next step - None * Asset write-off * Depriciation until write off * Asset purchase ## Income cycle * Payment record * Debit Memo * Loan interest ## Expense cycles * Credit Memo * Payroll Slip * Expenses ## Ledger cycle * --SPLIT-- records # Special care for ## Workflow module Basically it is the logic that defines who can do what and when ## Workflow * relationship with workflow assiciates (Transaction) * depends on the State of the associate * is_template * steps - reverse relationship to Step * step permissions * is_mandatory ## Step * permitted position * step name * step target * is_approved ### approval template doesn't exist - Transaction Created -> state DRAFT - Mid states are irrelivant - Transaction finalization (POSTING) ### approval template exists - Transaction Created -> state DRAFT - step 1 -> state PENDING - step n -> state PENDING - step final -> state NEW - Transaction Uapproved by last or mid approved step - step n -> state PENDING - step n -> unapprove all upper steps - Transaction Uapproved by first step - same as mid step -> state DRAFT - Transaction finalization (POSTING) ## Subscription module * Recurring Transaction (PayrollSlip, Invoice, etc) * Recurring Leg (PayrollLine, StockActivity, AssetLine which inclues depreciation records, ) ### examples * Recurring invoice (Subscription) -> Invoice * Recurring debits (Installments) -> Installment * Recurring Payroll (PaySlips) -> PaySlip ### rules * you identify the upcoming event, but don't execute the operation (optional) * the main subscription operation is cloning of a current transaction that should have a recurring event * some operation should have a time/value limit * we should have an option to pre-create the upcoming events ```python= class Subscription(IntEntity): name description start_date end_date tags grace_period period = ['daily', 'weekly', 'monthly', 'yearly'] unit = ['time', 'value'] time_based = checkbox value_based = checkbox type = ['once', 'periodic'] # in case of running once, end_date should be set to today recurrence_cost = max_value depletion_cost = min_value should_execute = bool pre_create = bool callable = what to call def is_expired(self): return if the subscription end_date passed today date def force_expire(self): sets the end_date to today def type_of(self): return the type def validate_periodic(self): if periodic is selected, check that period and at least start_date are set def validate_time(self): if time is selected, check that start_date and end_date and period are set def validate_value(self): check at least recurrence_cost or depletion_cost are set def subscribers(self): return all subscribers within categories, returns the upcoming events invoice deprecition payslip installment bill def global_validator(self): performs all global validations def depletion_limit(self, value): if validate_value(): return whether the depletion_cost has been reached or not def recurrence_limit(self, value): return whether the recurrence_cost has been reached or not ``` Depreciation: * initial value: 20,000 USD * current value * cumulative value * min_value: 10,000 USD * depreciation value: 10% * depreciation period: 5 years * depreciation subscription * periodic: montly|yearly * unit: value * depletion_cost: start: initial -> ends: min_value * types: * linear * non-linear * regressive Invoice: * subscription: * periodic: weekly|monthly|yearly * unit: time * when to expire