From 48058ab3d3328093f27ca841c8dd788206c607b8 Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Tue, 17 May 2022 19:07:17 +0000 Subject: [PATCH] [IMP]account_ux:prevent currency change when the invoice is not draft closes ingadhoc/account-financial-tools#341 Ticket: 51808 Related: ingadhoc/odoo-argentina#615 Signed-off-by: Katherine Zaoral --- account_ux/wizards/account_change_currency.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/account_ux/wizards/account_change_currency.py b/account_ux/wizards/account_change_currency.py index 110a24384..09cd00db9 100644 --- a/account_ux/wizards/account_change_currency.py +++ b/account_ux/wizards/account_change_currency.py @@ -3,6 +3,7 @@ # directory ############################################################################## from odoo import fields, models, api, _ +from odoo.exceptions import ValidationError class AccountChangeCurrency(models.TransientModel): @@ -55,6 +56,13 @@ def onchange_currency(self): date=self.move_id.date or fields.Date.context_today(self)) + @api.constrains('currency_to_id', 'currency_rate') + def _prevent_change_currency(self): + """prevent currency or currency rate 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 or currency rate')) + def change_currency(self): self.ensure_one() if self.change_type == 'currency':