Skip to content

Commit

Permalink
[IMP] account_payment_invoice: refact method create_electronic_payment
Browse files Browse the repository at this point in the history
       create and send request inside a try

closes #426

Signed-off-by: augusto-weiss <awe@adhoc.com.ar>
  • Loading branch information
maq-adhoc committed Dec 4, 2023
1 parent e253d1e commit 7abc32c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
3 changes: 2 additions & 1 deletion account_payment_invoice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Payment invoice token",
"version": "16.0.1.0.0",
"version": "16.0.2.0.0",
"category": "Accounting",
"description": """This module allows you to associate an invoice with a payment token and make the electronic payment of the invoice.
- add a filter Electronic payment pending
Expand All @@ -11,6 +11,7 @@
"website": "www.adhoc.com.ar",
"author": "ADHOC SA",
"license": "AGPL-3",
"sequence": 100,
"application": False,
'installable': True,
"external_dependencies": {
Expand Down
30 changes: 17 additions & 13 deletions account_payment_invoice/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# directory
##############################################################################
from odoo import models, fields, api
from odoo.tools import plaintext2html


class AccountMove(models.Model):
Expand Down Expand Up @@ -31,19 +32,22 @@ def _post(self, soft=True):

def create_electronic_payment(self):
tx_obj = self.env['payment.transaction']
values = []
for rec in self:
active_transaction_amount = sum(rec.transaction_ids.filtered(lambda tx: tx.state in ['authorized', 'done','pending']).mapped('amount'))
if rec.currency_id.compare_amounts(rec.amount_total, active_transaction_amount) > 0.0:
values.append({
'provider_id': rec.payment_token_id.provider_id.id,
'amount': rec.amount_total - active_transaction_amount,
'currency_id': rec.currency_id.id,
'partner_id': rec.partner_id.id,
'token_id': rec.payment_token_id.id,
'operation': 'offline',
'invoice_ids': [(6, 0, [rec.id])],
})
transactions = tx_obj.create(values)
for tx in transactions:
tx._send_payment_request()
try:
transaction = tx_obj.create({
'provider_id': rec.payment_token_id.provider_id.id,
'amount': rec.amount_total - active_transaction_amount,
'currency_id': rec.currency_id.id,
'partner_id': rec.partner_id.id,
'token_id': rec.payment_token_id.id,
'operation': 'offline',
'invoice_ids': [(6, 0, [rec.id])],
})
transaction._send_payment_request()
transaction._cr.commit()
except Exception as exp:
rec.message_post(
body=_('We tried to validate this payment but got this error') + ': \n\n' + plaintext2html(str(exp), 'em'),
partner_ids=rec.get_internal_partners().ids)

0 comments on commit 7abc32c

Please sign in to comment.