[IMP] point_of_sale: allow custo of pos.payment.method write constraint

Allow another module to override this behavior for some fields.
This commit is contained in:
Joren Van Onder
2019-08-23 16:22:00 -07:00
parent d661ed122f
commit 69e071e1f3
@@ -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)