@@ -116,9 +116,7 @@ def for_user(self, user_model) -> 'ChartOfAccountModelQuerySet':
116116 if user_model .is_superuser :
117117 return self
118118
119- return self .filter (
120- (Q (entity__admin = user_model ) | Q (entity__managers__in = [user_model ]))
121- )
119+ return self .filter ((Q (entity__admin = user_model ) | Q (entity__managers__in = [user_model ])))
122120
123121
124122class ChartOfAccountModelManager (Manager ):
@@ -148,9 +146,7 @@ def get_queryset(self) -> ChartOfAccountModelQuerySet:
148146 filter = Q (accountmodel__depth__gt = 2 ) & Q (accountmodel__active = True ),
149147 ),
150148 # Root-group presence and uniqueness checks:
151- accountmodel_rootgroup__count = Count (
152- 'accountmodel' , filter = Q (accountmodel__role__in = ROOT_GROUP )
153- ),
149+ accountmodel_rootgroup__count = Count ('accountmodel' , filter = Q (accountmodel__role__in = ROOT_GROUP )),
154150 accountmodel_rootgroup_roles__distinct_count = Count (
155151 'accountmodel__role' ,
156152 filter = Q (accountmodel__role__in = ROOT_GROUP_META ),
@@ -161,11 +157,7 @@ def get_queryset(self) -> ChartOfAccountModelQuerySet:
161157 configured = models .Case (
162158 models .When (
163159 Q (accountmodel_rootgroup__count__gte = 1 )
164- & Q (
165- accountmodel_rootgroup__count = F (
166- 'accountmodel_rootgroup_roles__distinct_count'
167- )
168- ),
160+ & Q (accountmodel_rootgroup__count = F ('accountmodel_rootgroup_roles__distinct_count' )),
169161 then = Value (True , output_field = BooleanField ()),
170162 ),
171163 default = Value (False , output_field = BooleanField ()),
@@ -177,7 +169,9 @@ def get_queryset(self) -> ChartOfAccountModelQuerySet:
177169
178170 @deprecated_entity_slug_behavior
179171 def for_entity (
180- self , entity_model : 'Union[EntityModel | str | UUID]' = None , ** kwargs
172+ self ,
173+ entity_model : 'Union[EntityModel | str | UUID]' = None , # noqa: F821
174+ ** kwargs , # noqa: F821
181175 ) -> ChartOfAccountModelQuerySet :
182176 """
183177 Fetches a QuerySet of ChartOfAccountsModel associated with a specific EntityModel & UserModel.
@@ -240,16 +234,10 @@ class ChartOfAccountModelAbstract(SlugNameMixIn, CreateUpdateMixIn):
240234 """
241235
242236 uuid = models .UUIDField (default = uuid4 , editable = False , primary_key = True )
243- entity = models .ForeignKey (
244- 'django_ledger.EntityModel' , verbose_name = _ ('Entity' ), on_delete = models .CASCADE
245- )
237+ entity = models .ForeignKey ('django_ledger.EntityModel' , verbose_name = _ ('Entity' ), on_delete = models .CASCADE )
246238 active = models .BooleanField (default = True , verbose_name = _ ('Is Active' ))
247- description = models .TextField (
248- verbose_name = _ ('CoA Description' ), null = True , blank = True
249- )
250- objects = ChartOfAccountModelManager .from_queryset (
251- queryset_class = ChartOfAccountModelQuerySet
252- )()
239+ description = models .TextField (verbose_name = _ ('CoA Description' ), null = True , blank = True )
240+ objects = ChartOfAccountModelManager .from_queryset (queryset_class = ChartOfAccountModelQuerySet )()
253241
254242 class Meta :
255243 abstract = True
@@ -299,9 +287,7 @@ def configure(self, raise_exception: bool = True):
299287
300288 if len (existing_root_roles ) > 0 :
301289 if raise_exception :
302- raise ChartOfAccountsModelValidationError (
303- message = f'Root Nodes already Exist in CoA { self .uuid } ...'
304- )
290+ raise ChartOfAccountsModelValidationError (message = f'Root Nodes already Exist in CoA { self .uuid } ...' )
305291 return
306292
307293 if ROOT_COA not in existing_root_roles :
@@ -322,9 +308,7 @@ def configure(self, raise_exception: bool = True):
322308 AccountModel .add_root (instance = root_account )
323309
324310 # must retrieve root model after added pero django-treebeard documentation...
325- coa_root_account_model = AccountModel .objects .get (
326- uuid__exact = account_pk
327- )
311+ coa_root_account_model = AccountModel .objects .get (uuid__exact = account_pk )
328312
329313 for root_role in ROOT_GROUP_LEVEL_2 :
330314 if root_role not in existing_root_roles :
@@ -398,9 +382,7 @@ def get_account_root_node(
398382
399383 if account_model .coa_model_id != self .uuid :
400384 raise ChartOfAccountsModelValidationError (
401- message = _ (
402- f'The account model { account_model } is not part of the chart of accounts { self .name } .'
403- ),
385+ message = _ (f'The account model { account_model } is not part of the chart of accounts { self .name } .' ),
404386 )
405387
406388 # Chart of Accounts hasn't been configured...
@@ -412,29 +394,17 @@ def get_account_root_node(
412394 root_account_qs = self .get_coa_root_accounts_qs ()
413395
414396 if account_model .is_asset ():
415- qs = root_account_qs .filter (
416- code__exact = ROOT_GROUP_META [ROOT_ASSETS ]['code' ]
417- )
397+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_ASSETS ]['code' ])
418398 elif account_model .is_liability ():
419- qs = root_account_qs .filter (
420- code__exact = ROOT_GROUP_META [ROOT_LIABILITIES ]['code' ]
421- )
399+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_LIABILITIES ]['code' ])
422400 elif account_model .is_capital ():
423- qs = root_account_qs .filter (
424- code__exact = ROOT_GROUP_META [ROOT_CAPITAL ]['code' ]
425- )
401+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_CAPITAL ]['code' ])
426402 elif account_model .is_income ():
427- qs = root_account_qs .filter (
428- code__exact = ROOT_GROUP_META [ROOT_INCOME ]['code' ]
429- )
403+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_INCOME ]['code' ])
430404 elif account_model .is_cogs ():
431- qs = root_account_qs .filter (
432- code__exact = ROOT_GROUP_META [ROOT_COGS ]['code' ]
433- )
405+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_COGS ]['code' ])
434406 elif account_model .is_expense ():
435- qs = root_account_qs .filter (
436- code__exact = ROOT_GROUP_META [ROOT_EXPENSES ]['code' ]
437- )
407+ qs = root_account_qs .filter (code__exact = ROOT_GROUP_META [ROOT_EXPENSES ]['code' ])
438408 else :
439409 raise ChartOfAccountsModelValidationError (
440410 message = f'Unable to locate Balance Sheet'
@@ -445,9 +415,7 @@ def get_account_root_node(
445415 return qs
446416 return qs .get ()
447417
448- raise ChartOfAccountsModelValidationError (
449- message = 'Adding Root account to Chart of Accounts is not allowed.'
450- )
418+ raise ChartOfAccountsModelValidationError (message = 'Adding Root account to Chart of Accounts is not allowed.' )
451419
452420 def get_non_root_coa_accounts_qs (self ) -> AccountModelQuerySet :
453421 """
@@ -518,13 +486,9 @@ def generate_slug(self, commit: bool = False, raise_exception: bool = False) ->
518486 """
519487 if self .slug :
520488 if raise_exception :
521- raise ChartOfAccountsModelValidationError (
522- message = _ (f'CoA { self .uuid } already has a slug' )
523- )
489+ raise ChartOfAccountsModelValidationError (message = _ (f'CoA { self .uuid } already has a slug' ))
524490 return
525- self .slug = f'coa-{ self .entity .slug [- 5 :]} -' + '' .join (
526- choices (SLUG_SUFFIX , k = 15 )
527- )
491+ self .slug = f'coa-{ self .entity .slug [- 5 :]} -' + '' .join (choices (SLUG_SUFFIX , k = 15 ))
528492
529493 if commit :
530494 self .save (update_fields = ['slug' , 'updated' ])
@@ -569,14 +533,10 @@ def validate_account_model_qs(self, account_model_qs: AccountModelQuerySet):
569533
570534 """
571535 if not isinstance (account_model_qs , AccountModelQuerySet ):
572- raise ChartOfAccountsModelValidationError (
573- message = 'Must pass an instance of AccountModelQuerySet'
574- )
536+ raise ChartOfAccountsModelValidationError (message = 'Must pass an instance of AccountModelQuerySet' )
575537 for acc_model in account_model_qs :
576538 if not acc_model .coa_model_id == self .uuid :
577- raise ChartOfAccountsModelValidationError (
578- message = f'Invalid root queryset for CoA { self .name } '
579- )
539+ raise ChartOfAccountsModelValidationError (message = f'Invalid root queryset for CoA { self .name } ' )
580540
581541 def insert_account (
582542 self ,
@@ -680,9 +640,7 @@ def create_account(
680640 )
681641 account_model .clean ()
682642
683- account_model = self .insert_account (
684- account_model = account_model , root_account_qs = root_account_qs
685- )
643+ account_model = self .insert_account (account_model = account_model , root_account_qs = root_account_qs )
686644 return account_model
687645
688646 # ACTIONS -----
@@ -697,9 +655,7 @@ def unlock_all_accounts(self) -> AccountModelQuerySet:
697655 account_qs .update (locked = False )
698656 return account_qs
699657
700- def mark_as_default (
701- self , commit : bool = False , raise_exception : bool = False , ** kwargs
702- ):
658+ def mark_as_default (self , commit : bool = False , raise_exception : bool = False , ** kwargs ):
703659 """
704660 Marks the current Chart of Accounts instances as default for the EntityModel.
705661
@@ -719,9 +675,7 @@ def mark_as_default(
719675 if not self .can_mark_as_default ():
720676 if raise_exception :
721677 raise ChartOfAccountsModelValidationError (
722- message = _ (
723- f'The Chart of Accounts { self .slug } cannot be marked as default'
724- )
678+ message = _ (f'The Chart of Accounts { self .slug } cannot be marked as default' )
725679 )
726680 return
727681 self .entity .default_coa_id = self .uuid
@@ -752,9 +706,7 @@ def can_deactivate(self) -> bool:
752706 """
753707 return all ([self .is_active (), not self .is_default ()])
754708
755- def mark_as_active (
756- self , commit : bool = False , raise_exception : bool = False , ** kwargs
757- ):
709+ def mark_as_active (self , commit : bool = False , raise_exception : bool = False , ** kwargs ):
758710 """
759711 Marks the current Chart of Accounts as Active.
760712
@@ -767,19 +719,15 @@ def mark_as_active(
767719 """
768720 if self .is_active ():
769721 if raise_exception :
770- raise ChartOfAccountsModelValidationError (
771- message = _ ('The Chart of Accounts is currently active.' )
772- )
722+ raise ChartOfAccountsModelValidationError (message = _ ('The Chart of Accounts is currently active.' ))
773723 return
774724
775725 self .active = True
776726 self .clean ()
777727 if commit :
778728 self .save (update_fields = ['active' , 'updated' ])
779729
780- def mark_as_inactive (
781- self , commit : bool = False , raise_exception : bool = False , ** kwargs
782- ):
730+ def mark_as_inactive (self , commit : bool = False , raise_exception : bool = False , ** kwargs ):
783731 """
784732 Marks the current Chart of Accounts as Active.
785733
@@ -792,9 +740,7 @@ def mark_as_inactive(
792740 """
793741 if not self .is_active ():
794742 if raise_exception :
795- raise ChartOfAccountsModelValidationError (
796- message = _ ('The Chart of Accounts is currently not active.' )
797- )
743+ raise ChartOfAccountsModelValidationError (message = _ ('The Chart of Accounts is currently not active.' ))
798744 return
799745
800746 self .active = False
@@ -846,9 +792,7 @@ def mark_as_inactive_url(self) -> str:
846792 )
847793
848794 def get_coa_list_url (self ):
849- return reverse (
850- viewname = 'django_ledger:coa-list' , kwargs = {'entity_slug' : self .entity_slug }
851- )
795+ return reverse (viewname = 'django_ledger:coa-list' , kwargs = {'entity_slug' : self .entity_slug })
852796
853797 def get_coa_list_inactive_url (self ):
854798 return reverse (
@@ -906,9 +850,7 @@ class Meta(ChartOfAccountModelAbstract.Meta):
906850def chartofaccountsmodel_presave (instance : ChartOfAccountModelAbstract , ** kwargs ):
907851 instance .generate_slug ()
908852 if instance .is_default () and not instance .active :
909- raise ChartOfAccountsModelValidationError (
910- _ ('Default Chart of Accounts cannot be deactivated.' )
911- )
853+ raise ChartOfAccountsModelValidationError (_ ('Default Chart of Accounts cannot be deactivated.' ))
912854
913855
914856@receiver (post_save , sender = ChartOfAccountModel )
0 commit comments