Skip to content

Commit

Permalink
[ADD] account_payment_base_oca: New base module for OCA/bank-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Jan 20, 2025
1 parent edc27c2 commit 0920212
Show file tree
Hide file tree
Showing 21 changed files with 1,271 additions and 0 deletions.
105 changes: 105 additions & 0 deletions account_payment_base_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
========================
Account Payment Base OCA
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:398fe25e1ed0988a7a0504f68878755aa77b7b87532718ca8dfaa344c31b88e1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github
:target: https://github.com/OCA/bank-payment/tree/18.0/account_payment_base_oca
:alt: OCA/bank-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-payment-18-0/bank-payment-18-0-account_payment_base_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This is the new base module for the OCA **bank-payment** project. This
module has been developped for Odoo 18 to adapt the OCA bank-payment
stack to the new native payment mode object of Odoo.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-payment/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_base_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Akretion

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

- Alexis de Lattre <[email protected]>
- Eric Lembregts <[email protected]>
- Andrea Stirpe <[email protected]>
- Marçal Isern <[email protected]>
- Miquel Alzanillas <[email protected]>
- Raphaël Valyi
- Stefan Rijnhart (Therp)
- Alexandre Fayolle
- Stéphane Bidoul <[email protected]>
- Danimar Ribeiro
- Angel Moya <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Pedro M. Baeza
- Carlos Dauden
- Víctor Martínez

- `DynApps <https://www.dynapps.be>`__:

- Raf Ven <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-alexis-via| image:: https://github.com/alexis-via.png?size=40px
:target: https://github.com/alexis-via
:alt: alexis-via

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/18.0/account_payment_base_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions account_payment_base_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import reports
25 changes: 25 additions & 0 deletions account_payment_base_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024-2025 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Account Payment Base OCA",
"version": "18.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "OCA extensions to native payment objects of Odoo",
"author": "Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"development_status": "Beta",
"website": "https://github.com/OCA/bank-payment",
"depends": ["account"],
"data": [
"security/ir.model.access.csv",
"views/account_payment_method.xml",
"views/account_payment_method_line.xml",
"views/account_move.xml",
"reports/account_invoice_report_view.xml",
],
"demo": ["demo/demo.xml"],
"installable": True,
}
53 changes: 53 additions & 0 deletions account_payment_base_oca/demo/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="bank_qonto" model="res.bank">
<field name="name">Qonto</field>
<field name="bic">QNTOFRP1XXX</field>
<field name="street">20 bis rue La Fayette</field>
<field name="zip">75009</field>
<field name="city">Paris</field>
<field name="country" ref="base.fr" />
</record>
<record id="bank_la_banque_postale" model="res.bank">
<field name="name">La Banque Postale</field>
<field name="bic">PSSTFRPPXXX</field>
<field name="street">115 rue de Sèvres</field>
<field name="zip">75007</field>
<field name="city">Paris</field>
<field name="country" ref="base.fr" />
</record>
<record id="bank_societe_generale" model="res.bank">
<field name="name">Société Générale</field>
<field name="bic">SOGEFRPPXXX</field>
<field name="street">1 avenue du Roi Fabien 1er</field>
<field name="zip">75008</field>
<field name="city">Paris</field>
<field name="country" ref="base.fr" />
</record>
<record id="bank_fortis" model="res.bank">
<field name="name">BNP Paribas Fortis Charleroi</field>
<field name="bic">GEBABEBB03A</field>
<field name="city">Charleroi</field>
<field name="country" ref="base.be" />
</record>
<record id="main_company_iban" model="res.partner.bank">
<field name="acc_number">FR76 4242 4242 4242 4242 4242 424</field>
<field name="bank_id" ref="bank_la_banque_postale" />
<field name="partner_id" ref="base.main_partner" />
</record>
<record id="main_company_iban2" model="res.partner.bank">
<field name="acc_number">FR20 1242 1242 1242 1242 1242 124</field>
<field name="bank_id" ref="bank_societe_generale" />
<field name="partner_id" ref="base.main_partner" />
</record>
<record id="res_partner_12_iban" model="res.partner.bank">
<field name="acc_number">FR66 1212 1212 1212 1212 1212 121</field>
<field name="bank_id" ref="bank_qonto" />
<field name="partner_id" ref="base.res_partner_12" />
</record>
<record id="res_partner_2_iban" model="res.partner.bank">
<field name="acc_number">BE96 9988 7766 5544</field>
<field name="bank_id" ref="bank_fortis" />
<field name="partner_id" ref="base.res_partner_2" />
</record>
</odoo>
5 changes: 5 additions & 0 deletions account_payment_base_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import account_payment_method
from . import account_payment_method_line
from . import account_move
from . import res_partner_bank
from . import res_bank
16 changes: 16 additions & 0 deletions account_payment_base_oca/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024-2025 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountMove(models.Model):
_inherit = "account.move"

bank_account_required = fields.Boolean(
related="preferred_payment_method_line_id.payment_method_id.bank_account_required",
)
payment_method_code = fields.Char(
related="preferred_payment_method_line_id.payment_method_id.code", store=True
)
34 changes: 34 additions & 0 deletions account_payment_base_oca/models/account_payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2016-2025 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountPaymentMethod(models.Model):
_inherit = "account.payment.method"

