From ffffef0fb9d42e539d341219328573cf8c6e19b6 Mon Sep 17 00:00:00 2001 From: Martin Quinteros Date: Wed, 12 Jul 2023 08:50:41 -0300 Subject: [PATCH] [ADD] Add new module accout_payment_ux Fix the behavior of pending transacition realated with a account.payment What is happening now: - when i'm create a electronic payment from backend and the transaction remains in pending status the payment status is changed to canceled what happens after installing this module - When the transaction is pending the payment remains in draft status. After done this transaction the payment change its state ans reconcilie with the invoices --- .../models/account_payment_group.py | 8 +++++-- account_payment_ux/__init__.py | 1 + account_payment_ux/__manifest__.py | 24 +++++++++++++++++++ account_payment_ux/models/__init__.py | 2 ++ account_payment_ux/models/account_payment.py | 15 ++++++++++++ .../models/payment_transaction.py | 23 ++++++++++++++++++ 6 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 account_payment_ux/__init__.py create mode 100644 account_payment_ux/__manifest__.py create mode 100644 account_payment_ux/models/__init__.py create mode 100644 account_payment_ux/models/account_payment.py create mode 100644 account_payment_ux/models/payment_transaction.py diff --git a/account_payment_group/models/account_payment_group.py b/account_payment_group/models/account_payment_group.py index 95d677c89..0d34db82a 100644 --- a/account_payment_group/models/account_payment_group.py +++ b/account_payment_group/models/account_payment_group.py @@ -489,8 +489,12 @@ def post(self): rec.payment_ids.mapped('name')) and ', '.join( rec.payment_ids.mapped('name')) or False - if not created_automatically: - counterpart_aml = rec.payment_ids.mapped('line_ids').filtered( + # Filtro porque los pagos electronicos solo pueden estar en pending si la transaccion esta en pending + # y no los puedo conciliar esto no es un comportamiento del core + # sino que esta implementado en account_payment_ux + posted_payments = rec.payment_ids.filtered(lambda x: x.state == 'posted') + if not created_automatically and posted_payments: + counterpart_aml = posted_payments.mapped('line_ids').filtered( lambda r: not r.reconciled and r.account_id.account_type in ('liability_payable', 'asset_receivable')) if counterpart_aml and rec.to_pay_move_line_ids: (counterpart_aml + (rec.to_pay_move_line_ids)).reconcile() diff --git a/account_payment_ux/__init__.py b/account_payment_ux/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_payment_ux/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_ux/__manifest__.py b/account_payment_ux/__manifest__.py new file mode 100644 index 000000000..99151a815 --- /dev/null +++ b/account_payment_ux/__manifest__.py @@ -0,0 +1,24 @@ +# © 2023 ADHOC SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Account Payment UX", + "version": "16.0.1.0.0", + "category": "Payment", + "website": "www.adhoc.com.ar", + "author": "ADHOC SA", + "license": "AGPL-3", + "application": False, + 'installable': True, + 'auto_install': True, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "account_payment", + ], + "data": [ + ], + "demo": [ + ], +} diff --git a/account_payment_ux/models/__init__.py b/account_payment_ux/models/__init__.py new file mode 100644 index 000000000..8d425d043 --- /dev/null +++ b/account_payment_ux/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_payment +from . import payment_transaction diff --git a/account_payment_ux/models/account_payment.py b/account_payment_ux/models/account_payment.py new file mode 100644 index 000000000..ae451a442 --- /dev/null +++ b/account_payment_ux/models/account_payment.py @@ -0,0 +1,15 @@ +from odoo import models + + +class AccountPayment(models.Model): + _inherit = 'account.payment' + + def action_post(self): + """ Odoo a partir de 16, cuando se valida un pago con token, si la transaccion no queda en done cancela el pago + por ahora nosotros revertimos este cambio para el caso de tu cuota""" + return super(AccountPayment, self.with_context(from_action_post=True)).action_post() + + def action_cancel(self): + if self._context.get('from_action_post'): + self = self - self.filtered(lambda x: x.payment_transaction_id.state in ['draft', 'pending', 'authorized']) + return super(AccountPayment, self).action_cancel() diff --git a/account_payment_ux/models/payment_transaction.py b/account_payment_ux/models/payment_transaction.py new file mode 100644 index 000000000..05e1c441c --- /dev/null +++ b/account_payment_ux/models/payment_transaction.py @@ -0,0 +1,23 @@ +from odoo import models + + +class PaymentTransaction(models.Model): + _inherit = 'payment.transaction' + + def _reconcile_after_done(self): + super()._reconcile_after_done() + + # Si el pago relacionado a la trasaccion esta en draft y coinciden los datos + # lo publico y concilio + if self.payment_id and self.payment_id.state == 'draft' and \ + self.payment_id.currency_id == self.currency_id and \ + self.payment_id.amount == abs(self.amount): + + self.payment_id.action_post() + if self.invoice_ids: + self.invoice_ids.filtered(lambda inv: inv.state == 'draft').action_post() + + (self.payment_id.line_ids + self.invoice_ids.line_ids).filtered( + lambda line: line.account_id == self.payment_id.destination_account_id + and not line.reconciled + ).reconcile()