-
-
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.
Merge pull request #119 from akretion/14-fix-direct_debit
[14.0][FIX] donation by direct debit
- Loading branch information
Showing
4 changed files
with
81 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
# @author: Alexis de Lattre <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountJournal(models.Model): | ||
|
@@ -16,8 +17,65 @@ class AccountJournal(models.Model): | |
domain="[('reconcile', '=', True), ('deprecated', '=', False), " | ||
"('company_id', '=', company_id), " | ||
"('id', 'not in', (default_account_id, suspense_account_id, " | ||
"payment_credit_account_id, payment_debit_account_id))]", | ||
"payment_credit_account_id, payment_debit_account_id, " | ||
"donation_debit_order_account_id))]", | ||
string="Donation by Credit Transfer Account", | ||
help="Transfer account for donations received by credit transfer. " | ||
"Leave empty if you don't receive donations on this bank account.", | ||
) | ||
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), " | ||
"('user_type_id.type', '=', 'receivable'), " | ||
"('id', 'not in', (default_account_id, suspense_account_id, " | ||
"payment_credit_account_id, payment_debit_account_id, donation_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_account_id", "donation_debit_order_account_id") | ||
def _check_donation_accounts(self): | ||
for journal in self: | ||
if ( | ||
journal.donation_account_id | ||
and not journal.donation_account_id.reconcile | ||
): | ||
raise ValidationError( | ||
_( | ||
"The Donation by Credit Transfer Account of journal " | ||
"'%(journal)s' must be reconciliable, but the account " | ||
"'%(account)s' is not reconciliable.", | ||
journal=journal.display_name, | ||
account=journal.donation_account_id.display_name, | ||
) | ||
) | ||
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.user_type_id.type != "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 " | ||
"type '%(account_type)s'.", | ||
journal=journal.display_name, | ||
account=ddo_account.display_name, | ||
account_type=ddo_account.user_type_id.display_name, | ||
) | ||
) |
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