From 914d2ca8708ed9fd4edb3b19f895d424521f1d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 18 May 2017 13:33:53 +0200 Subject: [PATCH] Add last statement update support. K-Psul - Add handler for checkout data (balance update) - New statements are sent through ws, and display live on K-Psul. --- kfet/static/kfet/js/kpsul.js | 10 ++++++++++ kfet/views.py | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 9e14f709..8fa667eb 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -316,6 +316,8 @@ class CheckoutManager { `, }; + + OperationWebSocket.add_handler(data => this.update_data(data)); } update(id) { @@ -344,6 +346,14 @@ class CheckoutManager { } + update_data(ws_data) { + let data = ws_data["checkouts"].find(o => o.id === this.checkout.id); + if (!data) + return; + this.checkout.update(data); + this._update_on_success(data); + } + is_empty() { return this.checkout.is_empty(); } display() { diff --git a/kfet/views.py b/kfet/views.py index 6751d95b..313ce9ae 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -765,7 +765,24 @@ class CheckoutStatementCreate(SuccessMessageMixin, CreateView): form.instance.balance_new = getAmountBalance(form.cleaned_data) form.instance.checkout_id = self.kwargs['pk_checkout'] form.instance.by = self.request.user.profile.account_kfet - return super(CheckoutStatementCreate, self).form_valid(form) + res = super(CheckoutStatementCreate, self).form_valid(form) + + ws_data = { + 'id': self.object.id, + 'at': self.object.at, + 'balance_new': self.object.balance_new, + 'balance_old': self.object.balance_old, + 'by': str(self.object.by), + } + consumers.KPsul.group_send('kfet.kpsul', { + 'checkouts': [{ + 'id': self.object.checkout.id, + 'laststatement': ws_data, + }], + }) + + return res + class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView): model = CheckoutStatement