haikal/inventory/hooks.py

22 lines
802 B
Python

import logging
from inventory.models import Dealer
from .utils import get_accounts_data,create_account
logger = logging.getLogger(__name__)
def check_create_coa_accounts(task):
logger.info("Checking if all accounts are created")
instance_id = task.args[0]
instance = Dealer.objects.get(pk=instance_id)
entity = instance.entity
coa = entity.get_default_coa()
for account_data in get_accounts_data():
if entity.get_all_accounts().filter(code=account_data["code"]).exists():
logger.info(f"Default account already exists: {account_data['code']}")
continue
logger.info(f"Default account does not exist: {account_data['code']}")
create_account(entity, coa, account_data)
def print_results(task):
print(task.kwargs.get("dealer"))