From cb1ce61c84300b61bbfcf85fec861944819e1f3f Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Fri, 21 Aug 2015 10:48:59 +0200 Subject: [PATCH] [ADD] account: add a popover with payment details and action on invoice --- addons/account/models/account_invoice.py | 7 ++- .../static/src/js/account_payment_widget.js | 46 +++++++++++++++++++ .../static/src/xml/account_payment.xml | 46 +++++++++++++++++-- addons/account/views/account_invoice_view.xml | 4 +- 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 69128aa25d9..2701039e974 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -127,7 +127,7 @@ class AccountInvoice(models.Model): else: amount_to_show = line.company_id.currency_id.compute(abs(line.amount_residual), self.currency_id) info['content'].append({ - 'ref': line.ref or line.move_id.name, + 'journal_name': line.ref or line.move_id.name, 'amount': amount_to_show, 'currency': self.currency_id.symbol, 'id': line.id, @@ -161,12 +161,15 @@ class AccountInvoice(models.Model): amount_to_show = payment.company_id.currency_id.compute(-amount, self.currency_id) info['content'].append({ 'name': payment.name, - 'ref': payment.journal_id.name, + 'journal_name': payment.journal_id.name, 'amount': amount_to_show, 'currency': self.currency_id.symbol, 'digits': [69, self.currency_id.decimal_places], 'position': self.currency_id.position, 'date': payment.date, + 'payment_id': payment.id, + 'move_id': payment.move_id.id, + 'ref': payment.move_id.ref, }) self.payments_widget = json.dumps(info) diff --git a/addons/account/static/src/js/account_payment_widget.js b/addons/account/static/src/js/account_payment_widget.js index fd201640a1a..5a1aae22291 100644 --- a/addons/account/static/src/js/account_payment_widget.js +++ b/addons/account/static/src/js/account_payment_widget.js @@ -15,6 +15,7 @@ var ShowPaymentLineWidget = form_common.AbstractField.extend({ var invoice_id = info.invoice_id; if (info !== false) { _.each(info.content, function(k,v){ + k.index = v; k.amount = formats.format_value(k.amount, {type: "float", digits: k.digits}); if (k.date){ k.date = formats.format_value(k.date, {type: "date"}); @@ -33,6 +34,51 @@ var ShowPaymentLineWidget = form_common.AbstractField.extend({ self.view.reload(); }); }); + _.each(this.$('.js_payment_info'), function(k, v){ + var options = { + 'content': QWeb.render('PaymentPopOver', { + 'name': info.content[v].name, + 'journal_name': info.content[v].journal_name, + 'date': info.content[v].date, + 'amount': info.content[v].amount, + 'currency': info.content[v].currency, + 'position': info.content[v].position, + 'payment_id': info.content[v].payment_id, + 'move_id': info.content[v].move_id, + 'ref': info.content[v].ref, + }), + 'html': true, + 'placement': 'left', + 'title': 'Payment Information', + 'trigger': 'focus', + }; + $(k).popover(options); + $(k).on('shown.bs.popover', function(event){ + $(this).parent().find('.js_unreconcile_payment').click(function(){ + var payment_id = parseInt($(this).attr('payment-id')) + if (payment_id !== undefined && payment_id !== NaN){ + new Model("account.move.line") + .call("remove_move_reconcile", [payment_id]) + .then(function (result) { + self.view.reload(); + }); + } + }); + $(this).parent().find('.js_open_payment').click(function(){ + var move_id = parseInt($(this).attr('move-id')) + if (move_id !== undefined && move_id !== NaN){ + //Open form view of account.move with id = move_id + self.do_action({ + type: 'ir.actions.act_window', + res_model: 'account.move', + res_id: move_id, + views: [[false, 'form']], + target: 'current' + }); + } + }); + }); + }); } else { this.$el.html(''); diff --git a/addons/account/static/src/xml/account_payment.xml b/addons/account/static/src/xml/account_payment.xml index c99dd36f9e4..91a1d82cda3 100644 --- a/addons/account/static/src/xml/account_payment.xml +++ b/addons/account/static/src/xml/account_payment.xml @@ -14,15 +14,18 @@ - Add + Add - + - Paid on + + + + Paid on @@ -42,4 +45,41 @@ + +
+ + + + + + + + + + + + + + + + + + + + + +
Name:
Date:
Payment Method:
Ref:
Amount: + + + + + + + +
+
+ + +
+ diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index d6ac5b78d5f..b2702c73174 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -219,7 +219,7 @@ @@ -356,7 +356,7 @@