From a45bad47f17c356b8284413415b19c2733294aea Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Tue, 17 May 2022 18:51:56 +0000 Subject: [PATCH] [IMP]l10n_ar_ux:prevent currency change when the invoice is not draft closes ingadhoc/odoo-argentina#615 Ticket: 51808 Related: ingadhoc/account-financial-tools#341 Signed-off-by: Katherine Zaoral --- l10n_ar_ux/wizards/account_move_change_rate.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/l10n_ar_ux/wizards/account_move_change_rate.py b/l10n_ar_ux/wizards/account_move_change_rate.py index 0466ef571..e6b374b6b 100644 --- a/l10n_ar_ux/wizards/account_move_change_rate.py +++ b/l10n_ar_ux/wizards/account_move_change_rate.py @@ -3,6 +3,7 @@ # directory ############################################################################## from odoo import fields, models, api, _ +from odoo.exceptions import ValidationError class AccountMoveChangeRate(models.TransientModel): @@ -26,6 +27,13 @@ def get_move(self): default=get_move ) + @api.constrains('currency_rate') + def _prevent_change_currency(self): + """prevent currency change when the invoice is not draft + """ + if self.move_id.state != 'draft': + raise ValidationError(_('This invoice is not draft, reset it to draft to change currency rate')) + @api.onchange('move_id') def _onchange_move(self): self.currency_rate = self.move_id.l10n_ar_currency_rate or self.move_id.computed_currency_rate