-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
18d351a
commit f3541fc
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 <[email protected]> | ||
# 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> |