Skip to content

Commit

Permalink
[ADD] website_payment_acquirer_bank_account
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Oct 16, 2024
1 parent d3ff0e3 commit 63f3dd3
Show file tree
Hide file tree
Showing 10 changed files with 346 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_payment_acquirer_bank_account/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
73 changes: 73 additions & 0 deletions website_payment_acquirer_bank_account/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
:target: https://opensource.org/licenses/LGPL-3.0
:alt: License: LGPL-3

=================================
Account Payment Mode and Acquirer
=================================

Overview
========

The **Account Payment Mode and Acquirer** module integrates payment modes with bank accounts in sales. It allows users to select a bank account for payments directly from the sales order, enhancing the payment processing workflow.

Features
========

- **Bank Account Selection**: Users can select a bank account for payments directly from the sales order.

- **Automatic Payment Mode Assignment**: When confirming an order, the payment mode is automatically set based on the selected bank account.

- **Bank Account Management**: Users can create new bank accounts linked to partners seamlessly.

Usage
=====

1. **Install the Module**:

- Install the module via Odoo's Apps interface.

2. **Using Bank Accounts**:

- When creating or editing a sales order, select a bank account from the dropdown.
- Confirm the order, and the payment mode will automatically be assigned based on the selected bank account.

Configuration
=============

No additional configuration is required. The module is ready to use once installed.

Testing
=======

Test the following scenarios:

- **Bank Account Selection**:

- Create or edit a sales order and select a bank account.
- Confirm the order and verify that the payment mode is set correctly.

- **Bank Account Creation**:

- Create a new bank account from the sales order and ensure it links correctly to the partner.

Bug Tracker
===========

If you encounter any issues, please report them on the GitHub repository at `GitHub Issues <https://github.com/avanzosc/odoo-addons/issues>`_.

Credits
=======

Contributors
------------

* Unai Beristain <unaiberistain@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>

For module-specific questions, please contact the contributors directly. Support requests should be made through the official channels.

License
=======

This project is licensed under the LGPL-3 License. For more details, please refer to the LICENSE file or visit <https://opensource.org/licenses/LGPL-3.0>.
1 change: 1 addition & 0 deletions website_payment_acquirer_bank_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions website_payment_acquirer_bank_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Account Payment Mode and Acquirer",
"version": "14.0.1.0.0",
"author": "Avanzosc",
"summary": "Integrates payment modes with bank accounts in sales.",
"website": "https://github.com/avanzosc/odoo-addons",
"license": "LGPL-3",
"depends": [
"sale",
"account",
"payment_acquirer_payment_mode", # trey
],
"data": ["views/payment_view.xml"],
"installable": True,
"application": False,
}
3 changes: 3 additions & 0 deletions website_payment_acquirer_bank_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_bank_account
from . import res_partner
from . import sale_order
10 changes: 10 additions & 0 deletions website_payment_acquirer_bank_account/models/res_bank_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class ResBankAccount(models.Model):
_name = "res.bank.account"
_description = "Bank Account"

name = fields.Char(string="Account Name", required=True)
bank_account = fields.Char(string="Bank Account", required=True)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
11 changes: 11 additions & 0 deletions website_payment_acquirer_bank_account/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

bank_account_ids = fields.One2many(
"res.bank.account",
"partner_id",
string="Bank Accounts",
)
29 changes: 29 additions & 0 deletions website_payment_acquirer_bank_account/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class SaleOrder(models.Model):
_inherit = "sale.order"

bank_account_id = fields.Many2one(
"res.bank.account",
string="Bank Account",
help="Bank account selected for the payment.",
)