# native field, we just inherit string and help
code = fields.Char(
string="Code (do not modify)",
help="This code is used in the source code of the Odoo module that handles "
"this payment method. Therefore, if you change it, "
"the generation of the payment file may fail.",
)
active = fields.Boolean(default=True)
bank_account_required = fields.Boolean(
help="Activate this option if this payment method requires you to "
"know the bank account number of your customer or supplier."
)
# add the one2many field which is not native
line_ids = fields.One2many(
comodel_name="account.payment.method.line",
inverse_name="payment_method_id",
string="Payment Methods",
)

@api.depends("code", "name", "payment_type")
def _compute_display_name(self):
for method in self:
name = f"[{method.code}] {method.name} ({method.payment_type})"
method.display_name = name
136 changes: 136 additions & 0 deletions account_payment_base_oca/models/account_payment_method_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Copyright 2024-2025 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# Copyright 2017 ForgeFlow S.L.
# Copyright 2018 Tecnativa - Carlos Dauden, Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import Command, _, api, fields, models
from odoo.exceptions import ValidationError


class AccountPaymentMethodLine(models.Model):
_inherit = "account.payment.method.line"
_check_company_auto = True

# Here is the strategy to support bank_account_link = variable
# without breaking the native behavior
# company_id is a related of journal_id.company_id
# When bank_account_link = 'fixed' => we use journal_id
# When bank_account_link = 'variable':
# - journal_id is considered as the default journal
# - alternative_journal_ids are additional journals that can be used
bank_account_link = fields.Selection(
[("fixed", "Fixed"), ("variable", "Variable")],
string="Link to Bank Account",
required=True,
default="fixed",
help="For payment modes that are always attached to the same bank "
"account of your company (such as wire transfer from customers or "
"SEPA direct debit from suppliers), select "
"'Fixed'. For payment modes that are not always attached to the same "
"bank account (such as SEPA Direct debit for customers, wire transfer "
"to suppliers), you should select 'Variable', which means that you "
"will select the bank account on the payment order. If your company "
"only has one bank account, you should always select 'Fixed'.",
)
# I need to explicitly define the table name
# because I have 2 M2M fields pointing to account.journal
alternative_journal_ids = fields.Many2many(
comodel_name="account.journal",
relation="account_payment_method_line_alternative_journal_rel",
column1="method_line_id",
column2="journal_id",
string="Alternative Bank Journals",
domain="[('company_id', '=', company_id), "
"('type', 'in', ('bank', 'cash', 'credit'))]",
check_company=True,
compute="_compute_alternative_journal_ids",
store=True,
readonly=False,
precompute=True,
)
active = fields.Boolean(default=True)
report_description = fields.Html(translate=True)
show_bank_account = fields.Selection(
selection=[
("full", "Full"),
("first", "First n chars"),
("last", "Last n chars"),
("first_last", "First n chars and Last n chars"),
("no", "No"),
],
default="full",
string="Show Customer Bank Account",
help="On invoice report, show partial or full bank account number.",
)
show_bank_account_chars = fields.Integer(
string="# of Digits to Show for Customer Bank Account",
default=4,
)
refund_payment_mode_id = fields.Many2one(
comodel_name="account.payment.method.line",
domain="[('payment_type', '!=', payment_type)]",
string="Payment Mode for Refunds",
help="This payment mode will be used when doing "
"refunds coming from the current payment mode.",
check_company=True,
)

_sql_constraints = [
(
"show_bank_account_chars_positive",
"CHECK(show_bank_account_chars >= 0)",
"The number of digits to show for customer bank account "
"must be positive or null.",
)
]

@api.constrains("bank_account_link", "journal_id", "alternative_journal_ids")
def _fixed_link_constrains(self):
for line in self:
if line.bank_account_link == "fixed" and not line.journal_id:
raise ValidationError(
_(
"On %(name)s, Link to Bank Account is "
"'Fixed' but the fixed bank journal is not set.",
name=line.display_name,
)
)
if line.payment_method_id.bank_account_required:
if line.journal_id and not line.journal_id.bank_account_id:
raise ValidationError(
_(
"On %(name)s, the Payment Method %(method)s is "
"configured with Bank Account Required but journal "
"%(journal)s is not linked to a bank account.",
name=line.display_name,
method=line.payment_method_id.display_name,
journal=line.journal_id.display_name,
)
)
if line.bank_account_link == "variable":
for journal in line.alternative_journal_ids:
if not journal.bank_account_id:
raise ValidationError(
_(
"On %(name)s, the Payment Method %(method)s is "
"configured with Bank Account Required but journal "
"%(journal)s is not linked to a bank account.",
name=line.display_name,
method=line.payment_method_id.display_name,
journal=journal.display_name,
)
)

@api.depends("journal_id", "bank_account_link")
def _compute_alternative_journal_ids(self):
for line in self:
if line.bank_account_link == "fixed":
line.alternative_journal_ids = [Command.clear()]
elif (
line.bank_account_link == "variable"
and line.journal_id
and line.journal_id in line.alternative_journal_ids
):
line.alternative_journal_ids = [Command.unlink(line.journal_id.id)]
Loading

0 comments on commit 0920212

Please sign in to comment.