@@ -123,7 +123,9 @@ def migrate(self):
123
123
ce_txs_gb = groupby (ce_txs , key = lambda k : k .tx_type )
124
124
125
125
# adding DEBITS and CREDITS...
126
- ce_txs_sum = {k : sum (v .balance for v in l ) for k , l in ce_txs_gb }
126
+ ce_txs_sum = {
127
+ k : sum (v .balance for v in l ) for k , l in ce_txs_gb
128
+ }
127
129
128
130
if len (ce_txs_sum ) and ce_txs_sum [TransactionModel .DEBIT ] != ce_txs_sum [TransactionModel .CREDIT ]:
129
131
raise ClosingEntryValidationError (
@@ -170,6 +172,8 @@ def migrate(self):
170
172
for k , je_model in ce_txs_journal_entries .items ():
171
173
je_model .save (verify = True )
172
174
175
+ self .ledger_model .lock (commit = True , raise_exception = True )
176
+
173
177
return ce_txs_journal_entries , ce_je_txs
174
178
175
179
def create_entry_ledger (self , commit : bool = False ):
@@ -178,7 +182,7 @@ def create_entry_ledger(self, commit: bool = False):
178
182
name = f'Closing Entry { self .closing_date } Ledger' ,
179
183
entity_id = self .entity_model_id ,
180
184
hidden = True ,
181
- locked = True ,
185
+ locked = False ,
182
186
posted = True
183
187
)
184
188
ledger_model .clean ()
@@ -195,7 +199,7 @@ def create_entry_ledger(self, commit: bool = False):
195
199
def can_post (self ) -> bool :
196
200
return not self .is_posted ()
197
201
198
- def mark_as_posted (self , commit : bool = False , update_entity_meta : bool = False , ** kwargs ):
202
+ def mark_as_posted (self , commit : bool = False , update_entity_meta : bool = True , ** kwargs ):
199
203
if not self .can_post ():
200
204
raise ClosingEntryValidationError (
201
205
message = _ (f'Closing Entry { self .closing_date } is already posted.' )
@@ -232,11 +236,14 @@ def get_mark_as_posted_url(self, entity_slug: Optional[str] = None) -> str:
232
236
def can_unpost (self ) -> bool :
233
237
return self .is_posted ()
234
238
235
- def mark_as_unposted (self , commit : bool = False , update_entity_meta : bool = False , ** kwargs ):
239
+ def mark_as_unposted (self , commit : bool = False , update_entity_meta : bool = True , ** kwargs ):
236
240
if not self .can_unpost ():
237
241
raise ClosingEntryValidationError (
238
242
message = _ (f'Closing Entry { self .closing_date } is not posted.' )
239
243
)
244
+
245
+ self .ledger_model .unlock (commit = False , raise_exception = True )
246
+ self .ledger_model .save (update_fields = ['posted' , 'locked' , 'updated' ])
240
247
self .posted = False
241
248
242
249
TransactionModel .objects .for_entity (
@@ -311,6 +318,8 @@ def delete(self, **kwargs):
311
318
message = _ ('Cannot delete a posted Closing Entry' )
312
319
)
313
320
321
+ self .ledger_model .unpost (commit = True , raise_exception = True )
322
+
314
323
TransactionModel .objects .for_entity (
315
324
entity_slug = self .entity_model_id
316
325
).for_ledger (ledger_model = self .ledger_model ).delete ()
0 commit comments