Skip to Content
Menu
This question has been flagged

Hi there,

I am setting up Odoo Accounting. I am using Odoo Online. 
I have thousands of posted entries to delete. Is there a way to do this in one go?
I tried to unreconcile and then delete but Odoo would not let me. It throws an error message saying I cannot delete posted entries.


What works is to go into each entry, then reset as draft and then cancel the journal. 
But it would take me days to go through each entry individually.


Anyone has a better solution?


Thanks a million,

Tom

Avatar
Discard
Best Answer

Hi,
You can write a server action and execute all the operations at once from the tree view.

See: Add Contextual Action Using Server Action To Ease Your Work In Odoo


Steps:
* Enable debug mode
* Navigate to Server action menu under Settings -> Technical
* Create a new server action as shown in below image




* Click Create Contextual Action
* Now refresh and Journal Entry tree view, select the entries to cancel
* From action button click this created action

Used Python Code:


for record in records:

​ if record.state == 'posted':

​ record.button_draft()

​ if record.state == 'draft':

​ record.button_cancel()

Thanks

Avatar
Discard
Author

Thanks a lot @Niyas for the pointers ! Really helped me getting out of a rabbit hole!

Best Answer

For that you can write server action and server action through you can perform this action.
To create server action follow bellow steps:
1. Enable debug mode
2. Navigate to Server action menu under Settings -> Technical
https://tinyurl.com/yn3ut35u
3. Create a new server action as shown in below image
https://tinyurl.com/ytbwv497
4. Click on Create Contextual Action button.
5. Now go to Accounting > Journal Entries and select journal entry which you want to cancel and in action and select "Mass cancel journal entries".

Avatar
Discard
Author Best Answer

Thanks Niyas for the pointer ! 

This is the solution that worked for me. It cancelled thousands of entries in one go.

In serveur actions, create "Mass cancel journal entries" with

* Model : journal entry

* Action : Execute Python code

* Python Code

​for record in records:

​ record.button_draft()

​ record.button_cancel()

* Create contextual action

* In the screen Accounting > Journal Entries, select all the lines I wanted to cancel, press action and select "Mass cancel journal entries"



Avatar
Discard
Related Posts Replies Views Activity
0
Nov 23
1216
1
Jun 22
3890
2
Oct 21
2769
0
Sep 18
2065
0
Aug 24
851