From 288e9dd7ea93e6718694919694d75de49be400a2 Mon Sep 17 00:00:00 2001 From: Quentin Mondot Date: Thu, 21 Aug 2025 18:29:16 +0200 Subject: [PATCH] [IMP] account_advanced_protection_features: be able to manage prevent_reset_to_draft_sent_invoice option in sale journals --- .../__manifest__.py | 1 + .../models/__init__.py | 3 ++- .../models/account_journal.py | 6 ++++++ .../models/account_move.py | 2 +- .../views/account_journal_views.xml | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 account_advanced_protection_features/models/account_journal.py create mode 100644 account_advanced_protection_features/views/account_journal_views.xml diff --git a/account_advanced_protection_features/__manifest__.py b/account_advanced_protection_features/__manifest__.py index e8f24f7..fc596f8 100644 --- a/account_advanced_protection_features/__manifest__.py +++ b/account_advanced_protection_features/__manifest__.py @@ -21,6 +21,7 @@ }, # always loaded "data": [ + "views/account_journal_views.xml" ], # only loaded in demonstration mode "demo": [], diff --git a/account_advanced_protection_features/models/__init__.py b/account_advanced_protection_features/models/__init__.py index 4c89822..ea6d653 100644 --- a/account_advanced_protection_features/models/__init__.py +++ b/account_advanced_protection_features/models/__init__.py @@ -1 +1,2 @@ -from . import account_move \ No newline at end of file +from . import account_move +from . import account_journal diff --git a/account_advanced_protection_features/models/account_journal.py b/account_advanced_protection_features/models/account_journal.py new file mode 100644 index 0000000..07dc21a --- /dev/null +++ b/account_advanced_protection_features/models/account_journal.py @@ -0,0 +1,6 @@ +from odoo import models, fields + +class AccountJournal(models.Model): + _inherit = "account.journal" + + prevent_reset_to_draft_sent_invoice = fields.Boolean("Prevent to reset to draft a sent invoice") diff --git a/account_advanced_protection_features/models/account_move.py b/account_advanced_protection_features/models/account_move.py index 3e5d722..9ce757d 100644 --- a/account_advanced_protection_features/models/account_move.py +++ b/account_advanced_protection_features/models/account_move.py @@ -8,7 +8,7 @@ class AccountMove(models.Model): def button_draft(self): res = super(AccountMove, self).button_draft() - if self.sent_by_email: + if self.sent_by_email and self.journal_id.prevent_reset_to_draft_sent_invoice: raise UserError(_( "You cannot reset to draft this invoice because it has been sent by email." )) diff --git a/account_advanced_protection_features/views/account_journal_views.xml b/account_advanced_protection_features/views/account_journal_views.xml new file mode 100644 index 0000000..2541acf --- /dev/null +++ b/account_advanced_protection_features/views/account_journal_views.xml @@ -0,0 +1,16 @@ + + + + account.journal.form + account.journal + + + + + + + +