Допустимые модели:
ACCOUNT_UNDER = (
('Assets', 'Assets'),
('Bank', 'Bank'),
('Cash-in-Hand', 'Cash-in-Hand'),
)
class Account(MPTTModel):
name = models.CharField(max_length=50, unique=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
under = models.CharField(max_length=100, choices=ACCOUNT_UNDER)
class MPTTMeta:
order_insertion_by = ['name']
class JournalVoucher(models.Model):
date = models.DateField()
class Transaction(models.Model):
voucher = models.ForeignKey(JournalVoucher, on_delete=models.CASCADE, blank=True, null=True)
date = models.DateField(default=datetime.date.today)
class TransactionEntry(models.Model):
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE, blank=True, null=True)
account = models.ForeignKey(Account, on_delete=models.CASCADE, related_name="transaction_entries")
debit = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
credit = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
class Ledger(models.Model):
account_name = models.CharField(max_length=254)
class LedgerEntry(models.Model):
ledger = models.ForeignKey(Ledger, on_delete=models.CASCADE, blank=True, null=True)
date = models.DateField()
account = models.ForeignKey(Account, on_delete=models.CASCADE, related_name="debit_account")
debit = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
credit = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
balance = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
В админке Django,
#using django-nested-admin
from django.contrib import admin
import nested_admin
class TransactionEntryInline(nested_admin.NestedTabularInline):
model = TransactionEntry
extra = 0
class TransactionInline(nested_admin.NestedStackedInline):
model = Transaction
inlines = [TransactionEntryInline]
extra = 0
@admin.register(JournalVoucher)
class JournalVoucherAdmin(nested_admin.NestedModelAdmin):
inlines = [TransactionInline]
Пример учета:
Jan. 10 Creative Advertising obtained a loan of Rs. 20,000 from the bank.
Журнал ваучер
Date Account Debit Credit
Jan 10 Cash 20,000
Bank Loan 20,000
Леджер:
- Банковский кредитный счет
Date Account Amount Date Account Amount
Jan 10 Cash 20,000
Date Account Amount Date Account Amount
Jan 10 Bank Loan 20,000
Проблема
- При сохранении порядка сигналов post_save:
JournalVoucher > Transaction > TransactionEntry
TransactionEntry
может быть наличными или банковским кредитом, но не обоими одновременно в сигнале
- Но для создания бухгалтерской книги необходимы обе записи транзакции, например. на банковском ссудном счете, банке, а также на кассовом счете, необходимы
Цель:
- Я хочу автоматически создавать бухгалтерские книги и соответствующие им записи в журнале при сохранении ваучера