def confirm_order(self):
self.ensure_one()
if self.bank_account_id:
# Si hay una cuenta bancaria seleccionada
self.payment_mode_id = self.bank_account_id.payment_method_id
# Crear la cuenta bancaria si es nueva
if not self.bank_account_id.exists():
self.env["res.bank.account"].create(
{
"name": self.bank_account_id.name,
"bank_account": self.bank_account_id.bank_account,
"partner_id": self.partner_id.id,
}
)
else:
raise ValidationError(_("Please select a bank account."))
196 changes: 196 additions & 0 deletions website_payment_acquirer_bank_account/views/payment_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_payment_form" model="ir.ui.view">
<field name="name">payment.form.inherit</field>
<field name="model">payment.acquirer</field>
<field name="inherit_id" ref="payment.payment_tokens_list" />
<field name="arch" type="xml">
<xpath expr="//t[@t-foreach='acquirers']/.." position="attritutes">
<attribute name="t-if">False</attribute>
</xpath>
<xpath expr="//t[@t-foreach='acquirers']/.." position="after">
<div class="card">
<t
t-set="acquirers_count"
t-value="len(acquirers) if acquirers else 0"
/>
<t t-set="pms_count" t-value="len(pms) if pms else 0" />
<t t-set="MAX_BRAND_LINE" t-value="3" />
<t t-foreach="acquirers" t-as="acq">
<div class="card-body o_payment_acquirer_select">
<label>
<t t-if="acq.payment_flow == 'form'">
<input
type="radio"
t-att-data-acquirer-id="acq.id"
t-att-data-form-payment="true"
t-att-data-provider="acq.provider"
t-att-class="'d-none' if (acquirers_count==1 and pms_count==0) else ''"
name="pm_id"
t-attf-value="form_{{acq.id}}"
t-att-checked="acquirers_count==1 and pms_count==0 or acquirers[0] == acq"
/>
</t>
<t t-else="acq.payment_flow == 's2s'">
<input
type="radio"
t-att-data-acquirer-id="acq.id"
t-att-data-s2s-payment="true"
t-att-data-provider="acq.provider"
name="pm_id"
t-attf-value="new_{{acq.id}}"
t-att-class="'d-none' if (acquirers_count==1 and pms_count==0) else ''"
t-att-checked="acquirers_count==1 and pms_count==0 or acquirers[0] == acq"
/>
</t>
<span class="payment_option_name">
<t t-esc="acq.display_as or acq.name" />
<div
t-if="acq.state == 'test'"
class="badge-pill badge-warning float-right"
style="margin-left:5px"
>
Test Mode
</div>
</span>
<t t-if="acq_extra_fees and acq_extra_fees.get(acq)">
<span
class="badge badge-pill badge-secondary"
> + <t
t-esc="acq_extra_fees[acq]"
t-options='{"widget": "monetary", "display_currency": acq_extra_fees["currency_id"]}'
/>
Fee </span>
</t>
<t t-elif="acq.fees_active">
<small
class="text-muted"
>(Some fees may apply)</small>
</t>
</label>
<ul class="float-right list-inline payment_icon_list">
<t t-set="i" t-value="0" />
<t t-foreach="acq.payment_icon_ids" t-as="pm_icon">
<li
t-attf-class="list-inline-item#{'' if (i &lt; MAX_BRAND_LINE) else ' d-none'}"
>
<span
t-field="pm_icon.image_payment_form"
t-options='{"widget": "image", "alt-field": "name"}'
/>
</li>
<li
t-if="i==MAX_BRAND_LINE"
style="display:block;"
class="list-inline-item"
>
<span class="float-right more_option text-info">
<a
href="#"
class="o_payment_form_pay_icon_more"
data-toggle="tooltip"
t-att-title="', '.join([opt.name for opt in acq.payment_icon_ids[MAX_BRAND_LINE:]])"
>and more</a>
</span>
</li>
<t t-set="i" t-value="i+1" />
</t>
</ul>
<div t-raw="acq.pre_msg" class="text-muted ml-3" />
</div>
<t t-if="acq.payment_flow == 'form'">
<div
t-attf-id="o_payment_form_acq_{{acq.id}}"
t-attf-class="d-none {{'card-footer' if acq.save_token == 'ask' else ''}}"
>
<label t-if="acq.save_token == 'ask'">
<input
type="checkbox"
name="o_payment_form_save_token"
data-remove-me=""
/>
Save my payment data
</label>
<t t-if="acq.save_token == 'always'">
<input
type="checkbox"
name="o_payment_form_save_token"
checked="'checked'"
class="o_hidden"
data-remove-me=""
/>
</t>
</div>
</t>
<t t-else="acq.payment_flow == 's2s'">
<div
t-attf-id="o_payment_add_token_acq_{{acq.id}}"
t-attf-class="card-footer {{'d-none' if(acquirers_count &gt; 1 and pms_count==0 and acquirers[0]!=acq) else 'd-none' if pms_count &gt;0 else ''}}"
>
<div class="clearfix">
<input
type="hidden"
t-if="(verify_validity==True or mode == 'manage') and acq.check_validity"
name="verify_validity"
t-att-value="acq.check_validity"
/>
<t t-call="{{acq.sudo().get_s2s_form_xml_id()}}">
<t t-set="id" t-value="acq.id" />
<t t-set="partner_id" t-value="partner_id" />
<t
t-if="not return_url"
t-set="return_url"
t-value="''"
/>
</t>
</div>
</div>
</t>
</t>
<t t-foreach="pms" t-as="pm">
<t
t-if="not verify_validity or (pm.acquirer_id.check_validity and pm.verified) or not pm.acquirer_id.check_validity"
>
<div class="card-body o_payment_acquirer_select">
<label>
<input
t-if="mode == 'payment'"
type="radio"
name="pm_id"
t-att-value="pm.id"
t-att-checked="checked_pm_id == pm.id"
/>
<span class="payment_option_name" t-esc="pm.name" />
<t t-if="pm.verified">
<i
class="fa fa-check text-success"
title="This payment method is verified by our system."
role="img"
aria-label="Ok"
/>
</t>
<t t-else="">
<i
class="fa fa-check text-muted"
title="This payment method has not been verified by our system."
role="img"
aria-label="Not verified"
/>
</t>
</label>
<button
t-if="mode == 'manage'"
name="delete_pm"
t-att-value="pm.id"
class="btn btn-primary btn-sm float-right"
>
<i class="fa fa-trash" /> Delete
</button>
</div>
</t>
</t>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 63f3dd3

Please sign in to comment.