From ec9a734b572bca0807585237b97ce7bee480f614 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Thu, 13 Jan 2022 13:17:38 +0000 Subject: [PATCH] [FIX] account : No cash journal Current behavior: When changing the type of a payment journal used in a cash payment method you couldn't close a PoS that used this payment method Steps to reproduce: - Point of Sale > Configuration > Payment Methods - Select 'Cash' payment method, go to journal 'Cash', edit the type to 'Bank' - Go to a Pos session, then try to close it. opw-2732933 closes odoo/odoo#83343 X-original-commit: 43b64a78888d5b79d87491caf1401964228809fc Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Engels Robin (roen) --- addons/point_of_sale/i18n/point_of_sale.pot | 7 +++++++ addons/point_of_sale/models/account_journal.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index d6080616d14..8bfd1ca91c4 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -5982,6 +5982,13 @@ msgid "" " specific tax rates." msgstr "" +#. module: point_of_sale +#: code:addons/point_of_sale/models/account_journal.py:0 +#, python-format +msgid "" +"This journal is associated with a payment method. You cannot modify its type" +msgstr "" + #. module: point_of_sale #. openerp-web #: code:addons/point_of_sale/static/src/js/ChromeWidgets/DebugWidget.js:0 diff --git a/addons/point_of_sale/models/account_journal.py b/addons/point_of_sale/models/account_journal.py index 3e41f4476b8..c511384884f 100644 --- a/addons/point_of_sale/models/account_journal.py +++ b/addons/point_of_sale/models/account_journal.py @@ -1,10 +1,16 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. # Copyright (C) 2004-2008 PC Solutions (). All Rights Reserved -from odoo import fields, models, api - +from odoo import fields, models, api, _ +from odoo.exceptions import ValidationError class AccountJournal(models.Model): _inherit = 'account.journal' pos_payment_method_ids = fields.One2many('pos.payment.method', 'journal_id', string='Point of Sale Payment Methods') + + @api.constrains('type') + def _check_type(self): + methods = self.env['pos.payment.method'].sudo().search([("journal_id", "in", self.ids)]) + if methods: + raise ValidationError(_("This journal is associated with a payment method. You cannot modify its type"))