-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from akretion/16-fix-direct_debit
[16.0][FIX] donation by direct debit
- Loading branch information
Showing
7 changed files
with
98 additions
and
8 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
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
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
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,58 @@ | ||
# Copyright 2023 Akretion France (http://www.akretion.com/) | ||
# @author: Alexis de Lattre <alexis.delattre@akretion.com> | ||
# 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], | ||
) | ||
) |
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
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
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
|
||
<record id="view_account_journal_form" model="ir.ui.view"> | ||
<field name="name">donation.account.journal.form</field> | ||
<field name="model">account.journal</field> | ||
<field name="inherit_id" ref="account.view_account_journal_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="loss_account_id" position="after"> | ||
<field | ||
name="donation_debit_order_account_id" | ||
groups="account.group_account_readonly" | ||
attrs="{'invisible': [('type', '!=', 'bank')]}" | ||
options="{'no_quick_create': True}" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
|
||
</odoo> |