2
2
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
3
3
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4
4
5
- from odoo import fields , models
5
+ from odoo import _ , api , fields , models
6
+ from odoo .exceptions import ValidationError
6
7
7
8
8
9
class AccountJournal (models .Model ):
@@ -16,8 +17,65 @@ class AccountJournal(models.Model):
16
17
domain = "[('reconcile', '=', True), ('deprecated', '=', False), "
17
18
"('company_id', '=', company_id), "
18
19
"('id', 'not in', (default_account_id, suspense_account_id, "
19
- "payment_credit_account_id, payment_debit_account_id))]" ,
20
+ "payment_credit_account_id, payment_debit_account_id, "
21
+ "donation_debit_order_account_id))]" ,
20
22
string = "Donation by Credit Transfer Account" ,
21
23
help = "Transfer account for donations received by credit transfer. "
22
24
"Leave empty if you don't receive donations on this bank account." ,
23
25
)
26
+ donation_debit_order_account_id = fields .Many2one (
27
+ "account.account" ,
28
+ check_company = True ,
29
+ copy = False ,
30
+ ondelete = "restrict" ,
31
+ domain = "[('reconcile', '=', True), ('deprecated', '=', False), "
32
+ "('company_id', '=', company_id), "
33
+ "('user_type_id.type', '=', 'receivable'), "
34
+ "('id', 'not in', (default_account_id, suspense_account_id, "
35
+ "payment_credit_account_id, payment_debit_account_id, donation_account_id))]" ,
36
+ string = "Donation by Debit Order Account" ,
37
+ help = "Transfer account for donations by debit order. "
38
+ "Leave empty if you don't handle donations by debit order on this bank account."
39
+ "This account must be a receivable account, otherwise the debit order will not work." ,
40
+ )
41
+
42
+ @api .constrains ("donation_account_id" , "donation_debit_order_account_id" )
43
+ def _check_donation_accounts (self ):
44
+ for journal in self :
45
+ if (
46
+ journal .donation_account_id
47
+ and not journal .donation_account_id .reconcile
48
+ ):
49
+ raise ValidationError (
50
+ _ (
51
+ "The Donation by Credit Transfer Account of journal "
52
+ "'%(journal)s' must be reconciliable, but the account "
53
+ "'%(account)s' is not reconciliable." ,
54
+ journal = journal .display_name ,
55
+ account = journal .donation_account_id .display_name ,
56
+ )
57
+ )
58
+ ddo_account = journal .donation_debit_order_account_id
59
+ if ddo_account :
60
+ if not ddo_account .reconcile :
61
+ raise ValidationError (
62
+ _ (
63
+ "The Donation by Debit Order Account of journal "
64
+ "'%(journal)s' must be reconciliable, but the account "
65
+ "'%(account)s' is not reconciliable." ,
66
+ journal = journal .display_name ,
67
+ account = ddo_account .display_name ,
68
+ )
69
+ )
70
+ if ddo_account .user_type_id .type != "receivable" :
71
+ raise ValidationError (
72
+ _ (
73
+ "The Donation by Debit Order Account of journal "
74
+ "'%(journal)s' must be a receivable account, "
75
+ "but the account '%(account)s' is configured with "
76
+ "type '%(account_type)s'." ,
77
+ journal = journal .display_name ,
78
+ account = ddo_account .display_name ,
79
+ account_type = ddo_account .user_type_id .display_name ,
80
+ )
81
+ )
0 commit comments