Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
12038 Lượt xem

I have posted an entry for checking how it is working. But unfortunately, I haven't changed the currency in my country. Now I wanted to change the currency and it says it can't be changed as I already have posted entries. 

Now I wanted to delete that journal entry. So, please suggest.

Ảnh đại diện
Huỷ bỏ

What Odoo version you are using? If you are using Odoo 15.0 you can reset the journal to draft and delete it. but in Odoo 14 you can't do that.

Tác giả

Thanks for your answer. Unfortunately, I am using Odoo 14 version.

You will not be able to delete them even if you cancelled them you will not be able to change the main currency. You have a lesson learned to not do any test in Live DB.

Tác giả

@Waleed Mohsen thanks for sharing your suggestion for the custom module

Tác giả

@Odoo Mates, thanks for your suggestion. It's really worked with my one entry.

But it isn't working with another entry from the expense app, which I have posted for adding with salary to the payroll.

Please suggest any solution for this.

Câu trả lời hay nhất

@Fahmida Yeasmin

We can edit the posted Journal Entries using write method with context value.(check_move_validity=False)

First cancel the journal entry.

journal_entry_obj.button_cancel()

And Remove the existing line item one2many data and create new records in one2many table in account.move.line. Look at the below code.

for line in journal_entry_obj.line_ids:
# Deleting the line_ids by passing the conlutext value for skipping the crdit and debit validation.
line.sudo().with_context(check_move_validity=False).unlink()
# Updating one2many table data

data_line_dict = {
"move_id": journal_entry_obj.id,
"account_id": account_id,
"partner_id": partner_id,
"name": name,
"debit": debit,
"credit": credit,
"company_id": journal_entry_obj.company_id.id,
"company_currency_id": journal_entry_obj.company_id.currency_id.id,
"currency_id": journal_entry_obj.currency_id.id,
}
self.env['account.move.line'].sudo().with_context(check_move_validity=False).create(data_line_dict)

and finally call the Reset to Draft and Post button

journal_entry_obj.button_draft()
journal_entry_obj.action_post()

It will work.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

In Odoo 14.0 you can't delete them but you can add a customization to override unlink method of account.move model as below, so you can develop a custom module and override unlink method and then install it and delete the journal entries and then uninstall it if you don't need it.


 from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"

def unlink(self):
for move in self:
move.line_ids.unlink()
return models.Model.unlink(self)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
1630
0
thg 1 24
1653
1
thg 11 23
1858
1
thg 9 23
2560
0
thg 3 15
4178