From 09e51611fe3c752950b5951a117a9497cf96f70d Mon Sep 17 00:00:00 2001 From: odoo-mvds Date: Mon, 12 Oct 2020 23:24:53 +0530 Subject: [PATCH] release new version v13.0.0.2 - Support mollie refund via credit notes - Updated description - Added changelog in the description --- payment_mollie_official/__manifest__.py | 1 + payment_mollie_official/models/__init__.py | 1 + .../models/account_move.py | 48 +++++++++++++++++++ .../models/payment_acquirer.py | 21 ++++++++ .../static/description/index.html | 47 ++++++++++++++---- .../views/account_move_view.xml | 24 ++++++++++ 6 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 payment_mollie_official/models/account_move.py create mode 100644 payment_mollie_official/views/account_move_view.xml diff --git a/payment_mollie_official/__manifest__.py b/payment_mollie_official/__manifest__.py index e5d3eb3..c6ce12c 100644 --- a/payment_mollie_official/__manifest__.py +++ b/payment_mollie_official/__manifest__.py @@ -26,6 +26,7 @@ 'security/ir.model.access.csv', 'views/payment_views.xml', 'views/payment_mollie_templates.xml', + 'views/account_move_view.xml', 'data/payment_acquirer_data.xml', ], diff --git a/payment_mollie_official/models/__init__.py b/payment_mollie_official/models/__init__.py index 4150353..8f279e8 100644 --- a/payment_mollie_official/models/__init__.py +++ b/payment_mollie_official/models/__init__.py @@ -5,3 +5,4 @@ from . import mollie_method from . import mollie_issuers from . import res_partner +from . import account_move diff --git a/payment_mollie_official/models/account_move.py b/payment_mollie_official/models/account_move.py new file mode 100644 index 0000000..c6a3fa8 --- /dev/null +++ b/payment_mollie_official/models/account_move.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, _ +from odoo.exceptions import UserError + +import logging + +_logger = logging.getLogger(__name__) + + +class AccountMove(models.Model): + _inherit = "account.move" + + valid_for_mollie_refund = fields.Boolean(compute="_compute_valid_for_mollie_refund") + mollie_refund_reference = fields.Char() + + def _compute_valid_for_mollie_refund(self): + for move in self: + has_mollie_tx = False + if move.type == 'out_refund' and move._find_valid_mollie_transactions() and move.state == "posted" and move.invoice_payment_state != 'paid': + has_mollie_tx = True + move.valid_for_mollie_refund = has_mollie_tx + + def mollie_process_refund(self): + self.ensure_one() + mollie_transactions = self._find_valid_mollie_transactions() + + # TODO: Need to handle multiple transection + if len(mollie_transactions) > 1: + raise UserError(_("Multiple mollie transactions are linked with invoice. Please refund manually from mollie portal")) + + if mollie_transactions: + + # Create payment record and post the payment + AccountPayment = self.env['account.payment'].with_context(active_ids=self.ids, active_model='account.move', active_id=self.id) + payment_obj = AccountPayment.create({ + 'journal_id': mollie_transactions.payment_id.journal_id.id, + 'payment_method_id': mollie_transactions.payment_id.payment_method_id.id + }) + payment_obj.post() + + # Create refund in mollie via API + refund = mollie_transactions.acquirer_id._api_mollie_refund(self.amount_total, self.currency_id, mollie_transactions.acquirer_reference) + if refund['status'] == 'refunded': + self.mollie_refund_reference = refund['id'] + + def _find_valid_mollie_transactions(self): + self.ensure_one() + return self.reversed_entry_id.transaction_ids.filtered(lambda tx: tx.state == 'done' and tx.acquirer_id.provider == 'mollie') diff --git a/payment_mollie_official/models/payment_acquirer.py b/payment_mollie_official/models/payment_acquirer.py index 57b4043..1516a9d 100644 --- a/payment_mollie_official/models/payment_acquirer.py +++ b/payment_mollie_official/models/payment_acquirer.py @@ -324,6 +324,27 @@ def _api_mollie_get_active_payment_methods(self, api_type=None): return result + def _api_mollie_refund(self, amount, currency, transection_reference): + payment_record = self._mollie_get_payment_data(transection_reference) + transection_id = False + if payment_record['resource'] == 'order': + payments = payment_record.get('_embedded', {}).get('payments', []) + if payments: + # TODO: handle multiple payment for same order + transection_id = payments[0]['id'] + elif payment_record['resource'] == 'payment': + transection_id = payment_record['id'] + + mollie_client = self._api_mollie_get_client() + payment_rec = mollie_client.payments.get(transection_id) + refund = mollie_client.payment_refunds.on(payment_rec).create({ + 'amount': { + 'value': "%.2f" % amount, + 'currency': currency.name + } + }) + return refund + # ----------------------------------------------- # Methods that create mollie order payload # ----------------------------------------------- diff --git a/payment_mollie_official/static/description/index.html b/payment_mollie_official/static/description/index.html index b6b0785..1edfc27 100644 --- a/payment_mollie_official/static/description/index.html +++ b/payment_mollie_official/static/description/index.html @@ -55,7 +55,7 @@

Inline Credit Card Payment

Inline Issuer Selector

Inline issuer selector shows available issuer in Odoo itself. - It reduces one step at payment portal and make checkout faster. + It reduces one step at payment portal and makes checkout faster.

@@ -116,42 +116,42 @@
Portal invoice payment (works without eCommerce)
- -
Can be tested with Test mode
+
Real-time data and insights from your free Dashboard
- -
Webhooks for delayed payments.
+
Convenient tools for refunds and chargebacks.
- -
Clear alert messages for customer.
+
In-house support teams, extensive documentation.
@@ -170,7 +170,7 @@

Step 2 Install python dependencies (it is listed in requirements.txt file in module) + style="display: inline-block;font-size: 19px;"> Install python dependencies (it is listed in requirements.txt file in module).

pip3 install -r requirements.txt @@ -189,14 +189,14 @@

style="background-color: #0077ff;color: #fff;padding: 5px 17px;font-size: 14px;"> Step 4 Open Website > Configuration > Payment Acquirers - And open acquirers + and open acquirers

Step 5 Fill the API keys and credentials. (You will find these keys from your mollie dashboard.) + style="display: inline-block;font-size: 19px;"> Fill the API keys and credentials. (You will find these keys from your Mollie dashboard.)

That's it you are ready to accept payments.
+ +

Changelog

+
+ +
+ +
+
+

v13.0.0.2

+
+
+
NEW Added support to refund the payment via credit notes
+
+
+ +
+
+

v13.0.0.1

+
+
+
NEW Initial release (revamped)
+
NEW Added inline credit card support
+
NEW Added inline issuer support
+
NEW Separate/Common account journal for payment methods
+
NEW Enable/Disable payment methods for shop
+
+
\ No newline at end of file diff --git a/payment_mollie_official/views/account_move_view.xml b/payment_mollie_official/views/account_move_view.xml new file mode 100644 index 0000000..d3c93ed --- /dev/null +++ b/payment_mollie_official/views/account_move_view.xml @@ -0,0 +1,24 @@ + + + + + account.move.form.view.mollie + account.move + + +
+ +
+ + + + Amount refunded in mollie + + +
+ +