Skip to content

Commit

Permalink
Merge pull request mollie#87 from mollie/13-0-mollie-refund
Browse files Browse the repository at this point in the history
release new version v13.0.0.2
  • Loading branch information
odoo-mvds authored Oct 12, 2020
2 parents e3640f2 + 09e5161 commit 23f10ce
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 10 deletions.
1 change: 1 addition & 0 deletions payment_mollie_official/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],

Expand Down
1 change: 1 addition & 0 deletions payment_mollie_official/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import mollie_method
from . import mollie_issuers
from . import res_partner
from . import account_move
48 changes: 48 additions & 0 deletions payment_mollie_official/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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')
21 changes: 21 additions & 0 deletions payment_mollie_official/models/payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -----------------------------------------------
Expand Down
47 changes: 37 additions & 10 deletions payment_mollie_official/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1 style="font-weight: bold;">Inline Credit Card Payment</h1>
<h1 style="font-weight: bold;">Inline Issuer Selector</h1>
<p class="lead pr-4" style="color: #000;font-size: 20px;font-weight: 300;font-family: lato;">
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.
</p>
</div>
<div class="col-md-6">
Expand Down Expand Up @@ -116,42 +116,42 @@ <h5> Portal invoice payment (works without eCommerce) </h5>
<div class="col-md-6 py-3">
<div class="card shadow">
<div class="card-body text-center">
<i class="fa fa-hand-pointer-o mb-2" style="
<i class="fa fa-dashboard mb-2" style="
color: white;
background-color: #0076fe;
padding: 12px;
border-radius: 25px;
font-size: 22px;
"></i>
<h5> Can be tested with Test mode </h5>
<h5> Real-time data and insights from your free Dashboard </h5>
</div>
</div>
</div>
<div class="col-md-6 py-3">
<div class="card shadow">
<div class="card-body text-center">
<i class="fa fa-anchor mb-2" style="
<i class="fa fa-reply-all mb-2" style="
color: white;
background-color: #0076fe;
padding: 12px;
border-radius: 25px;
font-size: 22px;
"></i>
<h5> Webhooks for delayed payments. </h5>
<h5> Convenient tools for refunds and chargebacks. </h5>
</div>
</div>
</div>
<div class="col-md-6 py-3">
<div class="card shadow">
<div class="card-body text-center">
<i class="fa fa-commenting-o mb-2" style="
<i class="fa fa-life-ring mb-2" style="
color: white;
background-color: #0076fe;
padding: 12px;
border-radius: 25px;
font-size: 22px;
"></i>
<h5> Clear alert messages for customer. </h5>
<h5> In-house support teams, extensive documentation. </h5>
</div>
</div>
</div>
Expand All @@ -170,7 +170,7 @@ <h3>
<h3>
<span class="badge badge-pill mr-2"
style="background-color: #0077ff;color: #fff;padding: 5px 17px;font-size: 14px;"> Step 2 </span><span
style="display: inline-block;font-size: 19px;"> Install python dependencies (it is listed in requirements.txt file in module) </span>
style="display: inline-block;font-size: 19px;"> Install python dependencies (it is listed in requirements.txt file in module). </span>
</h3>
<span style="background-color: #424242;color: white;padding: 8px 28px;display: inline-block;margin-left: 85px;border-radius: 6px;margin-bottom: 16px;">
pip3 install -r requirements.txt
Expand All @@ -189,14 +189,14 @@ <h3>
style="background-color: #0077ff;color: #fff;padding: 5px 17px;font-size: 14px;"> Step 4 </span><span
style="display: inline-block;font-size: 19px;"> Open
<span style="color:#0077ff;"> Website > Configuration > Payment Acquirers </span>
And open acquirers
and open acquirers
</span>
</h3>

<h3>
<span class="badge badge-pill mr-2"
style="background-color: #0077ff;color: #fff;padding: 5px 17px;font-size: 14px;"> Step 5 </span><span
style="display: inline-block;font-size: 19px;"> 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.)
</span>
</h3>
<img class="img img-fluid shadow" src="img/drgl-enter-keys.png"
Expand All @@ -218,3 +218,30 @@ <h3 class="mt-3">
That's it you are ready to accept payments.
</span>
</h3>

<h1 style="color: #000;font-weight: bold;/* font-size: 50px; */" class="mt-5 text-center mb-0">Changelog</h1>
<div class="text-center text-muted" style="font-weight:400; margin-bottom:18px">
<span style="width:73px;height: 10px;display:inline-block;border-radius: 4px;background-color: #0077ff;"> </span>
</div>

<div class="card mx-auto w-md-75">
<div class="card-header bg-200">
<h4 class="m-0">v13.0.0.2</h4>
</div>
<div class="card-body">
<div> <b class="text-success"> NEW </b> Added support to refund the payment via credit notes </div>
</div>
</div>

<div class="card mx-auto w-md-75">
<div class="card-header bg-200">
<h4 class="m-0">v13.0.0.1</h4>
</div>
<div class="card-body">
<div> <b class="text-success"> NEW </b> Initial release (revamped) </div>
<div> <b class="text-success"> NEW </b> Added inline credit card support </div>
<div> <b class="text-success"> NEW </b> Added inline issuer support </div>
<div> <b class="text-success"> NEW </b> Separate/Common account journal for payment methods </div>
<div> <b class="text-success"> NEW </b> Enable/Disable payment methods for shop </div>
</div>
</div>
24 changes: 24 additions & 0 deletions payment_mollie_official/views/account_move_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="account_move_form_view_mollie" model="ir.ui.view">
<field name="name">account.move.form.view.mollie</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<header position="inside">
<field name="valid_for_mollie_refund" invisible="1"/>
<button string="Mollie Refund"
confirm="Are you sure you want to refund? (This will refund the amount from mollie too)"
name="mollie_process_refund" type="object"
attrs="{'invisible' : ['|', ('valid_for_mollie_refund', '=', False), ('mollie_refund_reference', '!=' ,False)]}"/>
</header>
<field name="journal_id" position="after">
<field name="mollie_refund_reference" attrs="{'invisible' : [('mollie_refund_reference', '=' ,False)]}" groups="base.group_no_one"/>
<span attrs="{'invisible' : [('mollie_refund_reference', '=' ,False)]}"> </span>
<span attrs="{'invisible' : [('mollie_refund_reference', '=' ,False)]}" class="badge badge-success"> <span class="fa fa-check"/> Amount refunded in mollie </span>
</field>
</field>
</record>

</odoo>

0 comments on commit 23f10ce

Please sign in to comment.