From f3541fc6ef5585e103a33f484e2bce75a168c5ef Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 21 Nov 2023 00:29:39 +0100 Subject: [PATCH] [FIX] donation by direct debit For donation by debit order, we can't use twice the account "payment_debit_account_id", when validating the donation AND when validation the debit order. We have to use a different account. And, now that the OCA module account_payment_order uses account.payment, this account must be a receivable account. --- donation/README.rst | 2 +- donation/__manifest__.py | 2 +- donation/models/__init__.py | 1 + donation/models/account_journal.py | 58 ++++++++++++++++++++++++++ donation/models/donation.py | 19 ++++++--- donation/static/description/index.html | 2 +- donation/views/account_journal.xml | 22 ++++++++++ 7 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 donation/models/account_journal.py create mode 100644 donation/views/account_journal.xml diff --git a/donation/README.rst b/donation/README.rst index 83fc2b0fc..cd2d62673 100644 --- a/donation/README.rst +++ b/donation/README.rst @@ -7,7 +7,7 @@ Donation !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14 + !! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/donation/__manifest__.py b/donation/__manifest__.py index aae94a96d..a568652fb 100644 --- a/donation/__manifest__.py +++ b/donation/__manifest__.py @@ -22,7 +22,7 @@ "wizard/res_config_settings.xml", "data/donation_sequence.xml", "views/account_payment_mode.xml", - # "views/account_bank_statement.xml", + "views/account_journal.xml", "views/donation_campaign.xml", "views/donation_thanks_template.xml", "views/res_users.xml", diff --git a/donation/models/__init__.py b/donation/models/__init__.py index 363dc3463..5cac95802 100644 --- a/donation/models/__init__.py +++ b/donation/models/__init__.py @@ -5,6 +5,7 @@ from . import donation_thanks_template from . import account_bank_statement_line from . import account_analytic_applicability +from . import account_journal from . import res_partner from . import res_users from . import res_company diff --git a/donation/models/account_journal.py b/donation/models/account_journal.py new file mode 100644 index 000000000..41138c514 --- /dev/null +++ b/donation/models/account_journal.py @@ -0,0 +1,58 @@ +# Copyright 2023 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class AccountJournal(models.Model): + _inherit = "account.journal" + + donation_debit_order_account_id = fields.Many2one( + "account.account", + check_company=True, + copy=False, + ondelete="restrict", + domain="[('reconcile', '=', True), ('deprecated', '=', False), " + "('company_id', '=', company_id), " + "('account_type', '=', 'asset_receivable'), " + "('id', 'not in', (default_account_id, suspense_account_id))]", + string="Donation by Debit Order Account", + help="Transfer account for donations by debit order. " + "Leave empty if you don't handle donations by debit order on this bank account." + "This account must be a receivable account, otherwise the debit order will not work.", + ) + + @api.constrains("donation_debit_order_account_id") + def _check_donation_accounts(self): + acc_type2label = dict( + self.env["account.account"].fields_get("account_type", "selection")[ + "account_type" + ]["selection"] + ) + for journal in self: + ddo_account = journal.donation_debit_order_account_id + if ddo_account: + if not ddo_account.reconcile: + raise ValidationError( + _( + "The Donation by Debit Order Account of journal " + "'%(journal)s' must be reconciliable, but the account " + "'%(account)s' is not reconciliable.", + journal=journal.display_name, + account=ddo_account.display_name, + ) + ) + if ddo_account.account_type != "asset_receivable": + raise ValidationError( + _( + "The Donation by Debit Order Account of journal " + "'%(journal)s' must be a receivable account, " + "but the account '%(account)s' is configured with " + "account type '%(account_type)s'.", + journal=journal.display_name, + account=ddo_account.display_name, + account_type=acc_type2label[ddo_account.account_type], + ) + ) diff --git a/donation/models/donation.py b/donation/models/donation.py index ee93db44d..f278323a2 100644 --- a/donation/models/donation.py +++ b/donation/models/donation.py @@ -254,16 +254,13 @@ def _prepare_each_tax_receipt(self): } return vals + # TODO migration: remove 'journal' argument and use self.payment_mode_id.fixed_journal_id def _prepare_counterpart_move_line( self, total_company_cur, total_currency, journal ): self.ensure_one() + journal = self.payment_mode_id.fixed_journal_id company = journal.company_id - if not company.account_journal_payment_debit_account_id: - raise UserError( - _("Missing Outstanding Receipts Account on company '%s'.") - % company.display_name - ) if self.company_currency_id.compare_amounts(total_company_cur, 0) > 0: debit = total_company_cur credit = 0 @@ -272,7 +269,19 @@ def _prepare_counterpart_move_line( debit = 0 if self.bank_statement_line_id: account_id = company.donation_account_id.id + elif self.payment_mode_id.payment_order_ok: + if not journal.donation_debit_order_account_id: + raise UserError( + _("Missing Donation by Debit Order Account on journal '%s'.") + % journal.display_name + ) + account_id = journal.donation_debit_order_account_id.id else: + if not company.account_journal_payment_debit_account_id: + raise UserError( + _("Missing Outstanding Receipts Account on company '%s'.") + % company.display_name + ) payment_method = self.payment_mode_id.payment_method_id account_id = ( journal.inbound_payment_method_line_ids.filtered( diff --git a/donation/static/description/index.html b/donation/static/description/index.html index 640beedab..6a28043d5 100644 --- a/donation/static/description/index.html +++ b/donation/static/description/index.html @@ -367,7 +367,7 @@

Donation

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14 +!! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/donation Translate me on Weblate Try me on Runboat

This module handles donations by cash, check or by credit transfer and generate the corresponding journal entries and tax receipts. To fully support donations by credit transfer, if you are using the OCA bank statement reconcile interface, you also need the module donation_bank_statement_oca.

diff --git a/donation/views/account_journal.xml b/donation/views/account_journal.xml new file mode 100644 index 000000000..c6e73748d --- /dev/null +++ b/donation/views/account_journal.xml @@ -0,0 +1,22 @@ + + + + + + donation.account.journal.form + account.journal + + + + + + + + + +