Skip to content

Commit

Permalink
[FIX] account: prevent archiving journal used in payment methods
Browse files Browse the repository at this point in the history
You should not be able to archive a journal used in a payment method.

Steps to reproduce:
-------------------
* Go on any journal used in a payment method (e.g. Cash)
* Archive the journal
> Observation: You are still able to use the payment method without the
journal being active

Note:
---------------
Similar fix was done for the point of sale here :
odoo#177751

opw-4070620

closes odoo#180784

X-original-commit: 5722d52
Signed-off-by: Antoine Dupuis (andu) <[email protected]>
Signed-off-by: Robin Engels (roen) <[email protected]>
  • Loading branch information
robinengels committed Sep 19, 2024
1 parent 64bdeed commit d9713b1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addons/account/i18n/account.pot
Original file line number Diff line number Diff line change
Expand Up @@ -14853,12 +14853,21 @@ msgid ""
"have a specific limit on them."
msgstr ""

#. module: account
#. odoo-python
#: code:addons/account/models/account_journal.py:0
#, python-format
msgid ""
"This journal is associated with a payment method. You cannot archive it"
msgstr ""

#. module: account
#. odoo-python
#: code:addons/account/models/company.py:0
msgid "This journal is not restricted"
msgstr ""


#. module: account
#: model:ir.model.fields,help:account.field_account_report_line__hide_if_zero
msgid ""
Expand Down
5 changes: 5 additions & 0 deletions addons/account/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ def _compute_display_name(self):
name = f"{name} ({journal.currency_id.name})"
journal.display_name = name

def action_archive(self):
if self.env['account.payment.method.line'].search_count([('journal_id', '=', self.id)], limit=1):
raise ValidationError(_("This journal is associated with a payment method. You cannot archive it"))
return super().action_archive()

def action_configure_bank_journal(self):
""" This function is called by the "configure" button of bank journals,
visible on dashboard if no bank statement source has been defined yet
Expand Down
19 changes: 19 additions & 0 deletions addons/account/tests/test_account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ def test_account_journal_duplicates(self):

self.assertEqual(sorted(new_journals.mapped("code")), ["GEN1", "OD_BL"], "The journals should be set correctly")

def test_archive_used_journal(self):
journal = self.env['account.journal'].create({
'name': 'Test Journal',
'type': 'sale',
'code': 'A',
})
check_method = self.env['account.payment.method'].sudo().create({
'name': 'Test',
'code': 'check_printing_expense_test',
'payment_type': 'outbound',
})
self.env['account.payment.method.line'].create({
'name': 'Check',
'payment_method_id': check_method.id,
'journal_id': journal.id
})
with self.assertRaises(ValidationError):
journal.action_archive()


@tagged('post_install', '-at_install', 'mail_alias')
class TestAccountJournalAlias(AccountTestInvoicingCommon, MailCommon):
Expand Down

0 comments on commit d9713b1

Please sign in to comment.