Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] add new module account_payment_invoice
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
Showing
5 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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,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": [ | ||
], | ||
} |
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 @@ | ||
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 @@ | ||
############################################################################## | ||
# 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() |
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,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> |