Skip to content

Commit

Permalink
[ADD] add new module account_payment_invoice
Browse files Browse the repository at this point in the history
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
- add a payment status "Electronic payment pending" for invoices that are associated to a payment but are in pending or those that have a payment in done but have not yet been reconciled.
  • Loading branch information
maq-adhoc committed Sep 27, 2023
1 parent 6a0f9b6 commit 1f5ef11
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions account_payment_invoice/__init__.py
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions account_payment_invoice/__manifest__.py
@@ -0,0 +1,28 @@
# © 2023 ADHOC SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Payment invoice token",
"version": "16.0.1.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
- add a payment status "Electronic payment pending" for invoices that are associated to a payment
but are in pending or those that have a payment in done but have not yet been reconciled.""",
"website": "www.adhoc.com.ar",
"author": "ADHOC SA",
"license": "AGPL-3",
"application": False,
'installable': True,
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"account_payment",
],
"data": [
'views/account_move.xml'
],
"demo": [
],
}
1 change: 1 addition & 0 deletions account_payment_invoice/models/__init__.py
@@ -0,0 +1 @@
from . import account_move
48 changes: 48 additions & 0 deletions account_payment_invoice/models/account_move.py
@@ -0,0 +1,48 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api


class AccountMove(models.Model):

_inherit = "account.move"
payment_state = fields.Selection(
selection_add=[('electronic_pending', 'Electronic payment pending')],
ondelete={'electronic_pending': 'cascade'}
)
payment_token_id = fields.Many2one('payment.token', string="automatic electonic payment", check_company=True, copy=False)

@api.depends('transaction_ids.state')
def _compute_payment_state(self):
super()._compute_payment_state()
for rec in self.filtered(lambda x: x.payment_state=='not_paid' and {'done','pending','authorized'}.intersection(set(x.transaction_ids.mapped('state')))):
rec.payment_state = 'electronic_pending'

def _post(self, soft=True):
res = super()._post(soft=soft)
to_pay_moves = self.filtered(
lambda x: x.payment_token_id and x.state == 'posted' and
x.payment_state == 'not_paid' and x.move_type == 'out_invoice')
to_pay_moves.create_electronic_payment()
return res

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()
23 changes: 23 additions & 0 deletions account_payment_invoice/views/account_move.xml
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<odoo>
<record id="view_move_form_view_form" model="ir.ui.view">
<field name="name">view_move_form.view.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"></field>
<field name="arch" type="xml">
<field name="invoice_user_id" position="after">
<field name="payment_token_id" domain="[('partner_id', '=', partner_id)]" attrs="{'invisible': [('move_type', 'not in', ('out_invoice'))]}"/>
</field>
</field>
</record>
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">account.invoice.select</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<filter name="open" position="after">
<filter name="payment_pending" string="Electronic payment pending" domain="[('electronic_pending', '=', 'electronic_pending')]"/>
</filter>
</field>
</record>
</odoo>

0 comments on commit 1f5ef11

Please sign in to comment.