Skip to content

Commit cf119ff

Browse files
authored
Merge pull request #119 from akretion/14-fix-direct_debit
[14.0][FIX] donation by direct debit
2 parents 85321d1 + 79d9f51 commit cf119ff

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

donation/models/account_journal.py

+60-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import fields, models
5+
from odoo import _, api, fields, models
6+
from odoo.exceptions import ValidationError
67

78

89
class AccountJournal(models.Model):
@@ -16,8 +17,65 @@ class AccountJournal(models.Model):
1617
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
1718
"('company_id', '=', company_id), "
1819
"('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))]",
2022
string="Donation by Credit Transfer Account",
2123
help="Transfer account for donations received by credit transfer. "
2224
"Leave empty if you don't receive donations on this bank account.",
2325
)
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+
)

donation/models/donation.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,12 @@ def _prepare_each_tax_receipt(self):
275275
}
276276
return vals
277277

278+
# TODO migration: remove 'journal' argument and use self.payment_mode_id.fixed_journal_id
278279
def _prepare_counterpart_move_line(
279280
self, total_company_cur, total_currency, journal
280281
):
281282
self.ensure_one()
282-
if not journal.payment_debit_account_id:
283-
raise UserError(
284-
_("Missing Outstanding Receipts Account on journal '%s'.")
285-
% journal.display_name
286-
)
283+
journal = self.payment_mode_id.fixed_journal_id
287284
if self.company_currency_id.compare_amounts(total_company_cur, 0) > 0:
288285
debit = total_company_cur
289286
credit = 0
@@ -292,7 +289,19 @@ def _prepare_counterpart_move_line(
292289
debit = 0
293290
if self.bank_statement_line_id:
294291
account_id = journal.donation_account_id.id
292+
elif self.payment_mode_id.payment_order_ok:
293+
if not journal.donation_debit_order_account_id:
294+
raise UserError(
295+
_("Missing Donation by Debit Order Account on journal '%s'.")
296+
% journal.display_name
297+
)
298+
account_id = journal.donation_debit_order_account_id.id
295299
else:
300+
if not journal.payment_debit_account_id:
301+
raise UserError(
302+
_("Missing Outstanding Receipts Account on journal '%s'.")
303+
% journal.display_name
304+
)
296305
account_id = journal.payment_debit_account_id.id
297306
vals = {
298307
"debit": debit,

donation/views/account_journal.xml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
name="donation_account_id"
1313
attrs="{'invisible': [('type', '!=', 'bank')]}"
1414
/>
15+
<field
16+
name="donation_debit_order_account_id"
17+
attrs="{'invisible': [('type', '!=', 'bank')]}"
18+
/>
1519
</field>
1620
</field>
1721
</record>

donation_direct_debit/models/donation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def validate(self):
8888
"data-oe-id=%d>%s</a> has been automatically created"
8989
) % (payorder.id, payorder.name)
9090
# add payment line
91-
payment_account_id = (
92-
donation.payment_mode_id.fixed_journal_id.payment_debit_account_id.id
91+
match_account_id = (
92+
donation.payment_mode_id.fixed_journal_id.donation_debit_order_account_id.id
9393
)
9494
for mline in donation.move_id.line_ids:
95-
if mline.account_id.id == payment_account_id:
95+
if mline.account_id.id == match_account_id:
9696
mline.sudo().create_payment_line_from_move_line(payorder)
9797
break
9898
if not msg:

0 commit comments

Comments
 (0)