forked from mollie/mollie-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mollie#87 from mollie/13-0-mollie-refund
release new version v13.0.0.2
- Loading branch information
Showing
6 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
from . import mollie_method | ||
from . import mollie_issuers | ||
from . import res_partner | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |