From 69e071e1f3802083fd50afa271a147bd6ccea814 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Mon, 12 Aug 2019 13:43:20 -0700 Subject: [PATCH] [IMP] point_of_sale: allow custo of pos.payment.method write constraint Allow another module to override this behavior for some fields. --- addons/point_of_sale/models/pos_payment_method.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/models/pos_payment_method.py b/addons/point_of_sale/models/pos_payment_method.py index 997afa31541..87852afa5dc 100644 --- a/addons/point_of_sale/models/pos_payment_method.py +++ b/addons/point_of_sale/models/pos_payment_method.py @@ -59,8 +59,11 @@ class PosPaymentMethod(models.Model): if not self.is_cash_count: self.cash_journal_id = False + def _is_write_forbidden(self, fields): + return bool(fields and self.open_session_ids) + def write(self, vals): - if self.open_session_ids: + if self._is_write_forbidden(set(vals.keys())): raise UserError('Kindly close and validate the following open PoS Sessions before modifying this payment method.\n' 'Open sessions: %s' % (' '.join(self.open_session_ids.mapped('name')),)) return super(PosPaymentMethod, self).write(vals)